Class: GeminiCraft::Client
- Inherits:
-
Object
- Object
- GeminiCraft::Client
- Defined in:
- lib/gemini_craft/client.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #generate_content(text, system_instruction = nil, options = {}, stream: false) ⇒ Object
- #generate_with_functions(text, functions, system_instruction = nil, options = {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 |
# File 'lib/gemini_craft/client.rb', line 13 def initialize @config = GeminiCraft.configuration @config.validate! @cache = Cache.new(@config) @logger = setup_logger end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
11 12 13 |
# File 'lib/gemini_craft/client.rb', line 11 def cache @cache end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/gemini_craft/client.rb', line 11 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
11 12 13 |
# File 'lib/gemini_craft/client.rb', line 11 def logger @logger end |
Instance Method Details
#generate_content(text, system_instruction = nil, options = {}, stream: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gemini_craft/client.rb', line 20 def generate_content(text, system_instruction = nil, = {}, stream: false) log(:info, "Generating content", { model: @config.model, stream: stream }) cache_key = generate_cache_key(text, system_instruction, ) unless stream if !stream && @config.cache_enabled && (cached_response = @cache.get(cache_key)) log(:debug, "Cache hit", { cache_key: cache_key }) return cached_response end payload = build_payload(text, system_instruction, , stream: stream) if stream generate_streaming_content(payload) else generate_standard_content(payload, cache_key) end rescue StandardError => e log(:error, "Content generation failed", { error: e. }) raise end |
#generate_with_functions(text, functions, system_instruction = nil, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/gemini_craft/client.rb', line 42 def generate_with_functions(text, functions, system_instruction = nil, = {}) log(:info, "Generating content with functions", { function_count: functions.size }) payload = build_payload(text, system_instruction, ) payload[:tools] = [{ function_declarations: functions }] response = make_request("models/#{@config.model}:generateContent", payload) process_function_response(response) end |