Class: GenAI::Language::Gemini
- 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
Instance Method Summary collapse
- #chat(messages, options = {}, &block) ⇒ Object
- #complete(prompt, options = {}) ⇒ Object
-
#initialize(token:, options: {}) ⇒ Gemini
constructor
A new instance of Gemini.
Methods included from Api::Format::Gemini
#chunk_params_from_streaming, #extract_completions, #format_messages, #transform_message
Methods inherited from Base
Methods included from Dependency
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() } ) 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(, = {}, &block) if block_given? response = @client.stream_generate_content( (, ), server_sent_events: true, &chunk_process_block(block) ) build_result(model: model(), raw: response.first, parsed: extract_completions(response).flatten) else response = @client.generate_content((, )) build_result(model: model(), 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, = {}); end |