Documentation ¶
Index ¶
Constants ¶
View Source
const (
DefaultCompletionModelPath = "completions"
)
DefaultCompletionModelPath default model.
Variables ¶
View Source
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") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the ERNIE API.
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 []float64 `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 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.
Click to show internal directories.
Click to hide internal directories.