Skip to content

Conversation

@mostlygeek
Copy link
Owner

@mostlygeek mostlygeek commented Aug 14, 2025

Fixes #249

  • capture prompt processing metrics
  • display prompt processing metrics on UI Activity page

Summary by CodeRabbit

  • New Features
    • Added a “Prompt Processing” metric showing prompt speed (tokens/second) in the Activity table, appearing after “Output Tokens.”
    • Displays precise values with two decimals; shows “unknown” when the speed isn’t available.
    • Enhanced metrics tracking to capture and surface prompt processing speed across the app, enabling more detailed performance insights for each request.

- capture prompt processing metrics
- display prompt processing metrics on UI Activity page
@coderabbitai
Copy link

coderabbitai bot commented Aug 14, 2025

Walkthrough

Adds prompt_per_second to backend TokenMetrics, parses it from timings.prompt_per_second in proxy middleware, exposes it via JSON, updates UI API types, and displays a new “Prompt Processing” column on the Activity page using formatSpeed.

Changes

Cohort / File(s) Summary
Proxy metrics: struct + parsing
proxy/metrics_monitor.go, proxy/metrics_middleware.go
Add PromptPerSecond (float64, json:"prompt_per_second") to TokenMetrics and populate it from timings.prompt_per_second; defaults to -1.0 when timings absent.
UI API shape
ui/src/contexts/APIProvider.tsx
Extend Metrics interface with prompt_per_second: number.
UI Activity table rendering
ui/src/pages/Activity.tsx
Insert “Prompt Processing” column and render formatSpeed(metric.prompt_per_second) per row.

Sequence Diagram(s)

sequenceDiagram
  participant LlamaServer as llama-server
  participant Proxy as Proxy (metrics_middleware)
  participant UIAPI as APIProvider
  participant Activity as Activity Page

  LlamaServer-->>Proxy: Response with timings.prompt_per_second
  Proxy->>Proxy: parseAndRecordMetrics() extracts prompt_per_second
  Proxy-->>UIAPI: TokenMetrics JSON (prompt_per_second)
  UIAPI-->>Activity: Metrics.prompt_per_second
  Activity->>Activity: formatSpeed(prompt_per_second)
  Activity-->>User: Render "Prompt Processing" column
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Add Processing Speed in t/s or milliseconds to the Activity page (#249)

Assessment against linked issues: Out-of-scope changes

None found.

Possibly related PRs

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch prompt-speed-metrics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
proxy/metrics_monitor.go (1)

12-21: Document the sentinel semantics for PromptPerSecond

We’re relying on -1.0 to mean “unknown” downstream. Make this explicit in the struct to prevent misuse by future contributors.

 type TokenMetrics struct {
   ID              int       `json:"id"`
   Timestamp       time.Time `json:"timestamp"`
   Model           string    `json:"model"`
   InputTokens     int       `json:"input_tokens"`
   OutputTokens    int       `json:"output_tokens"`
-  PromptPerSecond float64   `json:"prompt_per_second"`
+  // PromptPerSecond represents average prompt token processing speed (tokens/sec).
+  // A value of -1.0 indicates the speed is unknown/unavailable.
+  PromptPerSecond float64   `json:"prompt_per_second"`
   TokensPerSecond float64   `json:"tokens_per_second"`
   DurationMs      int       `json:"duration_ms"`
 }
ui/src/pages/Activity.tsx (1)

55-55: Nit: Header wording for clarity

Consider renaming to better mirror “Generation Speed” and explicitly convey units.

-                <th className="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Prompt Processing</th>
+                <th className="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Prompt Speed (t/s)</th>
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a186318 and cfeeff3.

📒 Files selected for processing (4)
  • proxy/metrics_middleware.go (2 hunks)
  • proxy/metrics_monitor.go (1 hunks)
  • ui/src/contexts/APIProvider.tsx (1 hunks)
  • ui/src/pages/Activity.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
ui/src/contexts/APIProvider.tsx (1)
ui/src/pages/Models.tsx (3)
  • totalRequests (136-144)
  • StatsPanel (133-167)
  • sum (142-142)
ui/src/pages/Activity.tsx (1)
ui/src/pages/Models.tsx (1)
  • StatsPanel (133-167)
🔇 Additional comments (3)
ui/src/contexts/APIProvider.tsx (1)

31-31: LGTM: API surface aligned with backend

Adding prompt_per_second keeps the UI type in sync with the backend JSON (snake_case keys). The “unknown” handling in the Activity page covers the negative sentinel.

ui/src/pages/Activity.tsx (1)

67-67: LGTM: Correct rendering of prompt speed

Using formatSpeed(metric.prompt_per_second) ensures negative values map to “unknown” and others are displayed as t/s with two decimals.

proxy/metrics_middleware.go (1)

92-100: LGTM: Emitting new PromptPerSecond field

Wires promptPerSecond through to TokenMetrics with the correct JSON field for the UI.

@mostlygeek mostlygeek merged commit 74c69f3 into main Aug 14, 2025
3 checks passed
@mostlygeek mostlygeek deleted the prompt-speed-metrics branch October 10, 2025 05:14
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.

Feature Request: Add Processing Speed in t/s or milliseconds to the Activity page

2 participants