Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 8c8fd96

Browse files
authored
FIX: Don't check for #blank? when manipulating chunks (#1428)
1 parent 26217e5 commit 8c8fd96

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/completions/json_streaming_tracker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def <<(raw_json)
7474
private
7575

7676
def try_escape_and_parse(raw_json)
77-
if raw_json.blank? || !raw_json.is_a?(String)
77+
if !raw_json.is_a?(String)
7878
@broken = true
7979
return
8080
end

spec/lib/completions/endpoints/gemini_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,9 @@ def tool_response
544544
545545
data: {"candidates": [{"content": {"parts": [{"text": "Hello!"}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}
546546
547-
data: {"candidates": [{"content": {"parts": [{"text": "\\n there"}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}
547+
data: {"candidates": [{"content": {"parts": [{"text": "\\n "}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}
548+
549+
data: {"candidates": [{"content": {"parts": [{"text": "there"}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}
548550
549551
data: {"candidates": [{"content": {"parts": [{"text": "\\","}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}
550552

spec/lib/completions/structured_output_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
["Hello! I am a chunk", "There"],
113113
)
114114
end
115+
116+
it "handles empty newline chunks" do
117+
chunks = [+"{\"", +"message", +"\":\"", +"Hello!", +"\n", +"\"", +"}"]
118+
119+
chunks.each { |c| structured_output << c }
120+
121+
expect(structured_output.read_buffered_property(:message)).to eq("Hello!\n")
122+
end
115123
end
116124

117125
describe "dealing with non-JSON responses" do

0 commit comments

Comments
 (0)