Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
Target branch: Please verify that the pull request targets the dev branch.
Description: Provide a concise description of the changes made in this pull request.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Have you written and run sufficient tests for validating the changes?
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Label: To cleary categorize this pull request, assign a relevant label to the pull request title, using one of the following:
BREAKING CHANGE: Significant changes that may affect compatibility
build: Changes that affect the build system or external dependencies
ci: Changes to our continuous integration processes or workflows
chore: Refactor, cleanup, or other non-functional code changes
docs: Documentation update or addition
feat: Introduces a new feature or enhancement to the codebase
fix: Bug fix or error correction
i18n: Internationalization or localization changes
perf: Performance improvement
refactor: Code restructuring for better maintainability, readability, or scalability
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
test: Adding missing tests or correcting existing tests
WIP: Work in progress, a temporary label for incomplete or ongoing work
Changelog Entry
Description
Adds a new usage capability for OpenAI models that toggles if stream_options: { include_usage: true } is passed into the chat completion request.
This is not default true, because this is a relatively new OpenAI addition, some providers/services will fail hard if it's passed.
Tested:
OpenAI
OpenAI compatible endpoints via LiteLLM
OpenRouter
Not working:
GroqCloud
Added
OpenAI Generation Stats - show token usage when supported by the provider.
Screenshots or Videos
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/2602
**Author:** [@cheahjs](https://github.com/cheahjs)
**Created:** 5/27/2024
**Status:** ✅ Merged
**Merged:** 5/27/2024
**Merged by:** [@tjbck](https://github.com/tjbck)
**Base:** `dev` ← **Head:** `feat/openai-usage-stats`
---
### 📝 Commits (1)
- [`99b1661`](https://github.com/open-webui/open-webui/commit/99b16616383e2a9ddc77c995c84cd2bb7bfeecb5) feat: add OpenAI generation stats
### 📊 Changes
**6 files changed** (+61 additions, -7 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/config.py` (+1 -0)
📝 `src/lib/apis/streaming/index.ts` (+15 -1)
📝 `src/lib/components/chat/Chat.svelte` (+16 -1)
📝 `src/lib/components/chat/Messages/ResponseMessage.svelte` (+11 -5)
📝 `src/routes/(app)/workspace/models/create/+page.svelte` (+14 -0)
📝 `src/routes/(app)/workspace/models/edit/+page.svelte` (+4 -0)
</details>
### 📄 Description
# Pull Request Checklist
### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request.
**Before submitting, make sure you've checked the following:**
- [x] **Target branch:** Please verify that the pull request targets the `dev` branch.
- [x] **Description:** Provide a concise description of the changes made in this pull request.
- [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources?
- [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] **Testing:** Have you written and run sufficient tests for validating the changes?
- [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [x] **Label:** To cleary categorize this pull request, assign a relevant label to the pull request title, using one of the following:
- **BREAKING CHANGE**: Significant changes that may affect compatibility
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to our continuous integration processes or workflows
- **chore**: Refactor, cleanup, or other non-functional code changes
- **docs**: Documentation update or addition
- **feat**: Introduces a new feature or enhancement to the codebase
- **fix**: Bug fix or error correction
- **i18n**: Internationalization or localization changes
- **perf**: Performance improvement
- **refactor**: Code restructuring for better maintainability, readability, or scalability
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
- **test**: Adding missing tests or correcting existing tests
- **WIP**: Work in progress, a temporary label for incomplete or ongoing work
# Changelog Entry
### Description
Adds a new `usage` capability for OpenAI models that toggles if `stream_options: { include_usage: true }` is passed into the chat completion request.
This is not default true, because this is a [relatively new OpenAI addition](https://community.openai.com/t/usage-stats-now-available-when-using-streaming-with-the-chat-completions-api-or-completions-api/738156), some providers/services will fail hard if it's passed.
Tested:
* OpenAI
* OpenAI compatible endpoints via LiteLLM
* OpenRouter
Not working:
* GroqCloud
### Added
- OpenAI Generation Stats - show token usage when supported by the provider.
### Screenshots or Videos
<img width="630" alt="image" src="https://github.com/open-webui/open-webui/assets/818368/1c17cb75-4c06-4c9c-9d8f-30a135e4626e">
<img width="1161" alt="image" src="https://github.com/open-webui/open-webui/assets/818368/e6bf9cb4-ba0d-4883-88ee-bbda2bde68e3">
<img width="1339" alt="image" src="https://github.com/open-webui/open-webui/assets/818368/6d92952f-322f-49fe-be3d-395e456094a3">
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/2602
Author: @cheahjs
Created: 5/27/2024
Status: ✅ Merged
Merged: 5/27/2024
Merged by: @tjbck
Base:
dev← Head:feat/openai-usage-stats📝 Commits (1)
99b1661feat: add OpenAI generation stats📊 Changes
6 files changed (+61 additions, -7 deletions)
View changed files
📝
backend/config.py(+1 -0)📝
src/lib/apis/streaming/index.ts(+15 -1)📝
src/lib/components/chat/Chat.svelte(+16 -1)📝
src/lib/components/chat/Messages/ResponseMessage.svelte(+11 -5)📝
src/routes/(app)/workspace/models/create/+page.svelte(+14 -0)📝
src/routes/(app)/workspace/models/edit/+page.svelte(+4 -0)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Adds a new
usagecapability for OpenAI models that toggles ifstream_options: { include_usage: true }is passed into the chat completion request.This is not default true, because this is a relatively new OpenAI addition, some providers/services will fail hard if it's passed.
Tested:
Not working:
Added
Screenshots or Videos
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.