mistral

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

mistral implements an API client for the Mistral AI API. https://docs.mistral.ai/api/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRequest

func GenerateRequest(model string, session *schema.Conversation, opts ...opt.Opt) (any, error)

GenerateRequest builds a generate request from options without sending it. Useful for testing and debugging.

func WithFrequencyPenalty

func WithFrequencyPenalty(value float64) opt.Opt

WithFrequencyPenalty sets the frequency penalty (-2.0 to 2.0). Positive values penalise tokens proportionally to how often they have appeared so far, reducing repetition.

func WithJSONOutput

func WithJSONOutput(schema *jsonschema.Schema) opt.Opt

WithJSONOutput constrains the model to produce JSON conforming to the given schema.

func WithMaxTokens

func WithMaxTokens(value uint) opt.Opt

WithMaxTokens sets the maximum number of tokens to generate (minimum 1).

func WithPresencePenalty

func WithPresencePenalty(value float64) opt.Opt

WithPresencePenalty sets the presence penalty (-2.0 to 2.0). Positive values penalise tokens that have already appeared, encouraging the model to talk about new topics.

func WithSafePrompt

func WithSafePrompt() opt.Opt

WithSafePrompt enables the safety prompt injection.

func WithSeed

func WithSeed(value uint) opt.Opt

WithSeed sets the random seed for deterministic generation.

func WithStopSequences

func WithStopSequences(values ...string) opt.Opt

WithStopSequences sets custom stop sequences for the request. Generation stops when any of the specified sequences is encountered.

func WithSystemPrompt

func WithSystemPrompt(value string) opt.Opt

WithSystemPrompt sets the system prompt for the request.

func WithTemperature

func WithTemperature(value float64) opt.Opt

WithTemperature sets the temperature for the request (0.0 to 1.5). Higher values produce more random output, lower values more deterministic.

func WithToolChoiceAny

func WithToolChoiceAny() opt.Opt

WithToolChoiceAny forces the model to use one of the available tools.

func WithToolChoiceAuto

func WithToolChoiceAuto() opt.Opt

WithToolChoiceAuto lets the model decide whether to use tools.

func WithToolChoiceNone

func WithToolChoiceNone() opt.Opt

WithToolChoiceNone prevents the model from using any tools.

func WithToolChoiceRequired

func WithToolChoiceRequired() opt.Opt

WithToolChoiceRequired forces the model to use a tool (alias for "required").

func WithTopP

func WithTopP(value float64) opt.Opt

WithTopP sets the nucleus sampling parameter (0.0 to 1.0). Tokens are selected from the smallest set whose cumulative probability exceeds top_p.

Types

type Client

type Client struct {
	*client.Client
	*modelcache.ModelCache
}

func New

func New(apiKey string, opts ...client.ClientOpt) (*Client, error)

New creates a new Mistral API client with the given API key

func (*Client) BatchEmbedding

func (c *Client) BatchEmbedding(ctx context.Context, model schema.Model, texts []string, _ ...opt.Opt) ([][]float64, error)

BatchEmbedding generates embedding vectors for multiple texts using the specified model.

func (*Client) Embedding

func (c *Client) Embedding(ctx context.Context, model schema.Model, text string, opts ...opt.Opt) ([]float64, error)

Embedding generates an embedding vector for a single text using the specified model.

func (*Client) GetModel

func (c *Client) GetModel(ctx context.Context, name string, opts ...opt.Opt) (*schema.Model, error)

GetModel returns a specific model by name

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context, opts ...opt.Opt) ([]schema.Model, error)

ListModels returns all available models from the Mistral API

func (*Client) Name

func (*Client) Name() string

Name returns the provider name

func (*Client) WithSession

func (c *Client) WithSession(ctx context.Context, model schema.Model, session *schema.Conversation, message *schema.Message, opts ...opt.Opt) (*schema.Message, *schema.Usage, error)

WithSession sends a message within a session and returns the response (stateful)

func (*Client) WithoutSession

func (c *Client) WithoutSession(ctx context.Context, model schema.Model, message *schema.Message, opts ...opt.Opt) (*schema.Message, *schema.Usage, error)

WithoutSession sends a single message and returns the response (stateless)

Jump to

Keyboard shortcuts

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