8000 feat: Log table show output speed by tbphp · Pull Request #1302 · QuantumNous/new-api · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Log table show output speed #1302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tbphp
Copy link
Contributor
@tbphp tbphp commented Jun 26, 2025

日志列表显示输出token的速度

如图,在日志列表增加了输出速度显示。

实现方案

计算方式:
总输出tokens / 总时长(包含首字时长)
此处计算的平均输出速度,没有扣除首字响应时长。可以讨论是否调整计算方式为从首字返回时开始计算。

改动范围

consumedTime
!!破坏性修改:用时字段,从秒改为毫秒。因为使用秒计算误差太大。并且为了日志中和首字响应时间统一起来都保留一位小数。
此处是破坏性修改,更新后会影响历史数据的时间显示和速度计算都会异常。如果考虑日志影响不大,可以直接升级。
此处可讨论,是否使用新字段,使用新字段就会导致logs表冗余无用字段。

Summary by CodeRabbit

  • New Features

    • Added display of token processing speed (tokens per second) in the logs table, shown alongside usage time.
    • Updated logs table column header to reflect the addition of speed information.
  • Bug Fixes

    • Improved accuracy of usage time calculations by switching from seconds to milliseconds throughout the system for log records and display.
  • Style

    • Enhanced formatting of usage time and speed values for clearer presentation in the logs table.

Copy link
Contributor
coderabbitai bot commented Jun 26, 2025

Walkthrough

The changes standardize time measurement from seconds to milliseconds across several backend logging and quota functions, updating variable names and function signatures accordingly. The frontend log table now displays token processing speed (tokens per second) alongside use time, with new formatting and a revised column header to reflect these enhancements.

Changes

File(s) Change Summary
controller/channel-test.go Changed consumedTime calculation in testChannel from seconds to milliseconds, updating its usage accordingly.
model/log.go Renamed time parameter from useTimeSeconds to useTimeMs in logging functions and updated function signatures.
relay/relay-text.go Updated elapsed time calculation from seconds to milliseconds in postConsumeQuota, renamed variable, and updated log.
service/quota.go Changed usage time calculation from seconds to milliseconds in three quota functions and updated related variable names.
web/src/components/table/LogsTable.js Added renderUseSpeed for tokens/sec; updated renderUseTime to use ms→s; changed column header and render logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant Model

    User->>Frontend: Initiate log view
    Frontend->>Backend: Request logs
    Backend->>Model: Fetch logs with useTimeMs (ms)
    Model-->>Backend: Return logs (use_time in ms)
    Backend-->>Frontend: Send logs (use_time in ms)
    Frontend->>Frontend: Calculate tokens/sec (completion_tokens / use_time * 1000)
    Frontend-->>User: Display speed (t/s) and use time (s)
Loading

Poem

In milliseconds now we count,
Each token’s journey, every amount.
Logs display a swifter pace,
With speeds and times in one neat place.
The rabbit cheers this clever feat,
For data clear is hard to beat!
🕒✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf4700a and 2d52021.

📒 Files selected for processing (5)
  • controller/channel-test.go (1 hunks)
  • model/log.go (4 hunks)
  • relay/relay-text.go (2 hunks)
  • service/quota.go (4 hunks)
  • web/src/components/table/LogsTable.js (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: 9Ninety
PR: QuantumNous/new-api#1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
relay/relay-text.go (1)
Learnt from: 9Ninety
PR: QuantumNous/new-api#1273
File: relay/channel/gemini/relay-gemini.go:97-116
Timestamp: 2025-06-21T03:37:41.726Z
Learning: In relay/channel/gemini/relay-gemini.go, the thinking budget calculation logic (including the MaxOutputTokens multiplication) was introduced in PR #1247. PR #1273 focused specifically on decoupling the thoughts summary feature from thinking budget settings and did not modify the existing thinking budget behavior.
🔇 Additional comments (7)
model/log.go (1)

95-96: LGTM: Clean parameter rename for time unit standardization.

The parameter name changes from useTimeSeconds to useTimeMs clearly reflect the shift from seconds to milliseconds. The function signatures and field assignments are updated consistently.

Also applies to: 122-122, 140-141, 170-170

controller/channel-test.go (1)

170-170: LGTM: Correct removal of seconds conversion.

The change from float64(milliseconds) / 1000.0 to float64(milliseconds) correctly aligns with the new expectation that logging functions receive time in milliseconds rather than seconds.

service/quota.go (1)

149-149: LGTM: Consistent time unit standardization across quota functions.

All three quota functions consistently updated to:

  • Use UnixMilli() for millisecond precision
  • Rename variables from useTimeSeconds to useTimeMs
  • Pass millisecond values to logging functions

The changes maintain consistency across PostWssConsumeQuota, PostClaudeConsumeQuota, and PostAudioConsumeQuota.

Also applies to: 212-212, 218-218, 278-278, 284-284, 355-355

relay/relay-text.go (1)

350-350: LGTM: Consistent time calculation update.

The change from Unix() to UnixMilli() and variable rename from useTimeSeconds to useTimeMs maintains consistency with the time unit standardization across the codebase.

Also applies to: 544-544

web/src/components/table/LogsTable.js (3)

187-199: LGTM: Well-implemented token speed calculation.

The new renderUseSpeed function correctly calculates tokens per second:

  • Safely checks for positive values before calculation
  • Uses correct formula: (completion_tokens / use_time * 1000) to convert from milliseconds to seconds
  • Formats output to 1 decimal place with appropriate units

Note: As mentioned in the PR description, this includes first token response time in the calculation, which may affect accuracy for speed metrics, but provides a useful approximate measure.


134-135: LGTM: Correct time unit conversion for display.

The renderUseTime function properly converts the new millisecond values to seconds for display by dividing by 1000.0, maintaining the same user experience while adapting to the backend time unit changes.


502-502: LGTM: Appropriate UI updates for new speed feature.

The column header update to "速度/用时/首字" (Speed/Use Time/First Token) clearly communicates the new information displayed, and the speed rendering is appropriately added to both streaming and non-streaming display paths.

Also applies to: 513-513, 524-524

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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.

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.

1 participant
0