llm.rb 9.0.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,12 +30,7 @@ module LLM::Sequel
30
30
  # Resolves a single configured option against a model instance.
31
31
  # @return [Object]
32
32
  def self.resolve_option(obj, option)
33
- case option
34
- when Proc then obj.instance_exec(&option)
35
- when Symbol then obj.send(option)
36
- when Hash then option.dup
37
- else option
38
- end
33
+ LLM::Utils.resolve_option(obj, option)
39
34
  end
40
35
 
41
36
  ##
data/lib/llm/stream.rb CHANGED
@@ -9,8 +9,7 @@ module LLM
9
9
  # subclass that overrides the callbacks it needs. For basic streaming,
10
10
  # llm.rb also accepts any object that implements `#<<`. {#queue} provides
11
11
  # a small helper for collecting asynchronous tool work started from a
12
- # callback, and {#tool_not_found} returns an in-band tool error when a
13
- # streamed tool cannot be resolved.
12
+ # callback.
14
13
  #
15
14
  # @note The `on_*` callbacks run inline with the streaming parser. They
16
15
  # therefore block streaming progress and should generally return as
@@ -150,48 +149,24 @@ module LLM
150
149
 
151
150
  # @endgroup
152
151
 
153
- # @group Error handlers
154
-
155
- ##
156
- # Returns a function return describing a streamed tool that could not
157
- # be resolved.
158
- # @note This is mainly useful as a fallback from {#on_tool_call}. It
159
- # should be uncommon in normal use, since streamed tool callbacks only
160
- # run for tools already defined in the context.
161
- # @param [LLM::Function] tool
162
- # @return [LLM::Function::Return]
163
- def tool_not_found(tool)
164
- LLM::Function::Return.new(tool.id, tool.name, {
165
- error: true, type: LLM::NoSuchToolError.name, message: "tool not found"
166
- })
167
- end
168
-
169
- ##
170
- # Returns the tool definitions available for the current streamed request.
171
- # This prefers request-local tools attached to the stream and falls back
172
- # to the current context defaults when present.
173
- # @return [Array<LLM::Function, LLM::Tool>]
174
- def tools
175
- extra[:tools] || ctx&.params&.dig(:tools) || []
176
- end
152
+ # @group Finders
177
153
 
178
154
  ##
179
155
  # Resolves a streamed tool call against the current request tools first,
180
156
  # then falls back to the global function registry.
181
157
  # @param [String] name
182
158
  # @return [LLM::Function, nil]
183
- def find_tool(name)
184
- tool = tools.find do |candidate|
185
- candidate_name =
186
- if candidate.respond_to?(:function)
187
- candidate.function.name
188
- else
189
- candidate.name
190
- end
191
- candidate_name.to_s == name.to_s
159
+ def __find__(name)
160
+ tools = extra[:tools] || ctx&.params&.dig(:tools) || []
161
+ tool = tools.find do
162
+ candidate = _1.respond_to?(:function) ? _1.function.name : _1.name
163
+ candidate.to_s == name.to_s
192
164
  end
193
- tool&.then { _1.respond_to?(:function) ? _1.function : _1 } ||
165
+ if tool
166
+ tool.respond_to?(:function) ? tool.function : tool
167
+ else
194
168
  LLM::Function.find_by_name(name)
169
+ end
195
170
  end
196
171
 
197
172
  # @endgroup
@@ -62,14 +62,7 @@ class LLM::Tool
62
62
  extend self
63
63
 
64
64
  def resolve(schema, type)
65
- if LLM::Schema::Leaf === type
66
- type
67
- elsif Class === type && type.respond_to?(:object)
68
- type.object
69
- else
70
- target = type.name.split("::").last.downcase
71
- schema.public_send(target)
72
- end
65
+ LLM::Schema::Utils.resolve(schema, type)
73
66
  end
74
67
 
75
68
  def setup(leaf, description, options)
data/lib/llm/utils.rb ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LLM
4
+ ##
5
+ # Shared utility methods used across the runtime.
6
+ module Utils
7
+ extend self
8
+
9
+ ##
10
+ # Resolves a configured option against an object instance.
11
+ #
12
+ # Proc values are evaluated with `instance_exec`, symbol values are
13
+ # optionally sent to the object as method calls, hashes are duplicated,
14
+ # and all other values are returned as-is.
15
+ #
16
+ # @param [Object] obj
17
+ # @param [Object] option
18
+ # @param [Boolean] resolve_symbol
19
+ # @return [Object]
20
+ def resolve_option(obj, option, resolve_symbol: true)
21
+ case option
22
+ when Proc then obj.instance_exec(&option)
23
+ when Symbol then resolve_symbol ? obj.send(option) : option
24
+ when Hash then option.dup
25
+ else option
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/llm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LLM
4
- VERSION = "9.0.0"
4
+ VERSION = "10.0.0"
5
5
  end
data/lib/llm.rb CHANGED
@@ -12,6 +12,7 @@ module LLM
12
12
  require_relative "llm/prompt"
13
13
  require_relative "llm/schema"
14
14
  require_relative "llm/object"
15
+ require_relative "llm/utils"
15
16
  require_relative "llm/model"
16
17
  require_relative "llm/version"
17
18
  require_relative "llm/message"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.0
4
+ version: 10.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antar Azri
@@ -287,7 +287,6 @@ files:
287
287
  - lib/llm/active_record/acts_as_agent.rb
288
288
  - lib/llm/active_record/acts_as_llm.rb
289
289
  - lib/llm/agent.rb
290
- - lib/llm/bot.rb
291
290
  - lib/llm/buffer.rb
292
291
  - lib/llm/compactor.rb
293
292
  - lib/llm/context.rb
@@ -305,6 +304,7 @@ files:
305
304
  - lib/llm/function.rb
306
305
  - lib/llm/function/array.rb
307
306
  - lib/llm/function/call_group.rb
307
+ - lib/llm/function/call_task.rb
308
308
  - lib/llm/function/fiber_group.rb
309
309
  - lib/llm/function/fork.rb
310
310
  - lib/llm/function/fork/job.rb
@@ -467,6 +467,7 @@ files:
467
467
  - lib/llm/transport/response/http.rb
468
468
  - lib/llm/transport/stream_decoder.rb
469
469
  - lib/llm/usage.rb
470
+ - lib/llm/utils.rb
470
471
  - lib/llm/version.rb
471
472
  - lib/sequel/plugins/agent.rb
472
473
  - lib/sequel/plugins/llm.rb
@@ -493,7 +494,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
493
494
  - !ruby/object:Gem::Version
494
495
  version: '0'
495
496
  requirements: []
496
- rubygems_version: 4.0.3
497
+ rubygems_version: 4.0.6
497
498
  specification_version: 4
498
499
  summary: Ruby's most capable AI runtime
499
500
  test_files: []
data/lib/llm/bot.rb DELETED
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "context"