Skip to content
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

额度计算过程中存在一些取整操作导致计算结果偏小 #599

Closed
5 tasks done
wzxjohn opened this issue Oct 16, 2023 · 1 comment · Fixed by #627
Closed
5 tasks done

额度计算过程中存在一些取整操作导致计算结果偏小 #599

wzxjohn opened this issue Oct 16, 2023 · 1 comment · Fixed by #627
Labels
bug Something isn't working

Comments

@wzxjohn
Copy link
Contributor

wzxjohn commented Oct 16, 2023

例行检查

  • 我已确认目前没有类似 issue
  • 我已确认我已升级到最新版本
  • 我已完整查看过项目 README,尤其是常见问题部分
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述
在 API 调用的额度计算过程中,存在两次取整(舍去小数)操作,导致最终计算额度消耗略微偏小。
复现步骤
调用 API,查看后台日志:

gpt-3.5-turbo 123        78        $0.000338        模型倍率 0.75,分组倍率 1.00

实际消耗 $0.000338
该数值的计算方式为:

78*1.33=103.74,取整保留 103
0.75*1*(123+103)=169.5,取整保留 169
169/500000=0.000338

预期结果
按照公式,本次调用的消耗应为:

0.75*1*(123+78*1.33)=170.055
170.055/500000=0.00034011

按照 OpenAPI 官方算法,本次调用的消耗应为:

123*0.0015/1000 + 78*0.002/1000=0.0003405
@wzxjohn wzxjohn added the bug Something isn't working label Oct 16, 2023
@caoguangxin888
Copy link

你好具体在那个文件内呢?我想去做一下修改

wzxjohn added a commit to wzxjohn/one-api that referenced this issue Oct 24, 2023
Use float64 during calc and do math.Ceil after calc. This will result in the quota being used slightly more than the official standard, but it will be guaranteed that it will not be less.
songquanpeng added a commit that referenced this issue Nov 5, 2023
* fix: change quota calc code (close #599)

Use float64 during calc and do math.Ceil after calc. This will result in the quota being used slightly more than the official standard, but it will be guaranteed that it will not be less.

* chore: remove blank line

---------

Co-authored-by: JustSong <songquanpeng@foxmail.com>
humphery755 added a commit to humphery755/one-api that referenced this issue Nov 19, 2023
…ync-one-api

* 'main' of https://github.com/songquanpeng/one-api:
  fix: cloudflare test & expose detailed info about test failures (songquanpeng#715)
  feat: support tts model (songquanpeng#713)
  feat: keep sync with dall-e updates (songquanpeng#679)
  fix: fix PaLM not working issue (songquanpeng#667)
  fix: fix channel_id column name (songquanpeng#681, close songquanpeng#688)
  feat: add improve docker-compose.yml and support fast startup (songquanpeng#685)
  docs: add deploy to zeabur button (songquanpeng#693)
  fix: numeric sorting in tables (songquanpeng#695)
  feat: sync pricing for new 1106 models (songquanpeng#696)
  docs: update readme
  chore: update quota calc logic (close songquanpeng#599) (songquanpeng#627)
  fix: fix Cloudflare AI Gateway channel test support (songquanpeng#639)
  feat: support chatglm_turbo (songquanpeng#648)
  fix: fix typo (songquanpeng#651)
greeeds pushed a commit to greeeds/one-api that referenced this issue Mar 3, 2024
…#627)

* fix: change quota calc code (close songquanpeng#599)

Use float64 during calc and do math.Ceil after calc. This will result in the quota being used slightly more than the official standard, but it will be guaranteed that it will not be less.

* chore: remove blank line

---------

Co-authored-by: JustSong <songquanpeng@foxmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants