mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-22 17:42:18 -05:00
[PR #16910] [CLOSED] feat: Implement prompt usage counter and stats API #127935
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/16910
Author: @BoDy-PrISon
Created: 8/25/2025
Status: ❌ Closed
Base:
main← Head:feature/prompt-counter📝 Commits (2)
bb7af8dfeat: Implement prompt usage counter and stats APIdea5120Неуверенные изменения📊 Changes
12 files changed (+444 additions, -14 deletions)
View changed files
➕
.webui_secret_key(+1 -0)📝
backend/open_webui/main.py(+7 -0)➕
backend/open_webui/migrations/versions/14f6763df9ca_merge_heads.py(+27 -0)➕
backend/open_webui/migrations/versions/e1b2c3d4_add_prompt_usage_table.py(+37 -0)➕
backend/open_webui/models/prompt_usage.py(+37 -0)📝
backend/open_webui/routers/chats.py(+5 -1)📝
backend/open_webui/routers/ollama.py(+7 -0)📝
backend/open_webui/routers/openai.py(+6 -1)📝
backend/open_webui/routers/prompts.py(+130 -0)➕
backend/open_webui/utils/prompt_counter.py(+121 -0)📝
src/lib/apis/prompts/index.ts(+29 -0)📝
src/lib/components/chat/Suggestions.svelte(+37 -12)📄 Description
Changelog Entry
Description
This pull request introduces a comprehensive feature to track the usage of predefined "suggested prompts". It includes a backend counting mechanism and a new suite of API endpoints to retrieve detailed statistics. This fulfills and exceeds the requirements of the provided test task.
Added
app.stateto track prompt usage by total count, prompt type, user, and date.backend/open_webui/utils/prompt_counter.pycontaining all the logic for prompt detection and counting.backend/open_webui/routers/prompts.pywith a suite of new API endpoints:GET /api/v1/prompts/usage/stats: Returns overall usage statistics.GET /api/v1/prompts/usage/prompt/{prompt_command}: Returns statistics for a specific prompt type.GET /api/v1/prompts/usage/user/{user_id}: Returns statistics for a specific user, protected by an authorization check (admins or the user themselves).Changed
/routers/openai.pyand/routers/ollama.pyto call the new prompt counter on every user message.main.pyto initialize the counter and include the new prompts API router.Removed
Fixed
Additional Information
PromptUsageLogmodel and logging each event.TASK_MODELfor more intelligent, semantic classification of user intent.Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.