openai

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAPIEndpoint       = "v1/chat/completions"
	DefaultMaxTokens         = 100
	DefaultRequestsPerSecond = 1
	DefaultDuration          = time.Minute
)
View Source
const (
	HUGGINGFACE_API_ENDPOINT = "https://huggingface.co/api"

	// Dataset API
	DATASET_API_PATH         = "datasets"
	DATASET_API_PARQUET_PATH = "parquet"
)
View Source
const (
	DefaultMethod   = "POST"
	DefaultEndpoint = "/v1/chat/completions"

	DefaultRole        = "system"
	DefaultContentType = "application/json"

	ContentHeader       = "Content-Type"
	AuthorizationHeader = "Authorization"
	AuthorizationPrefix = "Bearer "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	RequestsPerSecond float64 `json:"rps"`
	Duration          float64 `json:"duration"`

	APIKey              string `json:"apikey"`
	Endpoint            string `json:"endpoint"`
	Model               string `json:"model"`
	MaxCompletionTokens int    `json:"maxtokens"`
}

func (*Config) GetAPIKey

func (g *Config) GetAPIKey() string

func (*Config) GetDuration

func (g *Config) GetDuration() time.Duration

func (*Config) GetEndpoint

func (g *Config) GetEndpoint() string

func (*Config) GetMaxCompletionTokens

func (g *Config) GetMaxCompletionTokens() int

func (*Config) GetModel

func (g *Config) GetModel() string

func (*Config) GetRequestsPerSecond

func (g *Config) GetRequestsPerSecond() float64

type Dataset

type Dataset struct {
	// contains filtered or unexported fields
}

func GetDataset

func GetDataset(repo_id string) (*Dataset, error)

func NewDataset

func NewDataset(repo_id string) *Dataset

func (*Dataset) RandomPrompt

func (d *Dataset) RandomPrompt() string

type OpenAIGenerator

type OpenAIGenerator struct {
	RPS      float64
	Duration time.Duration

	// OpenAI API key
	APIKey              string
	Method              string
	Endpoint            string
	Model               string
	MaxCompletionTokens int
}

func NewOpenAIGenerator

func NewOpenAIGenerator(conf Config) *OpenAIGenerator

func (*OpenAIGenerator) Generate

func (g *OpenAIGenerator) Generate() (trace.TraceLog, error)

type OpenAIMessage

type OpenAIMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type OpenAIRequestBody

type OpenAIRequestBody struct {
	Model               string          `json:"model"`
	Messages            []OpenAIMessage `json:"messages"`
	Stream              bool            `json:"stream"`
	StreamOptions       StreamOptions   `json:"stream_options"`
	MaxCompletionTokens int             `json:"max_completion_tokens"`
}

func NewOpenAIRequestBody

func NewOpenAIRequestBody(model string, role string, prompt string, maxCompletionTokens int) OpenAIRequestBody

type StreamOptions

type StreamOptions struct {
	IncludeUsage bool `json:"include_usage"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL