mistral

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultEmbeddingModel = "mistral-embed"
	ModelContextVar       = "model"
	APIKeyEnvVar          = "MISTRAL_API_KEY"
	DefaultBaseURL        = "https://api.mistral.ai"
	EmbeddingsEndpoint    = "/v1/embeddings"
	DefaultMaxBatchSize   = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	DefaultModel      string
	Client            *http.Client
	DefaultContext    *context.Context
	MaxBatchSize      int
	EmbeddingEndpoint string
	DefaultHeaders    map[string]string
	// contains filtered or unexported fields
}

func NewMistralClient

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

func (*Client) CreateEmbedding

func (c *Client) CreateEmbedding(ctx context.Context, req CreateEmbeddingRequest) ([]*types.Embedding, error)

type CreateEmbeddingRequest

type CreateEmbeddingRequest struct {
	Model          string   `json:"model"`
	Input          []string `json:"input"`
	EncodingFormat string   `json:"encoding_format,omitempty"`
}

func (*CreateEmbeddingRequest) JSON

func (c *CreateEmbeddingRequest) JSON() (string, error)

type CreateEmbeddingResponse

type CreateEmbeddingResponse struct {
	ID     string         `json:"id"`
	Object string         `json:"object"`
	Model  string         `json:"model"`
	Usage  map[string]any `json:"usage"`
	Data   []Embedding    `json:"data"`
}

type Embedding

type Embedding struct {
	Object    string    `json:"object"`
	Embedding []float32 `json:"embedding"` // TODO this can be also ints depending on encoding format
	Index     int       `json:"index"`
}

type MistralEmbeddingFunction

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

func NewMistralEmbeddingFunction

func NewMistralEmbeddingFunction(opts ...Option) (*MistralEmbeddingFunction, error)

func (*MistralEmbeddingFunction) EmbedDocuments

func (e *MistralEmbeddingFunction) EmbedDocuments(ctx context.Context, documents []string) ([]*types.Embedding, error)

func (*MistralEmbeddingFunction) EmbedQuery

func (e *MistralEmbeddingFunction) EmbedQuery(ctx context.Context, document string) (*types.Embedding, error)

func (*MistralEmbeddingFunction) EmbedRecords

func (e *MistralEmbeddingFunction) EmbedRecords(ctx context.Context, records []*types.Record, force bool) error

type Option

type Option func(p *Client) error

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 client

func WithDefaultModel

func WithDefaultModel(model string) Option

WithDefaultModel sets the default model for the client

func WithEnvAPIKey

func WithEnvAPIKey() Option

WithEnvAPIKey sets the API key for the client from the environment variable GOOGLE_API_KEY

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the generative AI client for the client

func WithMaxBatchSize

func WithMaxBatchSize(maxBatchSize int) Option

WithMaxBatchSize sets the max batch size for the client - this acts as a limit for the number of embeddings that can be sent in a single request

Jump to

Keyboard shortcuts

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