doubao

package
v0.8.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyResponse = errors.New("no response")
	ErrNoAuth        = errors.New("no authentication provided")
)

Functions

This section is empty.

Types

type LLM

type LLM struct {
	CallbacksHandler callbacks.Handler
	// contains filtered or unexported fields
}

LLM is a client for Doubao (Volcengine Ark) LLM. It supports chat completions and embeddings using the volcengine-go-sdk.

func New

func New(opts ...Option) (*LLM, error)

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) Call

func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOption) (string, error)

Call generates a response from the LLM for the given prompt.

func (*LLM) CreateEmbedding

func (o *LLM) CreateEmbedding(ctx context.Context, texts []string) ([][]float32, error)

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

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for the LLM (recommended method).

func WithAccessKey

func WithAccessKey(accessKey string) Option

WithAccessKey sets the Access Key for AK/SK authentication.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the base URL for the LLM API. Default is "https://ark.cn-beijing.volces.com/api/v3".

func WithCallbacks

func WithCallbacks(handler callbacks.Handler) Option

WithCallbacks sets the callbacks handler for the LLM.

func WithEmbeddingModel

func WithEmbeddingModel(model ModelName) Option

WithEmbeddingModel sets the embedding model name. You should use your custom Endpoint ID as the model name.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the HTTP client for the LLM.

func WithModel

func WithModel(model ModelName) Option

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

func WithRegion(region string) Option

WithRegion sets the region for the LLM API. Default is "cn-beijing".

func WithSecretKey

func WithSecretKey(secretKey string) Option

WithSecretKey sets the Secret Key for AK/SK authentication.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL