Module: RubyLLM::Protocols::Responses::Tools

Defined in:
lib/ruby_llm/protocols/responses/tools.rb

Overview

Tools methods of the OpenAI Responses API. Function definitions are flat rather than nested under a function key.

Class Method Summary collapse

Class Method Details

.build_tool_choice(tool_choice) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_llm/protocols/responses/tools.rb', line 25

def build_tool_choice(tool_choice)
  case tool_choice
  when :auto, :none, :required
    tool_choice
  else
    {
      type: 'function',
      name: tool_choice
    }
  end
end

.tool_for(tool) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_llm/protocols/responses/tools.rb', line 11

def tool_for(tool)
  definition = {
    type: 'function',
    name: tool.name,
    description: tool.description,
    parameters: ChatCompletions::Tools.parameters_schema_for(tool),
    strict: false
  }

  return definition if tool.provider_options.empty?

  RubyLLM::Support::Utils.deep_merge(definition, tool.provider_options)
end