[PR #15103] Add conversation context usage indicator #40898

Open
opened 2026-04-23 01:41:07 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15103
Author: @Reevoy24
Created: 3/27/2026
Status: 🔄 Open

Base: mainHead: codex/SessionTokenCounter


📝 Commits (5)

  • 7ea5dcc Add conversation context usage indicator
  • d0cb313 Merge remote-tracking branch 'origin/main' into codex/SessionTokenCounter
  • 792d18e Merge remote-tracking branch 'upstream/main' into codex/SessionTokenCounter
  • a0f02d5 Merge remote-tracking branch 'upstream/main' into codex/SessionTokenCounter
  • 120ed47 Refine context usage indicator behavior

📊 Changes

12 files changed (+703 additions, -8 deletions)

View changed files

📝 app/store/database.go (+40 -6)
📝 app/store/database_test.go (+93 -0)
📝 app/store/store.go (+6 -0)
📝 app/store/store_test.go (+9 -1)
📝 app/ui/app/codegen/gotypes.gen.ts (+8 -0)
📝 app/ui/app/src/components/Chat.tsx (+2 -0)
📝 app/ui/app/src/components/ChatForm.tsx (+93 -0)
📝 app/ui/app/src/hooks/useChats.ts (+38 -0)
app/ui/app/src/utils/contextUsage.test.ts (+94 -0)
app/ui/app/src/utils/contextUsage.ts (+274 -0)
📝 app/ui/responses/types.go (+2 -0)
📝 app/ui/ui.go (+44 -1)

📄 Description

Summary

This change adds a conversation context usage indicator to the Ollama desktop chat UI.

It persists prompt_eval_count and eval_count from completed chat responses, exposes those values to the frontend, and displays them as a compact circular indicator next to the model picker.

The hover card shows:

  • current context usage
  • prompt/reply token breakdown from the latest completed turn
  • status messaging for normal, near-limit, and over-limit states
  • a warning when older messages may already be dropped from the prompt

The implementation also keeps the indicator accessible by showing the hover card on keyboard focus.

What changed

  • Added prompt/eval token counters to stored chat messages
  • Added a database migration for the new message fields
  • Forwarded token metrics through chat completion events
  • Updated frontend chat state to keep the latest metrics in sync
  • Replaced the larger context bar with a compact circular indicator and custom hover panel

Testing

  • go test ./app/store
  • npm run build

Screenshots

You can tell at a glance whether the context window is getting full or has already been exceeded by the ring color, without needing to hover over it.
Screenshot 2026-03-27 222814

Screenshot 2026-03-27 213303 Screenshot 2026-03-27 215845 Screenshot 2026-03-27 213256

🔄 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/ollama/ollama/pull/15103 **Author:** [@Reevoy24](https://github.com/Reevoy24) **Created:** 3/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/SessionTokenCounter` --- ### 📝 Commits (5) - [`7ea5dcc`](https://github.com/ollama/ollama/commit/7ea5dcc4d292646616b6f1699cb75603394b76d4) Add conversation context usage indicator - [`d0cb313`](https://github.com/ollama/ollama/commit/d0cb31396311e66184f5594e0d18e76626347eb6) Merge remote-tracking branch 'origin/main' into codex/SessionTokenCounter - [`792d18e`](https://github.com/ollama/ollama/commit/792d18e2098ec3fa6894d0f61fd9c32d78a0dd32) Merge remote-tracking branch 'upstream/main' into codex/SessionTokenCounter - [`a0f02d5`](https://github.com/ollama/ollama/commit/a0f02d5cb933bee73c2560ef54c7621d73eb4b11) Merge remote-tracking branch 'upstream/main' into codex/SessionTokenCounter - [`120ed47`](https://github.com/ollama/ollama/commit/120ed473c38636545c99dcb00084ef8e3a5ba55d) Refine context usage indicator behavior ### 📊 Changes **12 files changed** (+703 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `app/store/database.go` (+40 -6) 📝 `app/store/database_test.go` (+93 -0) 📝 `app/store/store.go` (+6 -0) 📝 `app/store/store_test.go` (+9 -1) 📝 `app/ui/app/codegen/gotypes.gen.ts` (+8 -0) 📝 `app/ui/app/src/components/Chat.tsx` (+2 -0) 📝 `app/ui/app/src/components/ChatForm.tsx` (+93 -0) 📝 `app/ui/app/src/hooks/useChats.ts` (+38 -0) ➕ `app/ui/app/src/utils/contextUsage.test.ts` (+94 -0) ➕ `app/ui/app/src/utils/contextUsage.ts` (+274 -0) 📝 `app/ui/responses/types.go` (+2 -0) 📝 `app/ui/ui.go` (+44 -1) </details> ### 📄 Description ## Summary This change adds a conversation context usage indicator to the Ollama desktop chat UI. It persists `prompt_eval_count` and `eval_count` from completed chat responses, exposes those values to the frontend, and displays them as a compact circular indicator next to the model picker. The hover card shows: - current context usage - prompt/reply token breakdown from the latest completed turn - status messaging for normal, near-limit, and over-limit states - a warning when older messages may already be dropped from the prompt The implementation also keeps the indicator accessible by showing the hover card on keyboard focus. ## What changed - Added prompt/eval token counters to stored chat messages - Added a database migration for the new message fields - Forwarded token metrics through chat completion events - Updated frontend chat state to keep the latest metrics in sync - Replaced the larger context bar with a compact circular indicator and custom hover panel ## Testing - `go test ./app/store` - `npm run build` ## Screenshots You can tell at a glance whether the context window is getting full or has already been exceeded by the ring color, without needing to hover over it. <img width="827" height="147" alt="Screenshot 2026-03-27 222814" src="https://github.com/user-attachments/assets/4fd3a5b6-3e86-430b-aa5a-41484ec9a92b" /> <img width="886" height="290" alt="Screenshot 2026-03-27 213303" src="https://github.com/user-attachments/assets/55af8d3a-57b9-4c60-a504-c1a32b38f9a4" /> <img width="789" height="180" alt="Screenshot 2026-03-27 215845" src="https://github.com/user-attachments/assets/9ceda9fc-1afb-4ba0-9d35-d0e7a40e19c9" /> <img width="907" height="274" alt="Screenshot 2026-03-27 213256" src="https://github.com/user-attachments/assets/9437204e-4328-4f40-be69-0c31da248d68" /> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-23 01:41:07 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#40898