Class: LLM::Function
- Inherits:
-
Object
- Object
- LLM::Function
- Defined in:
- lib/llm/function.rb
Defined Under Namespace
Classes: Return
Instance Attribute Summary collapse
-
#arguments ⇒ Array?
Returns function arguments.
-
#id ⇒ String?
Returns the function ID.
-
#name ⇒ String
readonly
Returns the function name.
Instance Method Summary collapse
-
#call ⇒ Object
Call the function.
-
#called? ⇒ Boolean
Returns true when a function has been called.
-
#define(&b) ⇒ void
Set the function implementation.
-
#description(str) ⇒ void
Set the function description.
- #format(provider) ⇒ Hash
-
#initialize(name) {|self| ... } ⇒ Function
constructor
A new instance of Function.
- #params {|schema| ... } ⇒ void
Constructor Details
Instance Attribute Details
#arguments ⇒ Array?
Returns function arguments
15 16 17 |
# File 'lib/llm/function.rb', line 15 def arguments @arguments end |
#id ⇒ String?
Returns the function ID
20 21 22 |
# File 'lib/llm/function.rb', line 20 def id @id end |
#name ⇒ String (readonly)
Returns the function name
10 11 12 |
# File 'lib/llm/function.rb', line 10 def name @name end |
Instance Method Details
#call ⇒ Object
Call the function
58 59 60 61 62 |
# File 'lib/llm/function.rb', line 58 def call Return.new id, @runner.call(arguments) ensure @called = true end |
#called? ⇒ Boolean
Returns true when a function has been called
67 68 69 |
# File 'lib/llm/function.rb', line 67 def called? @called end |
#define(&b) ⇒ void
This method returns an undefined value.
Set the function implementation
50 51 52 |
# File 'lib/llm/function.rb', line 50 def define(&b) @runner = b end |
#description(str) ⇒ void
This method returns an undefined value.
Set the function description
35 36 37 |
# File 'lib/llm/function.rb', line 35 def description(str) @description = str end |
#format(provider) ⇒ Hash
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/llm/function.rb', line 73 def format(provider) case provider.class.to_s when "LLM::Gemini" {name: @name, description: @description, parameters: @params}.compact when "LLM::Anthropic" {name: @name, description: @description, input_schema: @params}.compact else { type: "function", name: @name, function: {name: @name, description: @description, parameters: @params} }.compact end end |
#params {|schema| ... } ⇒ void
This method returns an undefined value.
42 43 44 |
# File 'lib/llm/function.rb', line 42 def params @params = yield(@schema) end |