Documentation ¶
Overview ¶
Package ernie provides a client library for interacting with the Ernie API, which offers natural language processing (NLP) capabilities, including chat completion and text embedding. Ernie is designed to assist with tasks such as generating human-like text responses or obtaining embeddings for text data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest 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"` }
ChatCompletionRequest represents a request for chat completion.
type ChatCompletionResponse ¶
type ChatCompletionResponse 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"` ErrorCode int `json:"error_code,omitempty"` ErrorMsg string `json:"error_msg,omitempty"` }
ChatCompletionResponse represents the response from chat completion API.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a client for interacting with the Ernie API.
func (*Client) CreateChatCompletion ¶
func (c *Client) CreateChatCompletion(ctx context.Context, model string, request *ChatCompletionRequest) (*ChatCompletionResponse, error)
CreateChatCompletion generates chat completion using the specified model and request.
func (*Client) CreateEmbedding ¶
func (c *Client) CreateEmbedding(ctx context.Context, model string, request EmbeddingRequest) (*EmbeddingResponse, error)
CreateEmbedding generates text embedding using the specified model and request.
type EmbeddingRequest ¶
type EmbeddingRequest struct {
Input []string `json:"input"`
}
EmbeddingRequest represents a request for text embedding.
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"` ErrorCode int `json:"error_code,omitempty"` ErrorMsg string `json:"error_msg,omitempty"` }
EmbeddingResponse represents the response from text embedding API.
type HTTPClient ¶
HTTPClient is an interface for making HTTP requests.
type Options ¶
type Options struct { // The base URL of the Ernie API. APIUrl string // The HTTP client to use for making API requests. HTTPClient HTTPClient }
Options represents configuration options for the Ernie client.