Module: RubyLlmMesh::Rag::Tools

Defined in:
lib/ruby_llm_mesh/rag/tools.rb

Overview

Helpers for structuring tool / function-calling schemas across providers.

Class Method Summary collapse

Class Method Details

.define(name:, description:, parameters: {}, required: []) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ruby_llm_mesh/rag/tools.rb', line 9

def define(name:, description:, parameters: {}, required: [])
  {
    name: name.to_s,
    description: description.to_s,
    parameters: {
      type: "object",
      properties: parameters,
      required: Array(required).map(&:to_s)
    }
  }
end

.for_anthropic(tools) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/ruby_llm_mesh/rag/tools.rb', line 34

def for_anthropic(tools)
  Array(tools).map do |tool|
    {
      name: tool[:name] || tool["name"],
      description: tool[:description] || tool["description"],
      input_schema: tool[:parameters] || tool["parameters"]
    }
  end
end

.for_openai(tools) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_llm_mesh/rag/tools.rb', line 21

def for_openai(tools)
  Array(tools).map do |tool|
    {
      type: "function",
      function: {
        name: tool[:name] || tool["name"],
        description: tool[:description] || tool["description"],
        parameters: tool[:parameters] || tool["parameters"]
      }
    }
  end
end