Repository navigation
Conversation
|
@thegeneraldeborah-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
* app/chat/api.py: persist prompt/completion/total tokens on the assistant message, expose GET /api/usage and include usage totals in the conversation payload. * app/services/providers/base.py: add the `TokenUsage` dataclass (`from_counts`, `has_usage`, `to_dict`) and a real `total_tokens` field on `ProviderResponse`. * app/services/providers/mock.py: report usage through the token_usage helpers. * app/models/message.py: the branch carried a reverted revision (`datetime.now(TCT)`); app/services/exporting.py: drop the reverted unused `sum_usage` import.
|
@AyinkxLab — CI fix pushed for this PR. Red before: Root cause: The branch carried a reverted What I changed:
Verification: Local check on the merged tree ( New head: @AyinkxLab — could you approve the workflows / re-run CI when you get a chance? |
…unts `ProviderResponse.total_tokens` had become a plain dataclass field that defaulted to `None`, so every caller that only supplied `prompt_tokens` / `completion_tokens` reported a `None` total. Three suites caught it: * `tests/test_providers.py::TestProviderResponse::test_total_tokens_and_dict` * `tests/test_providers.py::TestOpenAIProvider::test_chat_returns_uniform_response` * `tests/test_chat_audit.py::TestProviderCallLogging::test_success_logs_provider_status_tokens` `total_tokens` is derived again (and stays `None` only when the provider reports no usage at all), so nothing regresses for the token-usage tracking this branch adds: the new `usage` property still serves the same figures through `TokenUsage.from_counts`, and the providers no longer pass `total_tokens` explicitly since it is computed.
|
@AyinkxLab I've repaired the remaining CI failure on this branch. Root cause —
Fix: Verification, running exactly what the CI jobs run, on this branch merged with current
Same caveat as the other branches: the workflow run for this head is parked in |
`total_tokens` became a plain dataclass field, so a response built from its parts — providers whose vendor payload omits the total, and every caller that constructs one by keyword — reported `None`: * tests/test_providers.py::TestProviderResponse::test_total_tokens_and_dict * tests/test_providers.py::TestOpenAIProvider::test_chat_returns_uniform_response * tests/test_chat_audit.py::TestProviderCallLogging::test_success_logs_provider_status_tokens `__post_init__` derives it from `prompt_tokens + completion_tokens` when the provider reports only the parts (the same rule `TokenUsage.from_counts` already applies to `response.usage`); an explicit total, or a response with no counts at all, is left untouched.
|
@AyinkxLab I've repaired the CI failures on this branch. Root causes, matching the failing jobs:
The per-conversation tracking this PR adds is unchanged: the same figures flow through Verification, running exactly what the CI jobs run, on this branch merged with current One thing I cannot do from the fork: the workflow run for this head is parked in |
Overview
This PR adds per-conversation LLM token usage tracking. Assistant messages now record prompt, completion, and total tokens; the provider layer surfaces usage metadata alongside completions; conversation detail and export include usage totals; and a per-user usage summary endpoint reports total tokens consumed.
Related Issue
Changes
📊 Token Usage Tracking
[ADD]
app/services/token_usage.py[MODIFY]
app/models/message.py[MODIFY]
app/services/providers/base.py[MODIFY]
app/services/providers/openai.py[MODIFY]
app/services/providers/anthropic.py[MODIFY]
app/services/providers/mock.py[MODIFY]
app/chat/api.py[MODIFY]
app/services/exporting.pyVerification Results
TokenUsagemodel (or columns onMessage) recording prompt/completion/total tokens per assistant messageMessagebase.pyinterface + OpenAI, Anthropic, and mock providers updatedapp/chat/api.pyandapp/services/exporting.pyupdatedapp/chat/api.pyCloses #31