Class: GenAI::Language::Gemini

Inherits:
Base
  • Object
show all
Includes:
Api::Format::Gemini
Defined in:
lib/gen_ai/language/gemini.rb

Constant Summary collapse

COMPLETION_MODEL =
'gemini-pro'

Constants included from Api::Format::Gemini

Api::Format::Gemini::ASSISTANT_ROLE, Api::Format::Gemini::USER_ROLE

Constants inherited from Base

Base::DEFAULT_ROLE

Instance Method Summary collapse

Methods included from Api::Format::Gemini

#chunk_params_from_streaming, #extract_completions, #format_messages, #transform_message

Methods inherited from Base

#embed

Methods included from Dependency

#depends_on

Constructor Details

#initialize(token:, options: {}) ⇒ Gemini

Returns a new instance of Gemini.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gen_ai/language/gemini.rb', line 12

def initialize(token:, options: {})
  depends_on 'gemini-ai'

  @client = ::Gemini.new(
    credentials: {
      service: 'generative-language-api',
      api_key: token
    },
    options: { model: model(options) }
  )
end

Instance Method Details

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



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gen_ai/language/gemini.rb', line 26

def chat(messages, options = {}, &block)
  if block_given?
    response = @client.stream_generate_content(
      generate_options(messages, options), server_sent_events: true, &chunk_process_block(block)
    )
    build_result(model: model(options), raw: response.first, parsed: extract_completions(response).flatten)
  else
    response = @client.generate_content(generate_options(messages, options))
    build_result(model: model(options), raw: response, parsed: extract_completions(response))
  end
end

#complete(prompt, options = {}) ⇒ Object



24
# File 'lib/gen_ai/language/gemini.rb', line 24

def complete(prompt, options = {}); end