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.
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 inherited from Provider
#assistant_role, #build_messages, #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
31
32
33
|
# File 'lib/llm/providers/mistral.rb', line 31
def initialize(host: HOST, base_path: BASE_PATH, **)
super
end
|
Instance Method Details
#adapt_function(fn) ⇒ Hash
125
126
127
128
129
130
131
|
# File 'lib/llm/providers/mistral.rb', line 125
def adapt_function(fn)
params = fn.params.to_h
{
type: "function",
function: {name: fn.name, description: fn.description, parameters: params}
}.compact
end
|
#name ⇒ Symbol
Returns the provider's name
38
39
40
|
# File 'lib/llm/providers/mistral.rb', line 38
def name
:mistral
end
|
#images ⇒ NotImplementedError
44
45
46
|
# File 'lib/llm/providers/mistral.rb', line 44
def images
raise NotImplementedError
end
|
#embed(input, model: "mistral-embed", **params) ⇒ LLM::Response
55
56
57
|
# File 'lib/llm/providers/mistral.rb', line 55
def embed(input, model: "mistral-embed", **params)
super
end
|
#ocr(image_url: nil, document_url: nil, model: "mistral-ocr-latest", **params) ⇒ LLM::Response
Runs OCR on a remote image or document URL.
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", )
req.body = LLM.json.dump({model:, document:}.merge!(params))
res, = execute(request: req, operation: "ocr", model:)
LLM::Response.new(res)
end
|
#responses ⇒ Object
87
88
89
|
# File 'lib/llm/providers/mistral.rb', line 87
def responses
raise NotImplementedError
end
|
93
94
95
|
# File 'lib/llm/providers/mistral.rb', line 93
def audio
raise NotImplementedError
end
|
99
100
101
|
# File 'lib/llm/providers/mistral.rb', line 99
def files
raise NotImplementedError
end
|
#moderations ⇒ Object
105
106
107
|
# File 'lib/llm/providers/mistral.rb', line 105
def moderations
raise NotImplementedError
end
|
#vector_stores ⇒ Object
111
112
113
|
# File 'lib/llm/providers/mistral.rb', line 111
def vector_stores
raise NotImplementedError
end
|
#default_model ⇒ String
Returns the default model for chat completions
118
119
120
|
# File 'lib/llm/providers/mistral.rb', line 118
def default_model
"mistral-large-latest"
end
|