mistral

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

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

Create a new client

func (*Client) DeleteModel added in v0.0.6

func (mistral *Client) DeleteModel(ctx context.Context, model string) error

Delete a fine-tuned model

func (*Client) GenerateEmbedding

func (mistral *Client) GenerateEmbedding(ctx context.Context, name string, prompt []string, _ ...llm.Opt) (*embeddings, error)

func (*Client) GetModel added in v0.0.6

func (mistral *Client) GetModel(ctx context.Context, model string) (*Model, error)

GetModel returns one model

func (*Client) ListModels

func (mistral *Client) ListModels(ctx context.Context) ([]Model, error)

ListModels returns all the models

func (*Client) Model

func (mistral *Client) Model(ctx context.Context, name string) llm.Model

Return a model by name, or nil if not found. Panics on error.

func (*Client) Models

func (mistral *Client) Models(ctx context.Context) ([]llm.Model, error)

Return the models

func (Client) Name

func (Client) Name() string

Return the name of the agent

type Completion

type Completion struct {
	Index   uint64   `json:"index"`
	Message *Message `json:"message"`
	Delta   *Message `json:"delta,omitempty"` // For streaming
	Reason  string   `json:"finish_reason,omitempty"`
}

Completion Variation

func (Completion) String added in v0.0.6

func (c Completion) String() string

type Completions

type Completions []Completion

Possible completions

func (Completions) Attachment added in v0.0.10

func (c Completions) Attachment(index int) *llm.Attachment

Return audio content for a specific completion

func (Completions) Choice added in v0.0.6

func (c Completions) Choice(index int) llm.Completion

Return message for a specific completion

func (Completions) Num

func (c Completions) Num() int

Return the number of completions

func (Completions) Role

func (c Completions) Role() string

Return the role of the completion

func (Completions) Text

func (c Completions) Text(index int) string

Return the text content for a specific completion

func (Completions) ToolCalls

func (c Completions) ToolCalls(index int) []llm.ToolCall

Return the current session tool calls given the completion index. Will return nil if no tool calls were returned.

type Content

type Content struct {
	Type        string                       `json:"type"` // text or content
	*Text       `json:"text,omitempty"`      // text content
	*Prediction `json:"content,omitempty"`   // prediction
	*Image      `json:"image_url,omitempty"` // image_url
}

func NewImageData added in v0.0.6

func NewImageData(image *llm.Attachment) *Content

func NewImageUrl added in v0.0.6

func NewImageUrl(u *url.URL) *Content

func NewPrediction added in v0.0.6

func NewPrediction(content Prediction) *Content

func NewTextContext added in v0.0.6

func NewTextContext(text Text) *Content

type Embedding

type Embedding struct {
	Type   string    `json:"object"`
	Index  uint64    `json:"index"`
	Vector []float64 `json:"embedding"`
}

Embedding is a single vector

func (Embedding) MarshalJSON

func (m Embedding) MarshalJSON() ([]byte, error)

type Embeddings

type Embeddings struct {
	Id    string      `json:"id"`
	Type  string      `json:"object"`
	Model string      `json:"model"`
	Data  []Embedding `json:"data"`
	Metrics
}

Embeddings is the metadata for a generated embedding vector

type Image

type Image string

either a URL or "data:image/png;base64," followed by the base64 encoded image

type Message

type Message struct {
	RoleContent
	Calls ToolCalls `json:"tool_calls,omitempty"`
}

Message with text or object content

func (*Message) Attachment added in v0.0.10

func (message *Message) Attachment(index int) *llm.Attachment

Unsupported

func (*Message) Choice added in v0.0.6

func (message *Message) Choice(index int) llm.Completion

Return the completion

func (Message) Num

func (Message) Num() int

func (*Message) Role

func (message *Message) Role() string

func (*Message) Text

func (message *Message) Text(index int) string

func (*Message) ToolCalls

func (message *Message) ToolCalls(index int) []llm.ToolCall

Return all the tool calls

type Metrics

type Metrics struct {
	InputTokens  uint64 `json:"prompt_tokens,omitempty"`
	OutputTokens uint   `json:"completion_tokens,omitempty"`
	TotalTokens  uint   `json:"total_tokens,omitempty"`
}

Metrics

func (Metrics) String added in v0.0.6

func (m Metrics) String() string

type Model

type Model struct {
	Name                    string   `json:"id"`
	Description             string   `json:"description,omitempty"`
	Type                    string   `json:"type,omitempty"`
	CreatedAt               *uint64  `json:"created,omitempty"`
	OwnedBy                 string   `json:"owned_by,omitempty"`
	MaxContextLength        uint64   `json:"max_context_length,omitempty"`
	Aliases                 []string `json:"aliases,omitempty"`
	Deprecation             *string  `json:"deprecation,omitempty"`
	DefaultModelTemperature *float64 `json:"default_model_temperature,omitempty"`
	Capabilities            struct {
		CompletionChat  bool `json:"completion_chat,omitempty"`
		CompletionFim   bool `json:"completion_fim,omitempty"`
		FunctionCalling bool `json:"function_calling,omitempty"`
		FineTuning      bool `json:"fine_tuning,omitempty"`
		Vision          bool `json:"vision,omitempty"`
	} `json:"capabilities,omitempty"`
}

type Prediction

type Prediction string

text content

type Response

type Response struct {
	Id          string `json:"id"`
	Type        string `json:"object"`
	Created     uint64 `json:"created"`
	Model       string `json:"model"`
	Completions `json:"choices"`
	*Metrics    `json:"usage,omitempty"`
}

Chat Completion Response

func (Response) String

func (r Response) String() string

type RoleContent

type RoleContent struct {
	Role    string `json:"role,omitempty"`         // assistant, user, tool, system
	Content any    `json:"content,omitempty"`      // string or array of text, reference, image_url
	Name    string `json:"name,omitempty"`         // function name - when role is tool
	Id      string `json:"tool_call_id,omitempty"` // tool call - when role is tool
}

type Text

type Text string

text content

type ToolCall

type ToolCall struct {
	Id       string `json:"id,omitempty"`    // tool id
	Type     string `json:"type,omitempty"`  // tool type (function)
	Index    uint64 `json:"index,omitempty"` // tool index
	Function struct {
		Name      string `json:"name,omitempty"`      // tool name
		Arguments string `json:"arguments,omitempty"` // tool arguments
	} `json:"function"`
}

type ToolCalls added in v0.0.6

type ToolCalls []toolcall

Jump to

Keyboard shortcuts

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