Documentation ¶
Index ¶
- Constants
- Variables
- type ChatChoice
- type ChatMessage
- type ChatRequest
- type ChatResponse
- type ChatUsage
- type Client
- func (c *Client) CreateChat(ctx context.Context, r *ChatRequest) (*ChatResponse, error)
- func (c *Client) CreateCompletion(ctx context.Context, modelPath ModelPath, r *CompletionRequest) (*Completion, error)
- func (c *Client) CreateEmbedding(ctx context.Context, texts []string) (*EmbeddingResponse, error)
- type Completion
- type CompletionRequest
- type Doer
- type EmbeddingResponse
- type FunctionCall
- type FunctionCallBehavior
- type FunctionCallRes
- type FunctionDefinition
- type Message
- type ModelPath
- type Option
- type StreamedChatResponsePayload
Constants ¶
const (
DefaultCompletionModelPath = "completions"
)
DefaultCompletionModelPath default model.
Variables ¶
var ( ErrNotSetAuth = errors.New("both accessToken and apiKey secretKey are not set") ErrCompletionCode = errors.New("completion API returned unexpected status code") ErrAccessTokenCode = errors.New("get access_token API returned unexpected status code") ErrEmbeddingCode = errors.New("embedding API returned unexpected status code") ErrEmptyResponse = errors.New("empty response") )
Functions ¶
This section is empty.
Types ¶
type ChatChoice ¶
type ChatChoice struct { Index int `json:"index"` Message ChatMessage `json:"message"` FinishReason string `json:"finish_reason"` }
ChatChoice is a choice in a chat response.
type ChatMessage ¶
type ChatMessage struct { // The role of the author of this message. One of system, user, or assistant. Role string `json:"role"` // The content of the message. Content string `json:"content"` // The name of the author of this message. May contain a-z, A-Z, 0-9, and underscores, // with a maximum length of 64 characters. Name string `json:"name,omitempty"` // FunctionCall represents a function call to be made in the message. FunctionCall *schema.FunctionCall `json:"function_call,omitempty"` }
ChatMessage is a message in a chat request.
type ChatRequest ¶
type ChatRequest struct { Model string `json:"model,omitempty"` Messages []*ChatMessage `json:"messages"` Temperature float64 `json:"temperature,omitempty"` TopP float64 `json:"top_p,omitempty"` MaxTokens int `json:"max_tokens,omitempty"` N int `json:"n,omitempty"` StopWords []string `json:"stop,omitempty"` Stream bool `json:"stream,omitempty"` FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` PresencePenalty float64 `json:"presence_penalty,omitempty"` // If the 'functions' parameter is set, setting the 'system' parameter is not supported. System string `json:"system,omitempty"` // Function definitions to include in the request. Functions []FunctionDefinition `json:"functions,omitempty"` // FunctionCallBehavior is the behavior to use when calling functions. // // If a specific function should be invoked, use the format: // `{"name": "my_function"}` FunctionCallBehavior FunctionCallBehavior `json:"function_call,omitempty"` // StreamingFunc is a function to be called for each chunk of a streaming response. // Return an error to stop streaming early. StreamingFunc func(ctx context.Context, chunk []byte) error `json:"-"` }
ChatRequest is a request to complete a chat completion..
type ChatResponse ¶
type ChatResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Result string `json:"result"` IsTruncated bool `json:"is_truncated"` NeedClearHistory bool `json:"need_clear_history"` FunctionCall *FunctionCallRes `json:"function_call,omitempty"` Usage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` } `json:"usage"` }
type ChatUsage ¶
type ChatUsage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` }
ChatUsage is the usage of a chat completion request.
type Client ¶
Client is a client for the ERNIE API.
func (*Client) CreateChat ¶
func (c *Client) CreateChat(ctx context.Context, r *ChatRequest) (*ChatResponse, error)
CreateChat creates chat request.
func (*Client) CreateCompletion ¶
func (c *Client) CreateCompletion(ctx context.Context, modelPath ModelPath, r *CompletionRequest) (*Completion, error)
CreateCompletion creates a completion.
func (*Client) CreateEmbedding ¶
CreateEmbedding use ernie Embedding-V1.
type Completion ¶
type Completion struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` SentenceID int `json:"sentence_id"` IsEnd bool `json:"is_end"` IsTruncated bool `json:"is_truncated"` Result string `json:"result"` NeedClearHistory bool `json:"need_clear_history"` Usage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` } `json:"usage"` // for error ErrorCode int `json:"error_code,omitempty"` ErrorMsg string `json:"error_msg,omitempty"` }
Completion is a completion.
type CompletionRequest ¶
type CompletionRequest struct { Messages []Message `json:"messages"` Temperature float64 `json:"temperature,omitempty"` TopP float64 `json:"top_p,omitempty"` PenaltyScore float64 `json:"penalty_score,omitempty"` Stream bool `json:"stream,omitempty"` UserID string `json:"user_id,omitempty"` StreamingFunc func(ctx context.Context, chunk []byte) error `json:"-"` }
CompletionRequest is a request to create a completion.
type EmbeddingResponse ¶
type EmbeddingResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Data []struct { Object string `json:"object"` Embedding []float32 `json:"embedding"` Index int `json:"index"` } `json:"data"` Usage struct { PromptTokens int `json:"prompt_tokens"` TotalTokens int `json:"total_tokens"` } `json:"usage"` // for error ErrorCode int `json:"error_code,omitempty"` ErrorMsg string `json:"error_msg,omitempty"` }
type FunctionCall ¶
type FunctionCall struct { // Name is the name of the function to call. Name string `json:"name"` // Arguments is the set of arguments to pass to the function. Arguments string `json:"arguments"` }
FunctionCall is a call to a function.
type FunctionCallBehavior ¶
type FunctionCallBehavior string
FunctionCallBehavior is the behavior to use when calling functions.
const ( // FunctionCallBehaviorUnspecified is the empty string. FunctionCallBehaviorUnspecified FunctionCallBehavior = "" // FunctionCallBehaviorNone will not call any functions. FunctionCallBehaviorNone FunctionCallBehavior = "none" // FunctionCallBehaviorAuto will call functions automatically. FunctionCallBehaviorAuto FunctionCallBehavior = "auto" )
type FunctionCallRes ¶
type FunctionDefinition ¶
type FunctionDefinition struct { // Name is the name of the function. Name string `json:"name"` // Description is a description of the function. Description string `json:"description"` // Parameters is a list of parameters for the function. Parameters any `json:"parameters"` }
FunctionDefinition is a definition of a function that can be called by the model.
type Option ¶
Option is an option for the ERNIE client.
func WithAccessToken ¶
Usually used for dev, Prod env recommend use WithAKSK.
func WithHTTPClient ¶
WithHTTPClient allows setting a custom HTTP client.
type StreamedChatResponsePayload ¶
type StreamedChatResponsePayload struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` SentenceID int `json:"sentence_id"` IsEnd bool `json:"is_end"` IsTruncated bool `json:"is_truncated"` Result string `json:"result"` NeedClearHistory bool `json:"need_clear_history"` FunctionCall *FunctionCallRes `json:"function_call,omitempty"` Usage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` } `json:"usage"` }