Class: Langchain::Assistant::LLM::Adapters::GoogleGemini
- Defined in:
- lib/langchain/assistant/llm/adapters/google_gemini.rb
Instance Method Summary collapse
-
#allowed_tool_choices ⇒ Object
Get the allowed assistant.tool_choice values for Google Gemini.
-
#available_tool_names(tools) ⇒ Object
Get the available tool names for Google Gemini.
-
#build_chat_params(messages:, instructions:, tools:, tool_choice:, parallel_tool_calls:) ⇒ Hash
Build the chat parameters for the Google Gemini LLM.
-
#build_message(role:, content: nil, image_url: nil, tool_calls: [], tool_call_id: nil) ⇒ Messages::GoogleGeminiMessage
Build a Google Gemini message.
-
#build_tools(tools) ⇒ Array
Build the tools for the Google Gemini LLM.
-
#extract_tool_call_args(tool_call:) ⇒ Array
Extract the tool call information from the Google Gemini tool call hash.
- #support_system_message? ⇒ Boolean
- #tool_role ⇒ Object
Instance Method Details
#allowed_tool_choices ⇒ Object
Get the allowed assistant.tool_choice values for Google Gemini
69 70 71 |
# File 'lib/langchain/assistant/llm/adapters/google_gemini.rb', line 69 def allowed_tool_choices ["auto", "none"] end |
#available_tool_names(tools) ⇒ Object
Get the available tool names for Google Gemini
74 75 76 |
# File 'lib/langchain/assistant/llm/adapters/google_gemini.rb', line 74 def available_tool_names(tools) build_tools(tools).map { |tool| tool.dig(:name) } end |
#build_chat_params(messages:, instructions:, tools:, tool_choice:, parallel_tool_calls:) ⇒ Hash
Build the chat parameters for the Google Gemini LLM
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/langchain/assistant/llm/adapters/google_gemini.rb', line 16 def build_chat_params( messages:, instructions:, tools:, tool_choice:, parallel_tool_calls: ) Langchain.logger.warn "WARNING: `parallel_tool_calls:` is not supported by Google Gemini currently" params = {messages: } if tools.any? params[:tools] = build_tools(tools) params[:system] = instructions if instructions params[:tool_choice] = build_tool_config(tool_choice) end params end |
#build_message(role:, content: nil, image_url: nil, tool_calls: [], tool_call_id: nil) ⇒ Messages::GoogleGeminiMessage
Build a Google Gemini message
42 43 44 45 46 |
# File 'lib/langchain/assistant/llm/adapters/google_gemini.rb', line 42 def (role:, content: nil, image_url: nil, tool_calls: [], tool_call_id: nil) Langchain.logger.warn "Image URL is not supported by Google Gemini" if image_url Messages::GoogleGeminiMessage.new(role: role, content: content, tool_calls: tool_calls, tool_call_id: tool_call_id) end |
#build_tools(tools) ⇒ Array
Build the tools for the Google Gemini LLM
64 65 66 |
# File 'lib/langchain/assistant/llm/adapters/google_gemini.rb', line 64 def build_tools(tools) tools.map { |tool| tool.class.function_schemas.to_google_gemini_format }.flatten end |
#extract_tool_call_args(tool_call:) ⇒ Array
Extract the tool call information from the Google Gemini tool call hash
52 53 54 55 56 57 58 |
# File 'lib/langchain/assistant/llm/adapters/google_gemini.rb', line 52 def extract_tool_call_args(tool_call:) tool_call_id = tool_call.dig("functionCall", "name") function_name = tool_call.dig("functionCall", "name") tool_name, method_name = function_name.split("__") tool_arguments = tool_call.dig("functionCall", "args").transform_keys(&:to_sym) [tool_call_id, tool_name, method_name, tool_arguments] end |
#support_system_message? ⇒ Boolean
82 83 84 |
# File 'lib/langchain/assistant/llm/adapters/google_gemini.rb', line 82 def Messages::GoogleGeminiMessage::ROLES.include?("system") end |
#tool_role ⇒ Object
78 79 80 |
# File 'lib/langchain/assistant/llm/adapters/google_gemini.rb', line 78 def tool_role Messages::GoogleGeminiMessage::TOOL_ROLE end |