Class: RCrewAI::LLMClients::Google
- Defined in:
- lib/rcrewai/llm_clients/google.rb
Constant Summary collapse
- BASE_URL =
'https://generativelanguage.googleapis.com/v1beta'- FINISH_REASON_MAP =
{ 'STOP' => :stop, 'MAX_TOKENS' => :length, 'SAFETY' => :stop, 'RECITATION' => :stop }.freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **options) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#initialize(config = RCrewAI.configuration) ⇒ Google
constructor
A new instance of Google.
- #models ⇒ Object
-
#supports_native_tools?(model: config.model) ⇒ Boolean
rubocop:disable Lint/UnusedMethodArgument.
Methods inherited from Base
Constructor Details
#initialize(config = RCrewAI.configuration) ⇒ Google
Returns a new instance of Google.
23 24 25 26 |
# File 'lib/rcrewai/llm_clients/google.rb', line 23 def initialize(config = RCrewAI.configuration) super @base_url = BASE_URL end |
Instance Method Details
#chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **options) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rcrewai/llm_clients/google.rb', line 28 def chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **) # rubocop:disable Lint/UnusedMethodArgument contents = () payload = { contents: contents, generationConfig: { temperature: [:temperature] || config.temperature, maxOutputTokens: [:max_tokens] || config.max_tokens || 2048 }.compact } payload[:generationConfig][:topP] = [:top_p] if [:top_p] payload[:generationConfig][:topK] = [:top_k] if [:top_k] payload[:generationConfig][:stopSequences] = [:stop_sequences] if [:stop_sequences] payload[:safetySettings] = [:safety_settings] if [:safety_settings] if tools && !tools.empty? payload[:tools] = [ProviderSchema.for_many(:google, tools)] # tool_choice: Google has toolConfig; left as default unless explicitly set end api_key = config.google_api_key || config.api_key if stream url = "#{@base_url}/models/#{config.model}:streamGenerateContent?alt=sse&key=#{api_key}" stream_chat(url, payload, stream) else url = "#{@base_url}/models/#{config.model}:generateContent?key=#{api_key}" plain_chat(url, payload) end end |
#models ⇒ Object
61 62 63 |
# File 'lib/rcrewai/llm_clients/google.rb', line 61 def models %w[gemini-pro gemini-1.5-pro gemini-1.5-flash gemini-pro-vision] end |
#supports_native_tools?(model: config.model) ⇒ Boolean
rubocop:disable Lint/UnusedMethodArgument
57 58 59 |
# File 'lib/rcrewai/llm_clients/google.rb', line 57 def supports_native_tools?(model: config.model) # rubocop:disable Lint/UnusedMethodArgument true end |