Documentation
¶
Index ¶
- Variables
- type LLM
- func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOption) (string, error)
- func (o *LLM) CreateEmbedding(ctx context.Context, texts []string) ([][]float32, error)
- func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageContent, ...) (*llms.ContentResponse, error)
- type ModelName
- type Option
- func WithAPIKey(apiKey string) Option
- func WithAccessKey(accessKey string) Option
- func WithBaseURL(baseURL string) Option
- func WithCallbacks(handler callbacks.Handler) Option
- func WithEmbeddingModel(model ModelName) Option
- func WithHTTPClient(client *http.Client) Option
- func WithModel(model ModelName) Option
- func WithRegion(region string) Option
- func WithSecretKey(secretKey string) Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyResponse = errors.New("no response") ErrNoAuth = errors.New("no authentication provided") )
Functions ¶
This section is empty.
Types ¶
type LLM ¶
LLM is a client for Doubao (Volcengine Ark) LLM. It supports chat completions and embeddings using the volcengine-go-sdk.
func New ¶
New returns a new Doubao LLM client.
Authentication options (choose one): 1. WithAPIKey(apiKey) - API Key authentication (recommended) 2. WithAccessKey(ak) + WithSecretKey(sk) - AK/SK authentication
Model configuration: - WithModel(endpointID) - Set your custom Endpoint ID for chat completion - WithEmbeddingModel(endpointID) - Set your custom Endpoint ID for embeddings
To create an endpoint and get your Endpoint ID, visit: https://www.volcengine.com/docs/82379/1330310
Environment variables: - DOUBAO_API_KEY - API Key for authentication - DOUBAO_ACCESS_KEY - Access Key for AK/SK authentication - DOUBAO_SECRET_KEY - Secret Key for AK/SK authentication
Example:
llm, err := doubao.New(
doubao.WithAPIKey("your-api-key"),
doubao.WithModel("your-chat-endpoint-id"),
doubao.WithEmbeddingModel("your-embedding-endpoint-id"),
)
func (*LLM) CreateEmbedding ¶
CreateEmbedding generates embeddings for the given texts using Doubao embedding models.
Supported embedding models:
- doubao-embedding: 基础向量化模型
- doubao-embedding-large: 大型向量化模型
- doubao-embedding-vision: 多模态向量化模型
API documentation: https://www.volcengine.com/docs/82379/1521766
func (*LLM) GenerateContent ¶
func (o *LLM) GenerateContent(ctx context.Context, messages []llms.MessageContent, options ...llms.CallOption) (*llms.ContentResponse, error)
GenerateContent implements the Model interface. Uses Doubao chat completion API for text generation.
type ModelName ¶
type ModelName string
ModelName represents the model identifier for Doubao (Volcengine Ark) API.
IMPORTANT: You should use your custom Endpoint ID (推理接入点ID) as the model name. To create an endpoint and get your Endpoint ID, visit: https://www.volcengine.com/docs/82379/1330310
Example usage:
llm, err := doubao.New(
doubao.WithAPIKey("your-api-key"),
doubao.WithModel("your-endpoint-id"), // Use your Endpoint ID directly
)
type Option ¶
type Option func(*options)
Option is a function that configures an LLM.
func WithAPIKey ¶
WithAPIKey sets the API key for the LLM (recommended method).
func WithAccessKey ¶
WithAccessKey sets the Access Key for AK/SK authentication.
func WithBaseURL ¶
WithBaseURL sets the base URL for the LLM API. Default is "https://ark.cn-beijing.volces.com/api/v3".
func WithCallbacks ¶
WithCallbacks sets the callbacks handler for the LLM.
func WithEmbeddingModel ¶
WithEmbeddingModel sets the embedding model name. You should use your custom Endpoint ID as the model name.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client for the LLM.
func WithModel ¶
WithModel sets the model name for the LLM. You should use your custom Endpoint ID as the model name. To create an endpoint and get your Endpoint ID, visit: https://www.volcengine.com/docs/82379/1330310
func WithRegion ¶
WithRegion sets the region for the LLM API. Default is "cn-beijing".
func WithSecretKey ¶
WithSecretKey sets the Secret Key for AK/SK authentication.