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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 035c0a8c4cfc32ee16cba0eba7e84e23ec1c510f41bd541a8409fa59dc5dbbd2
4
- data.tar.gz: aca768fe55956b76f30b9296fe9ee156b3547ce2089a49a5edcf18ab7ce33d07
3
+ metadata.gz: 0c8ecbe08e5ecf50f7f1233da3767074a79d9e4164a719e9397be1ac9637efb3
4
+ data.tar.gz: 622f3f889c550ecdff4cfab4f38120f2ce3f14b7f2021be99dae9790c3cfc5f7
5
5
  SHA512:
6
- metadata.gz: f3f877e2e128bd4b16ffece2ebf7a41b87678185906688cac6d514e70c28d0bb4c0bcebd1e466368a2fc591af83f8e89b6b15d5c6b59d493a8e5a2bc78c3da76
7
- data.tar.gz: aca365000fb9776754d29038d60061dcf92f71ade132e0ea602f80f0defe47a2fe83d5c3ef435e6e241b9bbd2cbdcb9fd1f4c34d38f99f160befd1b0f322930c
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 chunks
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
- messages = [{ role: "user", content: message }]
98
- # Delegate to ruby_llm's streaming interface
99
- if @ruby_llm
100
- # ruby_llm streaming would go here
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.respond_to?(:text) ? chunk.text : chunk.to_s
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whoosh
4
- VERSION = "1.9.1"
4
+ VERSION = "1.10.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whoosh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Dwi Cahyo