Documentation ¶
Index ¶
- Constants
- type App
- type AudioService
- type AudioServiceOp
- type ChatCompletion
- type ChatCreateRequest
- type ChatCreateResponse
- type ChatService
- type ChatServiceOp
- type Client
- func (c *Client) Close() error
- func (c *Client) Delete(ctx context.Context, relPath string, params, resp any) error
- func (c *Client) Do(ctx context.Context, method, relPath string, headers map[string]string, ...) error
- func (c *Client) Get(ctx context.Context, relPath string, params, resp any) error
- func (c *Client) GetByStream(ctx context.Context, relPath string, params any) (EventSource, error)
- func (c *Client) GetBytes(ctx context.Context, method, relPath string, headers map[string]string, ...) ([]byte, error)
- func (c *Client) NewRequest(ctx context.Context, method string, relPath string, headers map[string]string, ...) (*http.Request, error)
- func (c *Client) Post(ctx context.Context, relPath string, body, resp any) error
- func (c *Client) PostByStream(ctx context.Context, relPath string, body any) (EventSource, error)
- func (c *Client) Stream(ctx context.Context, method, relPath string, headers map[string]string, ...) (EventSource, error)
- func (c *Client) Upload(ctx context.Context, relPath string, files []*FormFile, v any, ...) error
- func (c *Client) V(version string) Client
- type Completion
- type CompletionCreateRequest
- type CompletionCreateResponse
- type CompletionService
- type CompletionServiceOp
- type Delta
- type Edit
- type EditCreateRequest
- type EditCreateResponse
- type EditService
- type EditServiceOp
- type Embedding
- type EmbeddingCreateRequest
- type EmbeddingCreateResponse
- type EmbeddingService
- type EmbeddingServiceOp
- type EmbeddingUsage
- type Event
- type EventListResponse
- type EventSource
- type File
- type FileDeleteResponse
- type FileListResponse
- type FileService
- type FileServiceOp
- func (f FileServiceOp) Delete(ctx context.Context, fileId string) (*FileDeleteResponse, error)
- func (f FileServiceOp) List(ctx context.Context) (*FileListResponse, error)
- func (f FileServiceOp) Retrieve(ctx context.Context, fileId string) (*File, error)
- func (f FileServiceOp) RetrieveContent(ctx context.Context, fileId string) ([]byte, error)
- func (f FileServiceOp) Upload(ctx context.Context, req *FileUploadRequest) (*File, error)
- type FileUploadRequest
- type FineTune
- type FineTuneCreateRequest
- type FineTuneEvent
- type FineTuneListResponse
- type FineTuneService
- type FineTuneServiceOp
- func (f FineTuneServiceOp) Cancel(ctx context.Context, id string) (*FineTune, error)
- func (f FineTuneServiceOp) Create(ctx context.Context, req *FineTuneCreateRequest) (*FineTune, error)
- func (f FineTuneServiceOp) DeleteModel(ctx context.Context, model string) (*ModelDeleteResponse, error)
- func (f FineTuneServiceOp) List(ctx context.Context) (*FineTuneListResponse, error)
- func (f FineTuneServiceOp) ListEvents(ctx context.Context, id string, stream ...bool) (chan *EventListResponse, error)
- func (f FineTuneServiceOp) Retrieve(ctx context.Context, id string) (*FineTune, error)
- type FormBuilder
- type FormField
- type FormFile
- type Function
- type FunctionCall
- type FunctionCallString
- type Hyperparams
- type IFunctionCall
- type Image
- type ImageAttributes
- type ImageCreateRequest
- type ImageEditRequest
- type ImageResponse
- type ImageService
- type ImageServiceOp
- func (i ImageServiceOp) Create(ctx context.Context, req *ImageCreateRequest) (*ImageResponse, error)
- func (i ImageServiceOp) Edit(ctx context.Context, req *ImageEditRequest) (*ImageResponse, error)
- func (i ImageServiceOp) Variation(ctx context.Context, req *ImageVariationRequest) (*ImageResponse, error)
- type ImageVariationRequest
- type Message
- type Model
- type ModelDeleteResponse
- type ModelResponse
- type ModelService
- type ModelServiceOp
- type Moderation
- type ModerationCategory
- type ModerationCategoryScore
- type ModerationCreateRequest
- type ModerationCreateResponse
- type ModerationService
- type ModerationServiceOp
- type Option
- type Parameter
- type Property
- type Proxy
- type TranscriptionsRequest
- type TranscriptionsResponse
- type TranslationsRequest
- type TranslationsResponse
- type Usage
Constants ¶
const ( AudioTranscriptionsPath = "/audio/transcriptions" AudioTranslationsPath = "/audio/translations" )
const ( // ChatCreatePath 聊天创建路径 ChatCreatePath = "/chat/completions" FunctionCallNone = FunctionCallString("none") FunctionCallAuto = FunctionCallString("auto") FinishReasonFunctionCall = "function_call" FinishReasonStop = "stop" )
const ( FilesListPath = "/files" FileUploadPath = "/files" FileDeletePath = "/files/%s" FileRetrievePath = "/files/%s" FileContentRetrievePath = "/files/%s/content" )
const ( FineTuneCreatePath = "/fine-tunes" FineTuneListPath = "/fine-tunes" FineTuneRetrievePath = "/fine-tunes/%s" FineTuneCancelPath = "/fine-tunes/%s/cancel" EventsListPath = "/fine-tunes/%s/events" ModelDeletePath = "/models/%s" )
const ( ImageCreatePath = "/images/generations" ImageEditPath = "/images/edits" ImageVariationPath = "/images/variations" )
const ( ModelListPath = "/models" ModelRetrievePath = "/models/%s" GPT35Turbo = "gpt-3.5-turbo" GPT35Turbo0301 = "gpt-3.5-turbo-0301" GPT35Turbo0613 = "gpt-3.5-turbo-0613" GPT35Turbo16k = "gpt-3.5-turbo-16k" GPT35Turbo16k0613 = "gpt-3.5-turbo-16k-0613" GPT4 = "gpt-4" GPT40314 = "gpt-4-0314" GPT40613 = "gpt-4-0613" Ada = "ada" TextAda001 = "text-ada-001" Babbage = "babbage" TextBabbage001 = "text-babbage-001" Curie = "curie" TextCurie001 = "text-curie-001" DaVinci = "davinci" TextDaVinci001 = "text-davinci-001" TextDaVinci002 = "text-davinci-002" TextDaVinci003 = "text-davinci-003" )
const (
CompletionsCreatePath = "/completions"
)
const (
EditCreatePath = "/edits"
)
const (
EmbeddingCreatePath = "/embeddings"
)
const (
ModerationCreatePath = "/moderations"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioService ¶
type AudioService interface { Transcriptions(ctx context.Context, req *TranscriptionsRequest) (*TranscriptionsResponse, error) Translations(ctx context.Context, req *TranslationsRequest) (*TranslationsResponse, error) }
type AudioServiceOp ¶
type AudioServiceOp struct {
// contains filtered or unexported fields
}
func (AudioServiceOp) Transcriptions ¶
func (a AudioServiceOp) Transcriptions(ctx context.Context, req *TranscriptionsRequest) (*TranscriptionsResponse, error)
func (AudioServiceOp) Translations ¶
func (a AudioServiceOp) Translations(ctx context.Context, req *TranslationsRequest) (*TranslationsResponse, error)
type ChatCompletion ¶
type ChatCreateRequest ¶
type ChatCreateRequest struct { Model string `json:"model"` Messages []*Message `json:"messages,omitempty"` Functions []*Function `json:"functions,omitempty"` FunctionCall IFunctionCall `json:"function_call,omitempty"` Temperature float64 `json:"temperature,omitempty"` TopP float64 `json:"top_p,omitempty"` N int64 `json:"n,omitempty"` Stream bool `json:"stream,omitempty"` Stop []string `json:"stop,omitempty"` MaxTokens int64 `json:"max_tokens,omitempty"` PresencePenalty float64 `json:"presence_penalty,omitempty"` FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` LogitBias map[string]int64 `json:"logit_bias,omitempty"` User string `json:"user,omitempty"` }
type ChatCreateResponse ¶
type ChatCreateResponse struct { Id string `json:"id"` Object string `json:"object"` Created int64 `json:"created"` Choices []*ChatCompletion `json:"choices"` Usage Usage `json:"usage"` }
type ChatService ¶
type ChatService interface {
Create(ctx context.Context, req *ChatCreateRequest) (chan *ChatCreateResponse, error)
}
type ChatServiceOp ¶
type ChatServiceOp struct {
// contains filtered or unexported fields
}
func (ChatServiceOp) Create ¶
func (c ChatServiceOp) Create(ctx context.Context, req *ChatCreateRequest) (chan *ChatCreateResponse, error)
Create 创建一个新的聊天,为了兼容 stream 模式,返回一个 channel,如果不是 stream 模式,返回的 channel 会在第一次返回后关闭 如果是 stream 模式,返回的 channel 会在 ctx.Done() 或者 stream 关闭后关闭 这里其实也可以考虑拆分为两个方法,一个是 Create,一个是 CreateStream,但是这样会导致 API 不一致,所以这里就不拆分了
type Client ¶
type Client struct { Models ModelService Completions CompletionService Chat ChatService Edits EditService Images ImageService Embeddings EmbeddingService Audio AudioService Files FileService FineTunes FineTuneService Moderations ModerationService // contains filtered or unexported fields }
func (*Client) GetByStream ¶
func (*Client) GetBytes ¶
func (c *Client) GetBytes(ctx context.Context, method, relPath string, headers map[string]string, params, body any) ([]byte, error)
GetBytes 获取字节流, 也可以考虑合并到Do中 但是由于api中大部分都是json, 所以这里单独提取出来
func (*Client) NewRequest ¶
func (*Client) PostByStream ¶
func (*Client) Stream ¶
func (c *Client) Stream(ctx context.Context, method, relPath string, headers map[string]string, params, body any) (EventSource, error)
Stream 为请求提供流式处理
type Completion ¶
type CompletionCreateRequest ¶
type CompletionCreateRequest struct { Model string `json:"model"` Prompt string `json:"prompt,omitempty"` Suffix string `json:"suffix,omitempty"` MaxTokens int64 `json:"max_tokens,omitempty"` Temperature float64 `json:"temperature,omitempty"` TopP float64 `json:"top_p,omitempty"` N int64 `json:"n,omitempty"` Stream bool `json:"stream,omitempty"` Logprobs int64 `json:"logprobs,omitempty"` Echo bool `json:"echo,omitempty"` Stop []string `json:"stop,omitempty"` PresencePenalty float64 `json:"presence_penalty,omitempty"` FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` BestOf int64 `json:"best_of,omitempty"` LogitBias map[string]int64 `json:"logit_bias,omitempty"` User string `json:"user,omitempty"` }
type CompletionService ¶
type CompletionService interface {
Create(ctx context.Context, req *CompletionCreateRequest) (chan *CompletionCreateResponse, error)
}
type CompletionServiceOp ¶
type CompletionServiceOp struct {
// contains filtered or unexported fields
}
func (CompletionServiceOp) Create ¶
func (c CompletionServiceOp) Create(ctx context.Context, req *CompletionCreateRequest) (chan *CompletionCreateResponse, error)
Create 创建一个新的聊天,为了兼容 stream 模式,返回一个 channel,如果不是 stream 模式,返回的 channel 会在第一次返回后关闭 如果是 stream 模式,返回的 channel 会在 ctx.Done() 或者 stream 关闭后关闭 这里其实也可以考虑拆分为两个方法,一个是 Create,一个是 CreateStream,但是这样会导致 API 不一致,所以这里就不拆分了
type EditCreateRequest ¶
type EditCreateResponse ¶
type EditService ¶
type EditService interface {
Create(ctx context.Context, request *EditCreateRequest) (*EditCreateResponse, error)
}
type EditServiceOp ¶
type EditServiceOp struct {
// contains filtered or unexported fields
}
func (EditServiceOp) Create ¶
func (e EditServiceOp) Create(ctx context.Context, req *EditCreateRequest) (*EditCreateResponse, error)
type EmbeddingCreateRequest ¶
type EmbeddingCreateResponse ¶
type EmbeddingCreateResponse struct { Object string `json:"object"` Data []*Embedding `json:"data"` Model string `json:"model"` Usage *EmbeddingUsage `json:"usage"` }
type EmbeddingService ¶
type EmbeddingService interface {
Create(ctx context.Context, req *EmbeddingCreateRequest) (*EmbeddingCreateResponse, error)
}
type EmbeddingServiceOp ¶
type EmbeddingServiceOp struct {
// contains filtered or unexported fields
}
func (EmbeddingServiceOp) Create ¶
func (e EmbeddingServiceOp) Create(ctx context.Context, req *EmbeddingCreateRequest) (*EmbeddingCreateResponse, error)
type EmbeddingUsage ¶
type EventListResponse ¶
type EventListResponse struct { Object string `json:"object"` Data []*FineTuneEvent `json:"data"` }
type EventSource ¶
type EventSource chan Event
func NewEventSource ¶
func NewEventSource(ctx context.Context, r io.ReadCloser, doneStr string) EventSource
NewEventSource 处理SSE
type FileDeleteResponse ¶
type FileListResponse ¶
type FileListResponse struct {
Data []*File `json:"data"`
}
type FileService ¶
type FileService interface { List(ctx context.Context) (*FileListResponse, error) Upload(ctx context.Context, req *FileUploadRequest) (*File, error) Delete(ctx context.Context, fileId string) (*FileDeleteResponse, error) Retrieve(ctx context.Context, fileId string) (*File, error) RetrieveContent(ctx context.Context, fileId string) ([]byte, error) }
type FileServiceOp ¶
type FileServiceOp struct {
// contains filtered or unexported fields
}
func (FileServiceOp) Delete ¶
func (f FileServiceOp) Delete(ctx context.Context, fileId string) (*FileDeleteResponse, error)
func (FileServiceOp) List ¶
func (f FileServiceOp) List(ctx context.Context) (*FileListResponse, error)
func (FileServiceOp) RetrieveContent ¶
func (FileServiceOp) Upload ¶
func (f FileServiceOp) Upload(ctx context.Context, req *FileUploadRequest) (*File, error)
type FileUploadRequest ¶
type FineTune ¶
type FineTune struct { Id string `json:"id"` Object string `json:"object"` Model string `json:"model"` CreateAt int64 `json:"create_at"` Events []*FineTuneEvent `json:"events"` FineTunedModel string `json:"fine_tuned_model"` Hyperparams Hyperparams `json:"hyperparams"` OrganizationId string `json:"organization_id"` ResultFiles []*File `json:"result_files"` Status string `json:"status"` ValidationFiles []*File `json:"validation_files"` TrainingFiles []*File `json:"training_files"` UpdatedAt int64 `json:"updated_at"` }
type FineTuneCreateRequest ¶
type FineTuneCreateRequest struct { // TrainingFile is the ID to the training file TrainingFile string `json:"training_file"` ValidationFile string `json:"validation_file,omitempty"` Model string `json:"model,omitempty"` NEpochs int `json:"n_epochs,omitempty"` BatchSize int `json:"batch_size,omitempty"` LearningRateMultiplier float64 `json:"learning_rate_multiplier,omitempty"` PromptLossWeight float64 `json:"prompt_loss_weight,omitempty"` ComputeClassificationMetrics bool `json:"compute_classification_metrics,omitempty"` ClassificationNClasses int64 `json:"classification_n_classes,omitempty"` ClassificationPositiveClasses string `json:"classification_positive_classes,omitempty"` ClassificationBetas []float64 `json:"classification_betas,omitempty"` Suffix string `json:"suffix,omitempty"` }
type FineTuneEvent ¶
type FineTuneListResponse ¶
type FineTuneService ¶
type FineTuneService interface { Create(ctx context.Context, req *FineTuneCreateRequest) (*FineTune, error) List(ctx context.Context) (*FineTuneListResponse, error) Retrieve(ctx context.Context, id string) (*FineTune, error) Cancel(ctx context.Context, id string) (*FineTune, error) ListEvents(ctx context.Context, id string, stream ...bool) (chan *EventListResponse, error) DeleteModel(ctx context.Context, model string) (*ModelDeleteResponse, error) }
type FineTuneServiceOp ¶
type FineTuneServiceOp struct {
// contains filtered or unexported fields
}
func (FineTuneServiceOp) Create ¶
func (f FineTuneServiceOp) Create(ctx context.Context, req *FineTuneCreateRequest) (*FineTune, error)
Create Creates a job that fine-tunes a specified model from a given dataset. Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
func (FineTuneServiceOp) DeleteModel ¶
func (f FineTuneServiceOp) DeleteModel(ctx context.Context, model string) (*ModelDeleteResponse, error)
DeleteModel Deletes a fine-tuned model.
func (FineTuneServiceOp) List ¶
func (f FineTuneServiceOp) List(ctx context.Context) (*FineTuneListResponse, error)
List Returns a list of all fine-tuning jobs.
func (FineTuneServiceOp) ListEvents ¶
func (f FineTuneServiceOp) ListEvents(ctx context.Context, id string, stream ...bool) (chan *EventListResponse, error)
ListEvents Returns a list of events for a fine-tuning job. If stream=true, the response will be a stream of events as they are generated. by default, the response will be a list of all events generated so far.
type FormBuilder ¶
type FormBuilder interface { CreateFormFile(name string, filename string) error CreateFormField(name string, value string) error FormDataContentType() string io.Closer }
FormBuilder is a builder for multipart/form-data requests.
func NewMultiPartFormBuilder ¶
func NewMultiPartFormBuilder(w io.Writer) FormBuilder
type FormField ¶
type FormField struct {
// contains filtered or unexported fields
}
func NewFormField ¶
type FormFile ¶
type FormFile struct {
// contains filtered or unexported fields
}
func NewFormFile ¶
type FunctionCall ¶ added in v1.0.1
type FunctionCall struct { Name string `json:"name"` Arguments []byte `json:"arguments,omitempty"` }
func (FunctionCall) Call ¶ added in v1.0.1
func (f FunctionCall) Call()
type FunctionCallString ¶ added in v1.0.1
type FunctionCallString string
func (FunctionCallString) Call ¶ added in v1.0.1
func (f FunctionCallString) Call()
type Hyperparams ¶
type IFunctionCall ¶ added in v1.0.1
type IFunctionCall interface {
Call()
}
type ImageAttributes ¶
type ImageCreateRequest ¶
type ImageCreateRequest struct { Prompt string `json:"prompt"` ImageAttributes }
type ImageEditRequest ¶
type ImageEditRequest struct { // Image is the path to the image file Image string `json:"image"` // Mask is the path to the mask file Mask string `json:"mask,omitempty"` Prompt string `json:"prompt"` ImageAttributes }
type ImageResponse ¶
type ImageService ¶
type ImageService interface { Create(ctx context.Context, req *ImageCreateRequest) (*ImageResponse, error) Edit(ctx context.Context, req *ImageEditRequest) (*ImageResponse, error) Variation(ctx context.Context, req *ImageVariationRequest) (*ImageResponse, error) }
type ImageServiceOp ¶
type ImageServiceOp struct {
// contains filtered or unexported fields
}
func (ImageServiceOp) Create ¶
func (i ImageServiceOp) Create(ctx context.Context, req *ImageCreateRequest) (*ImageResponse, error)
func (ImageServiceOp) Edit ¶
func (i ImageServiceOp) Edit(ctx context.Context, req *ImageEditRequest) (*ImageResponse, error)
func (ImageServiceOp) Variation ¶
func (i ImageServiceOp) Variation(ctx context.Context, req *ImageVariationRequest) (*ImageResponse, error)
type ImageVariationRequest ¶
type ImageVariationRequest struct { Image string `json:"image"` ImageAttributes }
type Message ¶
type Message struct { Role string `json:"role"` // user,assistant,system,function Content string `json:"content,omitempty"` Name string `json:"name,omitempty"` FunctionCall FunctionCall `json:"function_call,omitempty"` }
type ModelDeleteResponse ¶
type ModelResponse ¶
type ModelService ¶
type ModelServiceOp ¶
type ModelServiceOp struct {
// contains filtered or unexported fields
}
func (ModelServiceOp) List ¶
func (m ModelServiceOp) List(ctx context.Context) (*ModelResponse, error)
type Moderation ¶
type Moderation struct { Categories ModerationCategory `json:"categories"` CategoryScores ModerationCategoryScore `json:"category_scores"` Flagged bool `json:"flagged"` }
type ModerationCategory ¶
type ModerationCategoryScore ¶
type ModerationCategoryScore struct { Hate float64 `json:"hate"` HateThreatening float64 `json:"hate/threatening"` SelfHarm float64 `json:"self-harm"` Sexual float64 `json:"sexual"` SexualMinors float64 `json:"sexual/minors"` Violence float64 `json:"violence"` ViolenceGraphic float64 `json:"violence/graphic"` }
type ModerationCreateRequest ¶
type ModerationCreateResponse ¶
type ModerationCreateResponse struct { Id string `json:"id"` Model string `json:"model"` Results []*Moderation `json:"results"` }
type ModerationService ¶
type ModerationService interface {
Create(ctx context.Context, req *ModerationCreateRequest) (*ModerationCreateResponse, error)
}
type ModerationServiceOp ¶
type ModerationServiceOp struct {
// contains filtered or unexported fields
}
func (ModerationServiceOp) Create ¶
func (m ModerationServiceOp) Create(ctx context.Context, req *ModerationCreateRequest) (*ModerationCreateResponse, error)
type Option ¶
type Option func(*Client)
func WithFormBuilder ¶
func WithFormBuilder(builder func(w io.Writer) FormBuilder) Option
func WithLogger ¶
func WithRetries ¶
type TranscriptionsRequest ¶
type TranscriptionsRequest struct { // File is the path to the audio file File string `json:"file"` Model string `json:"model"` Prompt string `json:"prompt,omitempty"` ResponseFormat string `json:"response_format,omitempty"` Temperature float64 `json:"temperature,omitempty"` Language string `json:"language,omitempty"` }
type TranscriptionsResponse ¶
type TranscriptionsResponse struct {
Text string `json:"text"`
}
type TranslationsRequest ¶
type TranslationsResponse ¶
type TranslationsResponse struct {
Text string `json:"text"`
}