Module: Raif::Concerns::Llms::Bedrock::ToolFormatting
- Extended by:
- ActiveSupport::Concern
- Included in:
- Llms::Bedrock
- Defined in:
- app/models/raif/concerns/llms/bedrock/tool_formatting.rb
Instance Method Summary collapse
- #build_forced_tool_choice(tool_name) ⇒ Object
- #build_required_tool_choice ⇒ Object
- #build_tools_parameter(model_completion) ⇒ Object
Instance Method Details
#build_forced_tool_choice(tool_name) ⇒ Object
38 39 40 |
# File 'app/models/raif/concerns/llms/bedrock/tool_formatting.rb', line 38 def build_forced_tool_choice(tool_name) { tool: { name: tool_name } } end |
#build_required_tool_choice ⇒ Object
42 43 44 |
# File 'app/models/raif/concerns/llms/bedrock/tool_formatting.rb', line 42 def build_required_tool_choice { any: {} } end |
#build_tools_parameter(model_completion) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/raif/concerns/llms/bedrock/tool_formatting.rb', line 6 def build_tools_parameter(model_completion) tools = [] # If we're looking for a JSON response, add a tool to the request that the model can use to provide a JSON response if model_completion.response_format_json? && model_completion.json_response_schema.present? tools << { name: "json_response", description: "Generate a structured JSON response based on the provided schema.", input_schema: { json: model_completion.json_response_schema } } end model_completion.available_model_tools_map.each do |_tool_name, tool| tools << if tool.provider_managed? raise Raif::Errors::UnsupportedFeatureError, "Invalid provider-managed tool: #{tool.name} for #{key}" else { name: tool.tool_name, description: tool.tool_description, input_schema: { json: tool.tool_arguments_schema } } end end return {} if tools.blank? { tools: tools.map{|tool| { tool_spec: tool } } } end |