Class: LLM::Mistral

Inherits:
OpenAI show all
Includes:
Mistral::RequestAdapter
Defined in:
lib/llm/providers/mistral.rb,
lib/llm/providers/mistral/request_adapter.rb

Overview

The Mistral class implements a provider for Mistral through its OpenAI-compatible API.

Examples:

#!/usr/bin/env ruby
require "llm"

llm = LLM.mistral(key: ENV["KEY"])
ctx = LLM::Context.new(llm)
ctx.talk "Hello"
ctx.messages.select(&:assistant?).each { print "[#{_1.role}]", _1.content, "\n" }

Defined Under Namespace

Modules: RequestAdapter

Constant Summary collapse

HOST =
"api.mistral.ai"
BASE_PATH =
"/v1/"

Instance Method Summary collapse

Methods inherited from OpenAI

#assistant_role, #complete, #models, #server_tools, #web_search

Methods included from OpenAI::RequestAdapter

#adapt

Methods inherited from Provider

#assistant_role, #chat, #complete, #developer_role, #inspect, #interrupt!, #key?, #models, #request_owner, #respond, #schema, #server_tool, #server_tools, #system_role, #tool_role, #tracer, #tracer=, #user_role, #web_search, #with, #with_tracer

Constructor Details

#initialize(host: HOST, base_path: BASE_PATH) ⇒ LLM::Mistral

Parameters:

  • key (String, nil)

    The secret key for authentication

  • host (String) (defaults to: HOST)

    The host address of the LLM provider

  • base_path (String) (defaults to: BASE_PATH)

    Optional base path prefix for HTTP API routes.



31
32
33
# File 'lib/llm/providers/mistral.rb', line 31

def initialize(host: HOST, base_path: BASE_PATH, **)
  super
end

Instance Method Details

#audioLLM::Mistral::Audio

Returns:

Raises:

  • (NotImplementedError)


93
94
95
# File 'lib/llm/providers/mistral.rb', line 93

def audio
  raise NotImplementedError
end

#default_modelString

Returns the default model for chat completions

Returns:

  • (String)


118
119
120
# File 'lib/llm/providers/mistral.rb', line 118

def default_model
  "mistral-large-latest"
end

#embed(input, model: "mistral-embed", **params) ⇒ LLM::Response

Provides an embedding.

Parameters:

  • input (String, Array<String>)

    The input to embed

  • model (String) (defaults to: "mistral-embed")

    The embedding model to use

  • params (Hash)

    Other embedding parameters

Returns:



55
56
57
# File 'lib/llm/providers/mistral.rb', line 55

def embed(input, model: "mistral-embed", **params)
  super
end

#filesObject

Raises:

  • (NotImplementedError)


99
100
101
# File 'lib/llm/providers/mistral.rb', line 99

def files
  raise NotImplementedError
end

#imagesNotImplementedError

Returns:

  • (NotImplementedError)

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/llm/providers/mistral.rb', line 44

def images
  raise NotImplementedError
end

#moderationsObject

Raises:

  • (NotImplementedError)


105
106
107
# File 'lib/llm/providers/mistral.rb', line 105

def moderations
  raise NotImplementedError
end

#nameSymbol

Returns the provider's name

Returns:

  • (Symbol)

    Returns the provider's name



38
39
40
# File 'lib/llm/providers/mistral.rb', line 38

def name
  :mistral
end

#ocr(image_url: nil, document_url: nil, model: "mistral-ocr-latest", **params) ⇒ LLM::Response

Runs OCR on a remote image or document URL.

Parameters:

  • image_url (String, nil) (defaults to: nil)

    A remote HTTP(S) URL to the image

  • document_url (String, nil) (defaults to: nil)

    A remote HTTP(S) URL to the document

  • model (String) (defaults to: "mistral-ocr-latest")

    The OCR model to use

  • params (Hash)

    Additional OCR parameters

Returns:

See Also:



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/llm/providers/mistral.rb', line 72

def ocr(image_url: nil, document_url: nil, model: "mistral-ocr-latest", **params)
  if [image_url, document_url].all?(&:nil?)
    raise ArgumentError, "must provide one of: image_url, document_url"
  elsif [image_url, document_url].compact.size > 1
    raise ArgumentError, "must provide one of: image_url, document_url"
  end
  document = parse_document(image_url, document_url)
  req = LLM::Transport::Request.post("/v1/ocr", headers)
  req.body = LLM.json.dump({model:, document:}.merge!(params))
  res, = execute(request: req, operation: "ocr", model:)
  LLM::Response.new(res)
end

#responsesObject

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/llm/providers/mistral.rb', line 87

def responses
  raise NotImplementedError
end

#vector_storesObject

Raises:

  • (NotImplementedError)


111
112
113
# File 'lib/llm/providers/mistral.rb', line 111

def vector_stores
  raise NotImplementedError
end