Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/completions/json_streaming_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def <<(raw_json)
private

def try_escape_and_parse(raw_json)
if raw_json.blank? || !raw_json.is_a?(String)
if !raw_json.is_a?(String)
@broken = true
return
end
Expand Down
4 changes: 3 additions & 1 deletion spec/lib/completions/endpoints/gemini_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,9 @@ def tool_response

data: {"candidates": [{"content": {"parts": [{"text": "Hello!"}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}

data: {"candidates": [{"content": {"parts": [{"text": "\\n there"}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}
data: {"candidates": [{"content": {"parts": [{"text": "\\n "}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}

data: {"candidates": [{"content": {"parts": [{"text": "there"}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}

data: {"candidates": [{"content": {"parts": [{"text": "\\","}],"role": "model"},"finishReason": "STOP"}],"usageMetadata": {"promptTokenCount": 399,"candidatesTokenCount": 191,"totalTokenCount": 590},"modelVersion": "gemini-1.5-pro-002"}

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/completions/structured_output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@
["Hello! I am a chunk", "There"],
)
end

it "handles empty newline chunks" do
chunks = [+"{\"", +"message", +"\":\"", +"Hello!", +"\n", +"\"", +"}"]

chunks.each { |c| structured_output << c }

expect(structured_output.read_buffered_property(:message)).to eq("Hello!\n")
end
end

describe "dealing with non-JSON responses" do
Expand Down
Loading