client

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSetAuth = errors.New("API key not set")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a client for Baidu Qianfan embedding API using API Key authentication.

func New

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

New creates a new Client with the given options.

func (*Client) CreateEmbedding

func (c *Client) CreateEmbedding(ctx context.Context, model string, texts []string) (*EmbeddingResponse, error)

CreateEmbedding sends an embedding request.

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

type EmbeddingRequest struct {
	Model string   `json:"model"`
	Input []string `json:"input"`
}

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 WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for the client.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the base URL for the API.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the HTTP client for the API.

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Usage represents token usage information.

Jump to

Keyboard shortcuts

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