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.
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
10 11 12 |
# File 'lib/llm/function.rb', line 10 def arguments @arguments end |
#id ⇒ String?
Returns the function ID
15 16 17 |
# File 'lib/llm/function.rb', line 15 def id @id end |
Instance Method Details
#call ⇒ Object
Call the function
53 54 55 56 57 |
# File 'lib/llm/function.rb', line 53 def call Return.new id, @runner.call(arguments) ensure @called = true end |
#called? ⇒ Boolean
Returns true when a function has been called
62 63 64 |
# File 'lib/llm/function.rb', line 62 def called? @called end |
#define(&b) ⇒ void
This method returns an undefined value.
Set the function implementation
45 46 47 |
# File 'lib/llm/function.rb', line 45 def define(&b) @runner = b end |
#description(str) ⇒ void
This method returns an undefined value.
Set the function description
30 31 32 |
# File 'lib/llm/function.rb', line 30 def description(str) @description = str end |
#format(provider) ⇒ Hash
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/llm/function.rb', line 68 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.
37 38 39 |
# File 'lib/llm/function.rb', line 37 def params @params = yield(@schema) end |