whoosh 1.9.1 → 1.10.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/lib/whoosh/ai/llm.rb +10 -9
- data/lib/whoosh/streaming/llm_stream.rb +17 -1
- data/lib/whoosh/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c8ecbe08e5ecf50f7f1233da3767074a79d9e4164a719e9397be1ac9637efb3
|
|
4
|
+
data.tar.gz: 622f3f889c550ecdff4cfab4f38120f2ce3f14b7f2021be99dae9790c3cfc5f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70add9595209f2ff3a1c5c4a52e25a4428149694f4df9debc7cc58dace2d15b77d46dcf1591cb9cd78e7d02654f0402326c58c9e060f1c94897e0011fc2cfab2
|
|
7
|
+
data.tar.gz: 83fb93d35d3b1d446bc99d1f8ee0a21b16f062af81da4f4e737b98cd85acced622fe332ccefb785c5f114fa78131131bdea9f008e109c49291c793c117cea843
|
data/lib/whoosh/ai/llm.rb
CHANGED
|
@@ -90,18 +90,19 @@ module Whoosh
|
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
# Stream LLM response — yields
|
|
93
|
+
# Stream an LLM response — yields each chunk as ruby_llm produces it.
|
|
94
|
+
# The block receives a RubyLLM::Chunk (a Message subclass with #content).
|
|
95
|
+
# Returns the final response message after the stream completes.
|
|
94
96
|
def stream(message, model: nil, system: nil, &block)
|
|
95
97
|
ensure_ruby_llm!
|
|
98
|
+
unless @ruby_llm
|
|
99
|
+
raise Errors::DependencyError, "No LLM provider available. Add 'ruby_llm' to your Gemfile."
|
|
100
|
+
end
|
|
96
101
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
# For now, fall back to non-streaming
|
|
102
|
-
result = chat(message, model: model, system: system, cache: false)
|
|
103
|
-
yield result if block_given?
|
|
104
|
-
result
|
|
102
|
+
chat = RubyLLM.chat(model: model || @model || DEFAULT_MODEL)
|
|
103
|
+
chat.with_instructions(system) if system
|
|
104
|
+
chat.ask(message) do |chunk|
|
|
105
|
+
block.call(chunk) if block
|
|
105
106
|
end
|
|
106
107
|
end
|
|
107
108
|
|
|
@@ -17,7 +17,8 @@ module Whoosh
|
|
|
17
17
|
|
|
18
18
|
def <<(chunk)
|
|
19
19
|
return if @closed
|
|
20
|
-
text = chunk
|
|
20
|
+
text = extract_text(chunk)
|
|
21
|
+
return self if text.nil? || text.empty?
|
|
21
22
|
payload = { choices: [{ delta: { content: text } }] }
|
|
22
23
|
write("data: #{JSON.generate(payload)}\n\n")
|
|
23
24
|
self
|
|
@@ -40,6 +41,21 @@ module Whoosh
|
|
|
40
41
|
|
|
41
42
|
private
|
|
42
43
|
|
|
44
|
+
# ruby_llm chunks expose #content (Message subclass). Older code paths
|
|
45
|
+
# and plain-string yields are also supported.
|
|
46
|
+
def extract_text(chunk)
|
|
47
|
+
return chunk if chunk.is_a?(String)
|
|
48
|
+
if chunk.respond_to?(:content)
|
|
49
|
+
c = chunk.content
|
|
50
|
+
return "" if c.nil?
|
|
51
|
+
return c if c.is_a?(String)
|
|
52
|
+
return c.text if c.respond_to?(:text)
|
|
53
|
+
return c.to_s
|
|
54
|
+
end
|
|
55
|
+
return chunk.text if chunk.respond_to?(:text)
|
|
56
|
+
chunk.to_s
|
|
57
|
+
end
|
|
58
|
+
|
|
43
59
|
def write(data)
|
|
44
60
|
@io.write(data)
|
|
45
61
|
@io.flush if @io.respond_to?(:flush)
|
data/lib/whoosh/version.rb
CHANGED