Module: LLM::RequestAdapter::Tool Private
- Included in:
- Bedrock::RequestAdapter::Completion
- Defined in:
- lib/llm/request_adapter/tool.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Reads the abstract tool calls a message carries.
A tool call is saved as {id, name, arguments} - the form
the runtime reasons about - and never in a provider's wire
form. Each adapter builds the block its provider expects
from that form, which is what lets a conversation saved
under one provider be restored under another.
Instance Method Summary collapse
-
#tool_calls ⇒ Array<LLM::Object>
private
The tool calls a message carries.
-
#adapt_tool_calls ⇒ Array<Hash>
private
The tool calls a message carries, in the shape the OpenAI-compatible chat completions APIs share.
-
#tool_call_arguments(call) ⇒ Hash
private
The parsed arguments of a tool call.
-
#tool_call_arguments_json(call) ⇒ String
private
The arguments of a tool call, as JSON.
Instance Method Details
#tool_calls ⇒ Array<LLM::Object>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The tool calls a message carries.
18 19 20 |
# File 'lib/llm/request_adapter/tool.rb', line 18 def tool_calls .extra[:tool_calls].to_a end |
#adapt_tool_calls ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The tool calls a message carries, in the shape the OpenAI-compatible chat completions APIs share.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/llm/request_adapter/tool.rb', line 26 def adapt_tool_calls tool_calls.filter_map do |call| next unless call[:id] and call[:name] { id: call[:id], type: "function", function: {name: call[:name], arguments: tool_call_arguments_json(call)} } end end |
#tool_call_arguments(call) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The parsed arguments of a tool call.
41 42 43 44 45 46 47 48 |
# File 'lib/llm/request_adapter/tool.rb', line 41 def tool_call_arguments(call) args = call[:arguments] case args when String then parse_tool_arguments(args) when nil then {} else args.respond_to?(:to_h) ? args.to_h : {} end end |
#tool_call_arguments_json(call) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The arguments of a tool call, as JSON.
54 55 56 |
# File 'lib/llm/request_adapter/tool.rb', line 54 def tool_call_arguments_json(call) LLM.json.dump(tool_call_arguments(call)) end |