-
Notifications
You must be signed in to change notification settings - Fork 9
revert: Token estimation values should use existing auto-calculation #29
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
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/fix-token-estimation-values
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,12 @@ def __init__( | |
| self.max_async = config.llm.max_async | ||
| self.vlm_timeout = config.llm.vlm_timeout | ||
|
|
||
| # Token 估算配置 | ||
| self.llm_estimated_output_tokens = config.llm.estimated_output_tokens | ||
| self.vlm_estimated_output_tokens = config.llm.vlm_estimated_output_tokens | ||
| self.vlm_max_tokens = config.llm.vlm_max_tokens | ||
| self.vlm_image_tokens_estimate = config.llm.vlm_image_tokens_estimate | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问题同.env.example
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已在 e2cb6e7 中撤销相关修改。 |
||
| # 存储配置 | ||
| self.use_external_storage = config.storage.use_external | ||
| self.kv_storage = config.storage.kv_storage | ||
|
|
@@ -106,11 +112,14 @@ def _create_llm_func(self, llm_config: Dict): | |
| # 获取 rate_limiter 实际使用的并发数(将用于 LightRAG) | ||
| actual_max_concurrent = rate_limiter.max_concurrent | ||
|
|
||
| # 获取 token 估算配置(支持租户覆盖) | ||
| llm_estimated_output = llm_config.get("estimated_output_tokens", self.llm_estimated_output_tokens) | ||
|
|
||
| def llm_model_func(prompt, **kwargs): | ||
| # 精确计算输入 tokens(使用 tiktoken) | ||
| input_tokens = count_tokens(prompt, model="cl100k_base") | ||
| # 保守估算输出 tokens(实体提取通常输出较长) | ||
| estimated_output = 3000 # 50 entities + 46 relations ≈ 3000 tokens | ||
| estimated_output = llm_estimated_output # 从配置读取 | ||
| estimated_tokens = input_tokens + estimated_output | ||
|
|
||
| # Debug: 输出 token 计数 | ||
|
|
@@ -295,6 +304,11 @@ def _create_vision_model_func(self, llm_config: Dict): | |
| tokens_per_minute=tokens_per_minute | ||
| ) | ||
|
|
||
| # 获取 VLM token 估算配置(支持租户覆盖) | ||
| vlm_image_tokens = llm_config.get("vlm_image_tokens_estimate", self.vlm_image_tokens_estimate) | ||
| vlm_estimated_output = llm_config.get("vlm_estimated_output_tokens", self.vlm_estimated_output_tokens) | ||
| vlm_max_tokens = llm_config.get("vlm_max_tokens", self.vlm_max_tokens) | ||
|
|
||
| async def seed_vision_model_func(prompt: str, image_data: str, system_prompt: str) -> str: | ||
| """ | ||
| 使用 VLM 理解图片内容(带速率限制) | ||
|
|
@@ -309,8 +323,8 @@ async def seed_vision_model_func(prompt: str, image_data: str, system_prompt: st | |
| """ | ||
| # 精确计算 tokens(使用 tiktoken) | ||
| prompt_tokens = count_tokens(prompt, model="cl100k_base") | ||
| image_tokens = 200 # 图片约 200 tokens(固定估算) | ||
| estimated_output = 500 # VLM 输出通常较短 | ||
| image_tokens = vlm_image_tokens # 从配置读取 | ||
| estimated_output = vlm_estimated_output # 从配置读取 | ||
| estimated_tokens = prompt_tokens + image_tokens + estimated_output | ||
|
|
||
| # Debug: 输出 token 计数 | ||
|
|
@@ -336,7 +350,7 @@ async def seed_vision_model_func(prompt: str, image_data: str, system_prompt: st | |
| ] | ||
| } | ||
| ], | ||
| "max_tokens": 500, | ||
| "max_tokens": vlm_max_tokens, # 从配置读取 | ||
| "temperature": 0.1 | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个变量值和LLM_REQUESTS_PER_MINUTE=800 # 每分钟最大请求数(默认 800)
LLM_TOKENS_PER_MINUTE=40000 # 每分钟最大令牌数(包含输入+输出,默认 40000)
是不是有冲突?明明是自动计算,为什么还要这些估算值? @copilot @claude
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实有冲突。已在 e2cb6e7 中撤销这些配置项。
rate_limiter.py的avg_tokens_map已内置各服务的 token 估算值,通过LLM_REQUESTS_PER_MINUTE/LLM_TOKENS_PER_MINUTE自动计算并发数,不需要额外暴露这些内部值。