Skip to content

Fix token metrics in streaming, and improve token tracking#14

Merged
waybarrios merged 1 commit intowaybarrios:mainfrom
dearliory:metrics
Jan 21, 2026
Merged

Fix token metrics in streaming, and improve token tracking#14
waybarrios merged 1 commit intowaybarrios:mainfrom
dearliory:metrics

Conversation

@dearliory
Copy link
Copy Markdown
Contributor

Come across a few issues while testing token metrics in streaming responses, added fixes and improvements:

  • Add optional usage field to ChatCompletionChunk for token metrics
  • Refactor SimpleEngine.stream_generate() to properly track prompt/completion tokens
  • Fix JSON serialization in streaming responses by handling None values
  • Add get_usage() helper for consistent token metric extraction
  • Include prompt_tokens in all non-streaming responses
  • Improve logging to show breakdown of prompt vs completion tokens

Come across a few issues while testing token metrics in streaming responses, added fixes and improvements:
- Enable CORS for all origins using FastAPI middleware
- Add optional usage field to ChatCompletionChunk for token metrics
- Refactor SimpleEngine.stream_generate() to properly track prompt/completion tokens
- Fix JSON serialization in streaming responses by handling None values
- Add get_usage() helper for consistent token metric extraction
- Include prompt_tokens in all non-streaming responses
- Improve logging to show breakdown of prompt vs completion tokens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants