llm.rb 6.1.0 → 8.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +137 -1
- data/README.md +39 -20
- data/lib/llm/active_record/acts_as_agent.rb +2 -6
- data/lib/llm/active_record/acts_as_llm.rb +4 -82
- data/lib/llm/active_record.rb +80 -2
- data/lib/llm/agent.rb +41 -10
- data/lib/llm/compactor.rb +1 -2
- data/lib/llm/context.rb +1 -2
- data/lib/llm/error.rb +4 -0
- data/lib/llm/function/array.rb +7 -3
- data/lib/llm/function/fiber_group.rb +9 -3
- data/lib/llm/function/fork/job.rb +67 -0
- data/lib/llm/function/fork/task.rb +76 -0
- data/lib/llm/function/fork.rb +8 -0
- data/lib/llm/function/fork_group.rb +36 -0
- data/lib/llm/function/ractor/task.rb +13 -3
- data/lib/llm/function/task.rb +10 -2
- data/lib/llm/function.rb +24 -11
- data/lib/llm/loop_guard.rb +1 -10
- data/lib/llm/mcp/command.rb +1 -1
- data/lib/llm/mcp/transport/http.rb +2 -2
- data/lib/llm/mcp.rb +7 -4
- data/lib/llm/object/kernel.rb +8 -2
- data/lib/llm/object.rb +67 -21
- data/lib/llm/{mcp/pipe.rb → pipe.rb} +9 -8
- data/lib/llm/provider/transport/http.rb +2 -2
- data/lib/llm/stream/queue.rb +1 -1
- data/lib/llm/version.rb +1 -1
- data/lib/llm.rb +19 -1
- data/llm.gemspec +2 -1
- metadata +21 -3
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module LLM
|
|
4
4
|
##
|
|
5
|
-
# The {LLM::
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# the stdin, stdout, and stderr streams of an MCP process through
|
|
9
|
-
# one small interface.
|
|
5
|
+
# The {LLM::Pipe LLM::Pipe} class wraps a pair of IO objects created by
|
|
6
|
+
# {IO.pipe}. It is used by llm.rb internals to manage process and stream
|
|
7
|
+
# communication through one small interface.
|
|
10
8
|
class Pipe
|
|
11
9
|
##
|
|
12
10
|
# @return [IO]
|
|
@@ -20,9 +18,12 @@ class LLM::MCP
|
|
|
20
18
|
|
|
21
19
|
##
|
|
22
20
|
# Returns a new pipe.
|
|
23
|
-
# @
|
|
24
|
-
|
|
21
|
+
# @param [Boolean] binmode
|
|
22
|
+
# Whether both ends of the pipe should be switched to binary mode
|
|
23
|
+
# @return [LLM::Pipe]
|
|
24
|
+
def initialize(binmode: false)
|
|
25
25
|
@r, @w = IO.pipe
|
|
26
|
+
[@r, @w].each(&:binmode) if binmode
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
##
|
|
@@ -53,7 +53,7 @@ class LLM::Provider
|
|
|
53
53
|
# @return [Object]
|
|
54
54
|
def request_owner
|
|
55
55
|
return Fiber.current unless defined?(::Async)
|
|
56
|
-
Async::Task.current
|
|
56
|
+
Async::Task.current? ? Async::Task.current : Fiber.current
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
##
|
|
@@ -71,7 +71,7 @@ class LLM::Provider
|
|
|
71
71
|
##
|
|
72
72
|
# @return [Boolean]
|
|
73
73
|
def persistent?
|
|
74
|
-
|
|
74
|
+
!@persistent_client.nil?
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
##
|
data/lib/llm/stream/queue.rb
CHANGED
|
@@ -46,7 +46,7 @@ class LLM::Stream
|
|
|
46
46
|
# to wait on:
|
|
47
47
|
# - `:thread`: Use threads
|
|
48
48
|
# - `:task`: Use async tasks (requires async gem)
|
|
49
|
-
# - `:fiber`: Use
|
|
49
|
+
# - `:fiber`: Use scheduler-backed fibers (requires Fiber.scheduler)
|
|
50
50
|
# - `:ractor`: Use Ruby ractors (class-based tools only; MCP tools are not supported)
|
|
51
51
|
# - `[:thread, :ractor]`: Wait for any queued thread or ractor work, in the
|
|
52
52
|
# given order. This is useful when different tools were spawned with
|
data/lib/llm/version.rb
CHANGED
data/lib/llm.rb
CHANGED
|
@@ -20,6 +20,7 @@ module LLM
|
|
|
20
20
|
require_relative "llm/mime"
|
|
21
21
|
require_relative "llm/multipart"
|
|
22
22
|
require_relative "llm/file"
|
|
23
|
+
require_relative "llm/pipe"
|
|
23
24
|
require_relative "llm/stream"
|
|
24
25
|
require_relative "llm/provider"
|
|
25
26
|
require_relative "llm/context"
|
|
@@ -48,7 +49,24 @@ module LLM
|
|
|
48
49
|
|
|
49
50
|
##
|
|
50
51
|
# @api private
|
|
51
|
-
def self.clients
|
|
52
|
+
def self.clients
|
|
53
|
+
@clients
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
##
|
|
57
|
+
# Requires an optional runtime dependency
|
|
58
|
+
# @raise [LLM::DependencyError]
|
|
59
|
+
# When the dependency cannot be loaded
|
|
60
|
+
def self.require(name)
|
|
61
|
+
super
|
|
62
|
+
rescue ::LoadError
|
|
63
|
+
names = {"xchan" => "xchan.rb", "net/http/persistent" => "net-http-persistent"}
|
|
64
|
+
name = names[name] || name
|
|
65
|
+
raise LLM::LoadError,
|
|
66
|
+
"#{name} is an optional runtime dependency but it does not appear to be installed. " \
|
|
67
|
+
"Consider 'gem install #{name}', adding '#{name}' to your Gemfile or " \
|
|
68
|
+
"opting out of the functionality provided by '#{name}'"
|
|
69
|
+
end
|
|
52
70
|
|
|
53
71
|
##
|
|
54
72
|
# @param [Symbol, LLM::Provider] llm
|
data/llm.gemspec
CHANGED
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
DESCRIPTION
|
|
26
26
|
|
|
27
27
|
spec.license = "0BSD"
|
|
28
|
-
spec.required_ruby_version = ">= 3.
|
|
28
|
+
spec.required_ruby_version = ">= 3.3.0"
|
|
29
29
|
|
|
30
30
|
spec.homepage = "https://github.com/llmrb/llm.rb"
|
|
31
31
|
spec.metadata["homepage_uri"] = "https://github.com/llmrb/llm.rb"
|
|
@@ -57,5 +57,6 @@ Gem::Specification.new do |spec|
|
|
|
57
57
|
spec.add_development_dependency "activerecord", "~> 8.0"
|
|
58
58
|
spec.add_development_dependency "sequel", "~> 5.0"
|
|
59
59
|
spec.add_development_dependency "sqlite3", "~> 2.0"
|
|
60
|
+
spec.add_development_dependency "xchan.rb", "~> 0.20"
|
|
60
61
|
spec.add_development_dependency "pg", "~> 1.5"
|
|
61
62
|
end
|
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:
|
|
4
|
+
version: 8.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Antar Azri
|
|
@@ -236,6 +236,20 @@ dependencies:
|
|
|
236
236
|
- - "~>"
|
|
237
237
|
- !ruby/object:Gem::Version
|
|
238
238
|
version: '2.0'
|
|
239
|
+
- !ruby/object:Gem::Dependency
|
|
240
|
+
name: xchan.rb
|
|
241
|
+
requirement: !ruby/object:Gem::Requirement
|
|
242
|
+
requirements:
|
|
243
|
+
- - "~>"
|
|
244
|
+
- !ruby/object:Gem::Version
|
|
245
|
+
version: '0.20'
|
|
246
|
+
type: :development
|
|
247
|
+
prerelease: false
|
|
248
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
249
|
+
requirements:
|
|
250
|
+
- - "~>"
|
|
251
|
+
- !ruby/object:Gem::Version
|
|
252
|
+
version: '0.20'
|
|
239
253
|
- !ruby/object:Gem::Dependency
|
|
240
254
|
name: pg
|
|
241
255
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -301,6 +315,10 @@ files:
|
|
|
301
315
|
- lib/llm/function.rb
|
|
302
316
|
- lib/llm/function/array.rb
|
|
303
317
|
- lib/llm/function/fiber_group.rb
|
|
318
|
+
- lib/llm/function/fork.rb
|
|
319
|
+
- lib/llm/function/fork/job.rb
|
|
320
|
+
- lib/llm/function/fork/task.rb
|
|
321
|
+
- lib/llm/function/fork_group.rb
|
|
304
322
|
- lib/llm/function/ractor.rb
|
|
305
323
|
- lib/llm/function/ractor/job.rb
|
|
306
324
|
- lib/llm/function/ractor/mailbox.rb
|
|
@@ -317,7 +335,6 @@ files:
|
|
|
317
335
|
- lib/llm/mcp/command.rb
|
|
318
336
|
- lib/llm/mcp/error.rb
|
|
319
337
|
- lib/llm/mcp/mailbox.rb
|
|
320
|
-
- lib/llm/mcp/pipe.rb
|
|
321
338
|
- lib/llm/mcp/router.rb
|
|
322
339
|
- lib/llm/mcp/rpc.rb
|
|
323
340
|
- lib/llm/mcp/transport/http.rb
|
|
@@ -331,6 +348,7 @@ files:
|
|
|
331
348
|
- lib/llm/object.rb
|
|
332
349
|
- lib/llm/object/builder.rb
|
|
333
350
|
- lib/llm/object/kernel.rb
|
|
351
|
+
- lib/llm/pipe.rb
|
|
334
352
|
- lib/llm/prompt.rb
|
|
335
353
|
- lib/llm/provider.rb
|
|
336
354
|
- lib/llm/provider/transport/http.rb
|
|
@@ -464,7 +482,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
464
482
|
requirements:
|
|
465
483
|
- - ">="
|
|
466
484
|
- !ruby/object:Gem::Version
|
|
467
|
-
version: 3.
|
|
485
|
+
version: 3.3.0
|
|
468
486
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
469
487
|
requirements:
|
|
470
488
|
- - ">="
|