fix callers of count_tokens#554
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the token counting logic in both api/simple_chat.py and api/websocket_wiki.py to pass the raw request.provider string as the embedder_type argument to count_tokens. The reviewer suggests normalizing the provider string to lowercase using .lower() to ensure robust, case-insensitive matching and prevent potential issues with mixed-case provider names.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| last_message = request.messages[-1] | ||
| if hasattr(last_message, 'content') and last_message.content: | ||
| tokens = count_tokens(last_message.content, request.provider == "ollama") | ||
| tokens = count_tokens(last_message.content, embedder_type=request.provider) |
There was a problem hiding this comment.
Since request.provider is defined as a general str without strict casing validation in ChatCompletionRequest, a user could potentially pass provider names with mixed or upper casing (e.g., "Ollama", "Google"). Since count_tokens performs exact string matching (e.g., embedder_type == 'ollama'), passing the raw provider string directly might bypass the correct tokenizer selection. Normalizing the provider string to lowercase using .lower() ensures robust and case-insensitive matching.
| tokens = count_tokens(last_message.content, embedder_type=request.provider) | |
| tokens = count_tokens(last_message.content, embedder_type=request.provider.lower()) |
| last_message = request.messages[-1] | ||
| if hasattr(last_message, 'content') and last_message.content: | ||
| tokens = count_tokens(last_message.content, request.provider == "ollama") | ||
| tokens = count_tokens(last_message.content, embedder_type=request.provider) |
There was a problem hiding this comment.
Since request.provider is defined as a general str without strict casing validation in ChatCompletionRequest, a user could potentially pass provider names with mixed or upper casing (e.g., "Ollama", "Google"). Since count_tokens performs exact string matching (e.g., embedder_type == 'ollama'), passing the raw provider string directly might bypass the correct tokenizer selection. Normalizing the provider string to lowercase using .lower() ensures robust and case-insensitive matching.
| tokens = count_tokens(last_message.content, embedder_type=request.provider) | |
| tokens = count_tokens(last_message.content, embedder_type=request.provider.lower()) |
99ca4fc to
92a3c4e
Compare
92a3c4e to
cb9b34a
Compare
Summary
Fix callers in
simple_chat.pyandwebsocket_wiki.pycalling signature. Since the input signatures are as followspassing a bool value to the
embedder_typeis missleading. Change to pass provider string directly.