Skip to content

Commit 5160246

Browse files
committed
Add tests for consistent token counts in streaming vs non-streaming responses
- Implemented a new test in `chat_streaming_spec.rb` to verify that token counts for streaming responses are consistent with non-streaming responses for various models, excluding the DeepSeek provider due to known discrepancies. - Removed specific skips for the `claude-3-5-haiku-20241022` model in `chat_tools_spec.rb` to allow for more robust testing across different models. - Added VCR cassettes for streaming and non-streaming responses for multiple models including Anthropic Claude, Bedrock, Gemini, and OpenAI GPT-4.1 to facilitate consistent testing.
1 parent f6e2001 commit 5160246

File tree

36 files changed

+2317
-604
lines changed

36 files changed

+2317
-604
lines changed

lib/ruby_llm/stream_accumulator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def find_tool_call(tool_call_id)
8989
end
9090

9191
def count_tokens(chunk)
92-
@input_tokens += chunk.input_tokens if chunk.input_tokens
93-
@output_tokens += chunk.output_tokens if chunk.output_tokens
92+
@input_tokens = chunk.input_tokens if chunk.input_tokens
93+
@output_tokens = chunk.output_tokens if chunk.output_tokens
9494
end
9595
end
9696
end

spec/fixtures/vcr_cassettes/chat_basic_chat_functionality_anthropic_claude-3-5-haiku-20241022_can_handle_multi-turn_conversations.yml

Lines changed: 17 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/vcr_cassettes/chat_basic_chat_functionality_anthropic_claude-3-5-haiku-20241022_can_have_a_basic_conversation.yml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/vcr_cassettes/chat_basic_chat_functionality_anthropic_claude-3-5-haiku-20241022_replaces_previous_system_messages_when_replace_true.yml

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/vcr_cassettes/chat_basic_chat_functionality_anthropic_claude-3-5-haiku-20241022_successfully_uses_the_system_prompt.yml

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)