-
-
Notifications
You must be signed in to change notification settings - Fork 2k
fix callers of count_tokens
#554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -43,7 +43,7 @@ async def handle_websocket_chat(websocket: WebSocket): | |||||
| if request.messages and len(request.messages) > 0: | ||||||
| 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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Suggested change
|
||||||
| logger.info(f"Request size: {tokens} tokens") | ||||||
| if tokens > MAX_INPUT_TOKENS: | ||||||
| logger.warning(f"Request exceeds recommended token limit ({tokens} > {MAX_INPUT_TOKENS})") | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
request.provideris defined as a generalstrwithout strict casing validation inChatCompletionRequest, a user could potentially pass provider names with mixed or upper casing (e.g.,"Ollama","Google"). Sincecount_tokensperforms 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.