Class: Langchain::Assistant::Messages::GoogleGeminiMessage
- Defined in:
- lib/langchain/assistant/messages/google_gemini_message.rb
Constant Summary collapse
- ROLES =
Google Gemini uses the following roles:
[ "user", "model", "function" ].freeze
- TOOL_ROLE =
"function"
Instance Attribute Summary
Attributes inherited from Base
#content, #image_url, #role, #tool_call_id, #tool_calls
Instance Method Summary collapse
-
#function? ⇒ Boolean
Check if the message is a tool call.
-
#initialize(role:, content: nil, tool_calls: [], tool_call_id: nil) ⇒ GoogleGeminiMessage
constructor
Initialize a new Google Gemini message.
-
#llm? ⇒ Boolean
Check if the message came from an LLM.
-
#model? ⇒ Boolean
Check if the message came from an LLM.
-
#system? ⇒ Boolean
Google Gemini does not implement system prompts.
-
#to_hash ⇒ Hash
Convert the message to a Google Gemini API-compatible hash.
-
#tool? ⇒ Boolean
Check if the message is a tool call.
Methods inherited from Base
Constructor Details
#initialize(role:, content: nil, tool_calls: [], tool_call_id: nil) ⇒ GoogleGeminiMessage
Initialize a new Google Gemini message
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/langchain/assistant/messages/google_gemini_message.rb', line 22 def initialize(role:, content: nil, tool_calls: [], tool_call_id: nil) raise ArgumentError, "Role must be one of #{ROLES.join(", ")}" unless ROLES.include?(role) raise ArgumentError, "Tool calls must be an array of hashes" unless tool_calls.is_a?(Array) && tool_calls.all? { |tool_call| tool_call.is_a?(Hash) } @role = role # Some Tools return content as a JSON hence `.to_s` @content = content.to_s @tool_calls = tool_calls @tool_call_id = tool_call_id end |
Instance Method Details
#function? ⇒ Boolean
Check if the message is a tool call
79 80 81 |
# File 'lib/langchain/assistant/messages/google_gemini_message.rb', line 79 def function? role == "function" end |
#llm? ⇒ Boolean
Check if the message came from an LLM
36 37 38 |
# File 'lib/langchain/assistant/messages/google_gemini_message.rb', line 36 def llm? model? end |
#model? ⇒ Boolean
Check if the message came from an LLM
86 87 88 |
# File 'lib/langchain/assistant/messages/google_gemini_message.rb', line 86 def model? role == "model" end |
#system? ⇒ Boolean
Google Gemini does not implement system prompts
65 66 67 |
# File 'lib/langchain/assistant/messages/google_gemini_message.rb', line 65 def system? false end |
#to_hash ⇒ Hash
Convert the message to a Google Gemini API-compatible hash
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/langchain/assistant/messages/google_gemini_message.rb', line 43 def to_hash {}.tap do |h| h[:role] = role h[:parts] = if function? [{ functionResponse: { name: tool_call_id, response: { name: tool_call_id, content: content } } }] elsif tool_calls.any? tool_calls else [{text: content}] end end end |
#tool? ⇒ Boolean
Check if the message is a tool call
72 73 74 |
# File 'lib/langchain/assistant/messages/google_gemini_message.rb', line 72 def tool? function? end |