mistral

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: Apache-2.0 Imports: 6 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

func WithPrediction

func WithPrediction(v string) llm.Opt

Types

type Client

type Client struct {
	*client.Client
	// contains filtered or unexported fields
}

func New

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

Create a new client

func (*Client) ChatCompletion

func (mistral *Client) ChatCompletion(ctx context.Context, context llm.Context, opts ...llm.Opt) (*Response, error)

func (*Client) GenerateEmbedding

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

func (*Client) ListModels

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

ListModels returns all the models

func (*Client) Model

func (c *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 (c *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

type Completions

type Completions []Completion

Possible completions

func (Completions) Message

func (c Completions) Message(index int) *Message

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,omitempty"` // text, reference, image_url
	*Text       `json:"text,omitempty"`      // text content
	*Prediction `json:"content,omitempty"`   // prediction
	*Image      `json:"image_url,omitempty"` // image_url
}

func NewContent

func NewContent(t, v, p string) *Content

Return a Content object with text content (either in "text" or "prediction" field)

func NewImageAttachment

func NewImageAttachment(a *llm.Attachment) *Content

Return an image attachment

func NewTextContent

func NewTextContent(v string) *Content

Return a Content object with 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
	ToolCallArray `json:"tool_calls,omitempty"`
}

Message with text or object content

func (Message) Num

func (m Message) Num() int

func (Message) Role

func (m Message) Role() string

func (Message) Text

func (m Message) Text(index int) string

func (Message) ToolCalls

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

type Metrics

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

Metrics

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
	Id      string `json:"tool_call_id,omitempty"` // tool call - when role is tool
	Name    string `json:"name,omitempty"`         // function name - when role is tool
}

type Text

type Text string

text content

type ToolCall

type ToolCall struct {
	Id       string `json:"id,omitempty"`    // tool id
	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 ToolCallArray

type ToolCallArray []ToolCall

A set of tool calls

Jump to

Keyboard shortcuts

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