Class: Raif::ModelToolInvocation
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Raif::ModelToolInvocation
- Defined in:
- app/models/raif/model_tool_invocation.rb
Overview
Schema Information
Table name: raif_model_tool_invocations
id :bigint not null, primary key
completed_at :datetime
failed_at :datetime
result :jsonb not null
source_type :string not null
tool_arguments :jsonb not null
tool_type :string not null
created_at :datetime not null
updated_at :datetime not null
provider_tool_call_id :string
source_id :bigint not null
Indexes
index_raif_model_tool_invocations_on_source (source_type,source_id)
Instance Method Summary collapse
-
#as_tool_call_message(assistant_message: nil) ⇒ Hash
Returns tool call in the format expected by LLM message formatting.
-
#as_tool_call_result_message ⇒ Hash
Returns tool result in the format expected by LLM message formatting.
- #ensure_valid_tool_argument_schema ⇒ Object
- #to_partial_path ⇒ Object
- #tool ⇒ Object
Methods inherited from ApplicationRecord
table_name_prefix, where_json_not_blank
Instance Method Details
#as_tool_call_message(assistant_message: nil) ⇒ Hash
Returns tool call in the format expected by LLM message formatting
48 49 50 51 52 53 54 55 |
# File 'app/models/raif/model_tool_invocation.rb', line 48 def (assistant_message: nil) Raif::Messages::ToolCall.new( provider_tool_call_id: provider_tool_call_id, name: tool_name, arguments: tool_arguments, assistant_message: ).to_h end |
#as_tool_call_result_message ⇒ Hash
Returns tool result in the format expected by LLM message formatting
59 60 61 62 63 64 65 |
# File 'app/models/raif/model_tool_invocation.rb', line 59 def Raif::Messages::ToolCallResult.new( provider_tool_call_id: provider_tool_call_id, name: tool_name, result: result ).to_h end |
#ensure_valid_tool_argument_schema ⇒ Object
71 72 73 74 75 |
# File 'app/models/raif/model_tool_invocation.rb', line 71 def ensure_valid_tool_argument_schema unless JSON::Validator.validate(tool_arguments_schema, tool_arguments) errors.add(:tool_arguments, "does not match schema") end end |
#to_partial_path ⇒ Object
67 68 69 |
# File 'app/models/raif/model_tool_invocation.rb', line 67 def to_partial_path "raif/model_tool_invocations/#{tool.invocation_partial_name}" end |
#tool ⇒ Object
41 42 43 |
# File 'app/models/raif/model_tool_invocation.rb', line 41 def tool @tool ||= tool_type.constantize end |