Class: RubyCanUseLLM::Providers::Mistral

Inherits:
Base
  • Object
show all
Defined in:
lib/rubycanusellm/providers/mistral.rb

Constant Summary collapse

CHAT_URL =
"https://api.mistral.ai/v1/chat/completions"
EMBED_URL =
"https://api.mistral.ai/v1/embeddings"

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from RubyCanUseLLM::Providers::Base

Instance Method Details

#chat(messages, **options, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/rubycanusellm/providers/mistral.rb', line 13

def chat(messages, **options, &block)
  if options[:stream] && block
    body = build_body(messages, options.except(:stream)).merge(stream: true)
    stream_request(body, &block)
  else
    body = build_body(messages, options)
    response = request(body)
    parse_response(response)
  end
end

#embed(text, **options) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/rubycanusellm/providers/mistral.rb', line 24

def embed(text, **options)
  body = {
    model: options[:model] || "mistral-embed",
    input: text
  }
  response = embedding_request(body)
  parse_embedding(response)
end