Module: Raif::Concerns::Llms::Anthropic::ToolFormatting
- Extended by:
- ActiveSupport::Concern
- Included in:
- Llms::Anthropic
- Defined in:
- app/models/raif/concerns/llms/anthropic/tool_formatting.rb
Instance Method Summary collapse
Instance Method Details
#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 |
# File 'app/models/raif/concerns/llms/anthropic/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: model_completion.json_response_schema } end # If we support native tool use and have tools available, add them to the request if supports_native_tool_use? && model_completion.available_model_tools.any? model_completion.available_model_tools_map.each do |_tool_name, tool| tools << if tool.provider_managed? format_provider_managed_tool(tool) else { name: tool.tool_name, description: tool.tool_description, input_schema: tool.tool_arguments_schema } end end end tools end |
#format_provider_managed_tool(tool) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/raif/concerns/llms/anthropic/tool_formatting.rb', line 36 def format_provider_managed_tool(tool) validate_provider_managed_tool_support!(tool) case tool.name when "Raif::ModelTools::ProviderManaged::WebSearch" { type: "web_search_20250305", name: "web_search", max_uses: 5 } when "Raif::ModelTools::ProviderManaged::CodeExecution" { type: "code_execution_20250522", name: "code_execution" } else raise Raif::Errors::UnsupportedFeatureError, "Invalid provider-managed tool: #{tool.name} for #{key}" end end |