Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Choice ¶
type Choice struct {
Index int `json:"index"`
Message Message `json:"message"`
Delta Delta `json:"delta"`
FinishReason string `json:"finish_reason"`
}
Choice represents a choice in the completion response.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for Baidu Qianfan API using API Key authentication.
func (*Client) CreateCompletion ¶
func (c *Client) CreateCompletion(ctx context.Context, model string, req *CompletionRequest) (*CompletionResponse, error)
CreateCompletion sends a chat completion request.
func (*Client) CreateEmbedding ¶
func (c *Client) CreateEmbedding(ctx context.Context, model string, texts []string) (*EmbeddingResponse, error)
CreateEmbedding sends an embedding request.
type CompletionRequest ¶
type CompletionRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
PenaltyScore float64 `json:"penalty_score,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Stream bool `json:"stream,omitempty"`
StreamingFunc func(ctx context.Context, chunk []byte) error `json:"-"`
}
CompletionRequest represents a request to the chat completion API.
type CompletionResponse ¶
type CompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Result string `json:"result,omitempty"`
Choices []Choice `json:"choices"`
Usage Usage `json:"usage"`
ErrorCode int `json:"error_code,omitempty"`
ErrorMsg string `json:"error_msg,omitempty"`
}
CompletionResponse represents a response from the chat completion API.
type EmbedData ¶
type EmbedData struct {
Object string `json:"object"`
Embedding []float32 `json:"embedding"`
Index int `json:"index"`
}
EmbedData represents embedding data in the response.
type EmbeddingRequest ¶
EmbeddingRequest represents a request to the embedding API.
type EmbeddingResponse ¶
type EmbeddingResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Data []EmbedData `json:"data"`
Model string `json:"model"`
Usage Usage `json:"usage"`
ErrorCode int `json:"error_code,omitempty"`
ErrorMsg string `json:"error_msg,omitempty"`
}
EmbeddingResponse represents a response from the embedding API.
type Option ¶
type Option func(*clientOptions)
Option is a function that configures a Client.
func WithBaseURL ¶
WithBaseURL sets the base URL for the API.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client for the API.