Class: Raif::Llms::Google

Inherits:
Raif::Llm
  • Object
show all
Includes:
Concerns::Llms::Google::BatchInference, Concerns::Llms::Google::MessageFormatting, Concerns::Llms::Google::ResponseToolCalls, Concerns::Llms::Google::ToolFormatting
Defined in:
app/models/raif/llms/google.rb

Constant Summary collapse

API_BASE_URL =
"https://generativelanguage.googleapis.com/v1beta"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cache_read_input_token_cost_multiplier ⇒ Object



11
12
13
# File 'app/models/raif/llms/google.rb', line 11

def self.cache_read_input_token_cost_multiplier
  0.1
end

Instance Method Details

#perform_model_completion!(model_completion, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/raif/llms/google.rb', line 15

def perform_model_completion!(model_completion, &block)
  # Raif::Llm#chat fills in a default temperature, so clear it to keep the saved row matching the request.
  model_completion.temperature = nil unless supports_temperature?
  params = build_request_parameters(model_completion)
  endpoint = build_endpoint(model_completion)

  response = connection.post(endpoint) do |req|
    req.body = params
    req.options.on_data = streaming_chunk_handler(model_completion, &block) if model_completion.stream_response?
  end

  unless model_completion.stream_response?
    update_model_completion(model_completion, response.body)
  end

  model_completion
end

#supports_faithful_required_tool_choice?(available_model_tools) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'app/models/raif/llms/google.rb', line 33

def supports_faithful_required_tool_choice?(available_model_tools)
  super && Array(available_model_tools).none? do |tool|
    tool_class = tool.is_a?(String) ? tool.constantize : tool
    tool_class.provider_managed?
  end
end