Class: LLM::Clients::Gemini

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/llm/clients/gemini.rb,
lib/llm/clients/gemini/request.rb,
lib/llm/clients/gemini/response.rb

Defined Under Namespace

Classes: Request, Response

Instance Method Summary collapse

Constructor Details

#initialize(llm:) ⇒ Gemini

Returns a new instance of Gemini.



12
13
14
# File 'lib/llm/clients/gemini.rb', line 12

def initialize(llm:)
  @llm = llm
end

Instance Method Details

#chat(messages, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/llm/clients/gemini.rb', line 16

def chat(messages, options = {})
  req = Request.new(messages, options)

  return chat_streaming(req, options[:on_message], options[:on_complete]) if options[:stream]

  resp = post_url(
    "/v1beta/models/#{llm.canonical_name}:generateContent",
    body: req.params.to_json
  )

  Response.new(resp).to_normalized_response
end