Class: Ollama::ToolDSL
- Inherits:
-
Object
- Object
- Ollama::ToolDSL
- Defined in:
- lib/ollama/tool_dsl.rb
Overview
Optional class-based DSL for tools.
Subclasses produce a tool hash compatible with tools:.
Example:
class WeatherTool < Ollama::ToolDSL description "Get current weather for a city" tool_name "get_weather" input do string :city, description: "The name of the city" string :unit, optional: true, default: "celsius" end call { constructor } end
client.chat(messages: [...], tools: [WeatherTool.to_tool_hash])
Class Attribute Summary collapse
-
.input_schema ⇒ Object
readonly
Returns the value of attribute input_schema.
-
.output_schema ⇒ Object
readonly
Returns the value of attribute output_schema.
-
.tool_description ⇒ Object
readonly
Returns the value of attribute tool_description.
-
.user_block ⇒ Object
readonly
Returns the value of attribute user_block.
Class Method Summary collapse
- .call(&block) ⇒ Object
- .description(text) ⇒ Object
- .input(&block) ⇒ Object
- .output(&block) ⇒ Object
- .to_tool_hash ⇒ Object
- .tool_name(text = nil) ⇒ Object
Class Attribute Details
.input_schema ⇒ Object (readonly)
Returns the value of attribute input_schema.
23 24 25 |
# File 'lib/ollama/tool_dsl.rb', line 23 def input_schema @input_schema end |
.output_schema ⇒ Object (readonly)
Returns the value of attribute output_schema.
23 24 25 |
# File 'lib/ollama/tool_dsl.rb', line 23 def output_schema @output_schema end |
.tool_description ⇒ Object (readonly)
Returns the value of attribute tool_description.
23 24 25 |
# File 'lib/ollama/tool_dsl.rb', line 23 def tool_description @tool_description end |
.user_block ⇒ Object (readonly)
Returns the value of attribute user_block.
23 24 25 |
# File 'lib/ollama/tool_dsl.rb', line 23 def user_block @user_block end |
Class Method Details
.call(&block) ⇒ Object
42 43 44 45 |
# File 'lib/ollama/tool_dsl.rb', line 42 def call(&block) @user_block = block def_constructor end |
.description(text) ⇒ Object
25 26 27 |
# File 'lib/ollama/tool_dsl.rb', line 25 def description(text) @tool_description = text end |
.input(&block) ⇒ Object
34 35 36 |
# File 'lib/ollama/tool_dsl.rb', line 34 def input(&block) @input_schema = SchemaDSL.define(&block).to_h end |
.output(&block) ⇒ Object
38 39 40 |
# File 'lib/ollama/tool_dsl.rb', line 38 def output(&block) @output_schema = SchemaDSL.define(&block).to_h end |
.to_tool_hash ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ollama/tool_dsl.rb', line 47 def to_tool_hash function = { "name" => tool_name || tool_method_name, "description" => tool_description || "", "strict" => true } function["parameters"] = input_schema if input_schema { "type" => "function", "function" => function } end |
.tool_name(text = nil) ⇒ Object
29 30 31 32 |
# File 'lib/ollama/tool_dsl.rb', line 29 def tool_name(text = nil) @tool_name = text unless text.nil? @tool_name end |