auto-coder 0.1.268__py3-none-any.whl → 0.1.270__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of auto-coder might be problematic. Click here for more details.
- {auto_coder-0.1.268.dist-info → auto_coder-0.1.270.dist-info}/METADATA +2 -2
- {auto_coder-0.1.268.dist-info → auto_coder-0.1.270.dist-info}/RECORD +23 -20
- autocoder/agent/auto_learn_from_commit.py +209 -0
- autocoder/auto_coder.py +4 -0
- autocoder/auto_coder_runner.py +2647 -0
- autocoder/chat_auto_coder.py +54 -2630
- autocoder/commands/auto_command.py +23 -33
- autocoder/common/__init__.py +6 -2
- autocoder/common/auto_coder_lang.py +21 -4
- autocoder/common/auto_configure.py +41 -30
- autocoder/common/code_modification_ranker.py +55 -11
- autocoder/common/command_templates.py +2 -3
- autocoder/common/context_pruner.py +214 -14
- autocoder/common/conversation_pruner.py +11 -10
- autocoder/index/entry.py +44 -22
- autocoder/index/index.py +1 -1
- autocoder/utils/auto_project_type.py +120 -0
- autocoder/utils/model_provider_selector.py +23 -23
- autocoder/version.py +1 -1
- {auto_coder-0.1.268.dist-info → auto_coder-0.1.270.dist-info}/LICENSE +0 -0
- {auto_coder-0.1.268.dist-info → auto_coder-0.1.270.dist-info}/WHEEL +0 -0
- {auto_coder-0.1.268.dist-info → auto_coder-0.1.270.dist-info}/entry_points.txt +0 -0
- {auto_coder-0.1.268.dist-info → auto_coder-0.1.270.dist-info}/top_level.txt +0 -0
|
@@ -21,6 +21,8 @@ from loguru import logger
|
|
|
21
21
|
from autocoder.utils import llms as llms_utils
|
|
22
22
|
from autocoder.rag.token_counter import count_tokens
|
|
23
23
|
from autocoder.common.global_cancel import global_cancel
|
|
24
|
+
from autocoder.common.auto_configure import config_readme
|
|
25
|
+
from autocoder.utils.auto_project_type import ProjectTypeAnalyzer
|
|
24
26
|
|
|
25
27
|
class CommandMessage(BaseModel):
|
|
26
28
|
role: str
|
|
@@ -155,7 +157,8 @@ class CommandAutoTuner:
|
|
|
155
157
|
self.printer = Printer()
|
|
156
158
|
self.memory_config = memory_config
|
|
157
159
|
self.command_config = command_config
|
|
158
|
-
self.tools = AutoCommandTools(args=args, llm=self.llm)
|
|
160
|
+
self.tools = AutoCommandTools(args=args, llm=self.llm)
|
|
161
|
+
self.project_type_analyzer = ProjectTypeAnalyzer(args=args, llm=self.llm)
|
|
159
162
|
|
|
160
163
|
def get_conversations(self) -> List[CommandMessage]:
|
|
161
164
|
"""Get conversation history from memory file"""
|
|
@@ -440,7 +443,7 @@ class CommandAutoTuner:
|
|
|
440
443
|
safe_zone=self.args.conversation_prune_safe_zone_tokens
|
|
441
444
|
)
|
|
442
445
|
from autocoder.common.conversation_pruner import ConversationPruner
|
|
443
|
-
pruner = ConversationPruner(self.llm)
|
|
446
|
+
pruner = ConversationPruner(self.args, self.llm)
|
|
444
447
|
conversations = pruner.prune_conversations(conversations)
|
|
445
448
|
|
|
446
449
|
title = printer.get_message_from_key("auto_command_analyzing")
|
|
@@ -646,34 +649,7 @@ class CommandAutoTuner:
|
|
|
646
649
|
|
|
647
650
|
常见的一些配置选项示例:
|
|
648
651
|
|
|
649
|
-
|
|
650
|
-
## auto_merge: 代码合并方式,可选值为editblock、diff、wholefile.
|
|
651
|
-
- editblock: 生成 SEARCH/REPLACE 块,然后根据 SEARCH块到对应的源码查找,如果相似度阈值大于 editblock_similarity, 那么则将
|
|
652
|
-
找到的代码块替换为 REPLACE 块。大部分情况都推荐使用 editblock。
|
|
653
|
-
- wholefile: 重新生成整个文件,然后替换原来的文件。对于重构场景,推荐使用 wholefile。
|
|
654
|
-
- diff: 生成标准 git diff 格式,适用于简单的代码修改。
|
|
655
|
-
|
|
656
|
-
## editblock_similarity: editblock相似度阈值
|
|
657
|
-
- editblock相似度阈值,取值范围为0-1,默认值为0.9。如果设置的太低,虽然能合并进去,但是会引入错误。推荐不要修改该值。
|
|
658
|
-
|
|
659
|
-
## generate_times_same_model: 相同模型生成次数,也叫采样数
|
|
660
|
-
当进行生成代码时,大模型会对同一个需求生成多份代码,然后会使用 generate_rerank_model 模型对多份代码进行重排序,
|
|
661
|
-
然后选择得分最高的代码。一般次数越多,最终得到正确的代码概率越高。默认值为1,推荐设置为3。但是设置值越多,可能速度就越慢,消耗的token也越多。
|
|
662
|
-
当用户提到,帮我采样数设置为3, 那么你就设置该参数即可。
|
|
663
|
-
|
|
664
|
-
## skip_filter_index: 是否跳过索引过滤
|
|
665
|
-
是否跳过根据用户的query 自动查找上下文。推荐设置为 false
|
|
666
|
-
|
|
667
|
-
## skip_build_index: 是否跳过索引构建
|
|
668
|
-
是否自动构建索引。推荐设置为 false。注意,如果该值设置为 true, 那么 skip_filter_index 设置不会生效。
|
|
669
|
-
|
|
670
|
-
## enable_global_memory: 是否开启全局记忆
|
|
671
|
-
是否开启全局记忆。
|
|
672
|
-
|
|
673
|
-
## rank_times_same_model: 相同模型重排序次数
|
|
674
|
-
默认值为1. 如果 generate_times_same_model 参数设置大于1,那么 coding 函数会自动对多份代码进行重排序。
|
|
675
|
-
rank_times_same_model 表示重拍的次数,次数越多,选择到最好的代码的可能性越高,但是也会显著增加消耗的token和时间。
|
|
676
|
-
建议保持默认,要修改也建议不要超过3。
|
|
652
|
+
{{ config_readme }}
|
|
677
653
|
|
|
678
654
|
比如你想开启索引,则可以执行:
|
|
679
655
|
|
|
@@ -1190,10 +1166,26 @@ class CommandAutoTuner:
|
|
|
1190
1166
|
exclude_files(query="/drop regex://.*/package-lock\.json")
|
|
1191
1167
|
</usage>
|
|
1192
1168
|
</command>
|
|
1169
|
+
|
|
1170
|
+
<command>
|
|
1171
|
+
<name>get_project_type</name>
|
|
1172
|
+
<description>获取项目类型。</description>
|
|
1173
|
+
<usage>
|
|
1174
|
+
该命令获取项目类型。
|
|
1175
|
+
|
|
1176
|
+
使用例子:
|
|
1177
|
+
get_project_type()
|
|
1178
|
+
|
|
1179
|
+
此时会返回诸如 "ts,py,java,go,js,ts" 这样的字符串,表示项目类型。
|
|
1180
|
+
</usage>
|
|
1181
|
+
</command>
|
|
1193
1182
|
</commands>
|
|
1194
1183
|
|
|
1195
1184
|
|
|
1196
1185
|
'''
|
|
1186
|
+
return {
|
|
1187
|
+
"config_readme": config_readme.prompt()
|
|
1188
|
+
}
|
|
1197
1189
|
|
|
1198
1190
|
def execute_auto_command(self, command: str, parameters: Dict[str, Any]) -> None:
|
|
1199
1191
|
"""
|
|
@@ -1232,9 +1224,7 @@ class CommandAutoTuner:
|
|
|
1232
1224
|
"get_project_related_files": self.tools.get_project_related_files,
|
|
1233
1225
|
"ask_user":self.tools.ask_user,
|
|
1234
1226
|
"read_file_with_keyword_ranges": self.tools.read_file_with_keyword_ranges,
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1227
|
+
"get_project_type": self.project_type_analyzer.analyze,
|
|
1238
1228
|
}
|
|
1239
1229
|
|
|
1240
1230
|
if command not in command_map:
|
autocoder/common/__init__.py
CHANGED
|
@@ -376,12 +376,16 @@ class AutoCoderArgs(pydantic.BaseModel):
|
|
|
376
376
|
conversation_prune_group_size: Optional[int] = 4
|
|
377
377
|
conversation_prune_strategy: Optional[str] = "summarize"
|
|
378
378
|
|
|
379
|
-
context_prune_strategy: Optional[str] = "
|
|
379
|
+
context_prune_strategy: Optional[str] = "extract"
|
|
380
380
|
context_prune: Optional[bool] = True
|
|
381
|
+
context_prune_sliding_window_size: Optional[int] = 1000
|
|
382
|
+
context_prune_sliding_window_overlap: Optional[int] = 100
|
|
381
383
|
|
|
382
384
|
auto_command_max_iterations: Optional[int] = 10
|
|
383
385
|
|
|
384
|
-
skip_commit: Optional[bool] = False
|
|
386
|
+
skip_commit: Optional[bool] = False
|
|
387
|
+
|
|
388
|
+
enable_beta: Optional[bool] = False
|
|
385
389
|
|
|
386
390
|
class Config:
|
|
387
391
|
protected_namespaces = ()
|
|
@@ -130,7 +130,7 @@ MESSAGES = {
|
|
|
130
130
|
"quick_filter_too_long": "⚠️ index file is too large ({{ tokens_len }}/{{ max_tokens }}). The query will be split into {{ split_size }} chunks.",
|
|
131
131
|
"quick_filter_tokens_len": "📊 Current index size: {{ tokens_len }} tokens",
|
|
132
132
|
"estimated_chat_input_tokens": "Estimated chat input tokens: {{ estimated_input_tokens }}",
|
|
133
|
-
"estimated_input_tokens_in_generate": "Estimated input tokens in generate ({{ generate_mode }}): {{ estimated_input_tokens }}",
|
|
133
|
+
"estimated_input_tokens_in_generate": "Estimated input tokens in generate ({{ generate_mode }}): {{ estimated_input_tokens }}",
|
|
134
134
|
"model_has_access_restrictions": "{{model_name}} has access restrictions, cannot use the current function",
|
|
135
135
|
"auto_command_not_found": "Auto command not found: {{command}}. Please check your input and try again.",
|
|
136
136
|
"auto_command_failed": "Auto command failed: {{error}}. Please check your input and try again.",
|
|
@@ -161,9 +161,22 @@ MESSAGES = {
|
|
|
161
161
|
"index_import_success": "Index imported successfully: {{path}}",
|
|
162
162
|
"edits_title": "edits",
|
|
163
163
|
"diff_blocks_title":"diff blocks",
|
|
164
|
-
"index_exclude_files_error": "index filter exclude files fail: {{ error }}"
|
|
164
|
+
"index_exclude_files_error": "index filter exclude files fail: {{ error }}",
|
|
165
|
+
"file_sliding_window_processing": "File {{ file_path }} is too large ({{ tokens }} tokens), processing with sliding window...",
|
|
166
|
+
"file_snippet_processing": "Processing file {{ file_path }} with code snippet extraction...",
|
|
167
|
+
"context_pruning_start": "⚠️ Context pruning started. Total tokens: {{ total_tokens }} (max allowed: {{ max_tokens }}). Applying strategy: {{ strategy }}.",
|
|
168
|
+
"context_pruning_reason": "Context length exceeds maximum limit ({{ total_tokens }} > {{ max_tokens }}). Pruning is required to fit within the model's context window.",
|
|
169
|
+
"rank_code_modification_title": "{{model_name}} ranking codes",
|
|
170
|
+
"sorted_files_message": "Reordered files:\n{% for file in files %}- {{ file }}\n{% endfor %}",
|
|
171
|
+
"estimated_input_tokens_in_ranking": "estimate input token {{ estimated_input_tokens }} when ranking",
|
|
172
|
+
"file_snippet_procesed": "{{ file_path }} processed with tokens: {{ tokens }} => {{ snippet_tokens }}. Current total tokens: {{ total_tokens }}",
|
|
173
|
+
|
|
165
174
|
},
|
|
166
175
|
"zh": {
|
|
176
|
+
"file_sliding_window_processing": "文件 {{ file_path }} 过大 ({{ tokens }} tokens),正在使用滑动窗口处理...",
|
|
177
|
+
"file_snippet_processing": "正在对文件 {{ file_path }} 进行代码片段提取...",
|
|
178
|
+
"context_pruning_start": "⚠️ 开始上下文剪枝。总token数: {{ total_tokens }} (最大允许: {{ max_tokens }})。正在应用策略: {{ strategy }}。",
|
|
179
|
+
"context_pruning_reason": "上下文长度超过最大限制 ({{ total_tokens }} > {{ max_tokens }})。需要进行剪枝以适配模型的上下文窗口。",
|
|
167
180
|
"file_scored_message": "文件评分: {{file_path}} - 分数: {{score}}",
|
|
168
181
|
"invalid_file_pattern": "无效的文件模式: {{file_pattern}}. 例如: regex://.*/package-lock\\.json",
|
|
169
182
|
"conf_not_found": "未找到配置文件: {{path}}",
|
|
@@ -304,7 +317,7 @@ MESSAGES = {
|
|
|
304
317
|
"quick_filter_title": "{{ model_name }} 正在分析如何筛选上下文...",
|
|
305
318
|
"quick_filter_failed": "❌ 快速过滤器失败: {{ error }}. ",
|
|
306
319
|
"estimated_chat_input_tokens": "对话输入token预估为: {{ estimated_input_tokens }}",
|
|
307
|
-
"estimated_input_tokens_in_generate": "生成代码({{ generate_mode }})预计输入token数: {{
|
|
320
|
+
"estimated_input_tokens_in_generate": "生成代码({{ generate_mode }})预计输入token数: {{ estimated_input_tokens }}",
|
|
308
321
|
"model_has_access_restrictions": "{{model_name}} 有访问限制,无法使用当前功能",
|
|
309
322
|
"auto_command_not_found": "未找到自动命令: {{command}}。请检查您的输入并重试。",
|
|
310
323
|
"auto_command_failed": "自动命令执行失败: {{error}}。请检查您的输入并重试。",
|
|
@@ -320,7 +333,11 @@ MESSAGES = {
|
|
|
320
333
|
"index_import_success": "索引导入成功: {{path}}",
|
|
321
334
|
"edits_title": "编辑块",
|
|
322
335
|
"diff_blocks_title": "差异块",
|
|
323
|
-
"index_exclude_files_error": "索引排除文件时出错: {{error}}"
|
|
336
|
+
"index_exclude_files_error": "索引排除文件时出错: {{error}}",
|
|
337
|
+
"rank_code_modification_title": "模型{{model_name}}对代码打分",
|
|
338
|
+
"sorted_files_message": "重新排序后的文件路径:\n{% for file in files %}- {{ file }}\n{% endfor %}",
|
|
339
|
+
"estimated_input_tokens_in_ranking": "排序预计输入token数: {{ estimated_input_tokens }}",
|
|
340
|
+
"file_snippet_procesed": "文件 {{ file_path }} 处理后token数: {{ tokens }} => {{ snippet_tokens }} 当前总token数: {{ total_tokens }}"
|
|
324
341
|
}}
|
|
325
342
|
|
|
326
343
|
|
|
@@ -119,7 +119,45 @@ class AutoConfigRequest(BaseModel):
|
|
|
119
119
|
|
|
120
120
|
class AutoConfigResponse(BaseModel):
|
|
121
121
|
configs: List[Dict[str, Any]] = Field(default_factory=list)
|
|
122
|
-
reasoning: str = ""
|
|
122
|
+
reasoning: str = ""
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@byzerllm.prompt()
|
|
126
|
+
def config_readme() -> str:
|
|
127
|
+
"""
|
|
128
|
+
# 配置项说明
|
|
129
|
+
## auto_merge: 代码合并方式,可选值为editblock、diff、wholefile.
|
|
130
|
+
- editblock: 生成 SEARCH/REPLACE 块,然后根据 SEARCH块到对应的源码查找,如果相似度阈值大于 editblock_similarity, 那么则将
|
|
131
|
+
找到的代码块替换为 REPLACE 块。大部分情况都推荐使用 editblock。
|
|
132
|
+
- wholefile: 重新生成整个文件,然后替换原来的文件。对于重构场景,推荐使用 wholefile。
|
|
133
|
+
- diff: 生成标准 git diff 格式,适用于简单的代码修改。
|
|
134
|
+
|
|
135
|
+
## editblock_similarity: editblock相似度阈值
|
|
136
|
+
- editblock相似度阈值,取值范围为0-1,默认值为0.9。如果设置的太低,虽然能合并进去,但是会引入错误。推荐不要修改该值。
|
|
137
|
+
|
|
138
|
+
## generate_times_same_model: 相同模型生成次数
|
|
139
|
+
当进行生成代码时,大模型会对同一个需求生成多份代码,然后会使用 generate_rerank_model 模型对多份代码进行重排序,
|
|
140
|
+
然后选择得分最高的代码。一般次数越多,最终得到正确的代码概率越高。默认值为1,推荐设置为3。但是设置值越多,可能速度就越慢,消耗的token也越多。
|
|
141
|
+
|
|
142
|
+
## skip_filter_index: 是否跳过索引过滤
|
|
143
|
+
是否跳过根据用户的query 自动查找上下文。推荐设置为 false
|
|
144
|
+
|
|
145
|
+
## skip_build_index: 是否跳过索引构建
|
|
146
|
+
是否自动构建索引。推荐设置为 false。注意,如果该值设置为 true, 那么 skip_filter_index 设置不会生效。
|
|
147
|
+
|
|
148
|
+
## rank_times_same_model: 相同模型重排序次数
|
|
149
|
+
默认值为1. 如果 generate_times_same_model 参数设置大于1,那么 coding 函数会自动对多份代码进行重排序。
|
|
150
|
+
rank_times_same_model 表示重拍的次数,次数越多,选择到最好的代码的可能性越高,但是也会显著增加消耗的token和时间。
|
|
151
|
+
建议保持默认,要修改也建议不要超过3。
|
|
152
|
+
|
|
153
|
+
## project_type: 项目类型
|
|
154
|
+
项目类型通常为如下三种选择:
|
|
155
|
+
1. ts
|
|
156
|
+
2. py
|
|
157
|
+
3. 代码文件后缀名列表(比如.java,.py,.go,.js,.ts),多个按逗号分割
|
|
158
|
+
|
|
159
|
+
推荐使用 3 选项,因为项目类型通常为多种后缀名混合。
|
|
160
|
+
"""
|
|
123
161
|
|
|
124
162
|
class ConfigAutoTuner:
|
|
125
163
|
def __init__(self,args: AutoCoderArgs, llm: Union[byzerllm.ByzerLLM, byzerllm.SimpleByzerLLM], memory_config: MemoryConfig):
|
|
@@ -135,34 +173,7 @@ class ConfigAutoTuner:
|
|
|
135
173
|
self.memory_config.configure(conf, skip_print)
|
|
136
174
|
|
|
137
175
|
|
|
138
|
-
|
|
139
|
-
def config_readme(self) -> str:
|
|
140
|
-
"""
|
|
141
|
-
# 配置项说明
|
|
142
|
-
## auto_merge: 代码合并方式,可选值为editblock、diff、wholefile.
|
|
143
|
-
- editblock: 生成 SEARCH/REPLACE 块,然后根据 SEARCH块到对应的源码查找,如果相似度阈值大于 editblock_similarity, 那么则将
|
|
144
|
-
找到的代码块替换为 REPLACE 块。大部分情况都推荐使用 editblock。
|
|
145
|
-
- wholefile: 重新生成整个文件,然后替换原来的文件。对于重构场景,推荐使用 wholefile。
|
|
146
|
-
- diff: 生成标准 git diff 格式,适用于简单的代码修改。
|
|
147
|
-
|
|
148
|
-
## editblock_similarity: editblock相似度阈值
|
|
149
|
-
- editblock相似度阈值,取值范围为0-1,默认值为0.9。如果设置的太低,虽然能合并进去,但是会引入错误。推荐不要修改该值。
|
|
150
|
-
|
|
151
|
-
## generate_times_same_model: 相同模型生成次数
|
|
152
|
-
当进行生成代码时,大模型会对同一个需求生成多份代码,然后会使用 generate_rerank_model 模型对多份代码进行重排序,
|
|
153
|
-
然后选择得分最高的代码。一般次数越多,最终得到正确的代码概率越高。默认值为1,推荐设置为3。但是设置值越多,可能速度就越慢,消耗的token也越多。
|
|
154
|
-
|
|
155
|
-
## skip_filter_index: 是否跳过索引过滤
|
|
156
|
-
是否跳过根据用户的query 自动查找上下文。推荐设置为 false
|
|
157
|
-
|
|
158
|
-
## skip_build_index: 是否跳过索引构建
|
|
159
|
-
是否自动构建索引。推荐设置为 false。注意,如果该值设置为 true, 那么 skip_filter_index 设置不会生效。
|
|
160
|
-
|
|
161
|
-
## rank_times_same_model: 相同模型重排序次数
|
|
162
|
-
默认值为1. 如果 generate_times_same_model 参数设置大于1,那么 coding 函数会自动对多份代码进行重排序。
|
|
163
|
-
rank_times_same_model 表示重拍的次数,次数越多,选择到最好的代码的可能性越高,但是也会显著增加消耗的token和时间。
|
|
164
|
-
建议保持默认,要修改也建议不要超过3。
|
|
165
|
-
"""
|
|
176
|
+
|
|
166
177
|
|
|
167
178
|
def command_readme(self) -> str:
|
|
168
179
|
"""
|
|
@@ -212,7 +223,7 @@ class ConfigAutoTuner:
|
|
|
212
223
|
"query": request.query,
|
|
213
224
|
"current_conf": json.dumps(self.memory_config.memory["conf"], indent=2),
|
|
214
225
|
"last_execution_stat": "",
|
|
215
|
-
"config_readme":
|
|
226
|
+
"config_readme": config_readme.prompt()
|
|
216
227
|
}
|
|
217
228
|
|
|
218
229
|
def tune(self, request: AutoConfigRequest) -> 'AutoConfigResponse':
|
|
@@ -6,11 +6,13 @@ from pydantic import BaseModel
|
|
|
6
6
|
from autocoder.common.printer import Printer
|
|
7
7
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
8
8
|
import traceback
|
|
9
|
-
from autocoder.common.utils_code_auto_generate import chat_with_continue
|
|
9
|
+
from autocoder.common.utils_code_auto_generate import chat_with_continue,stream_chat_with_continue
|
|
10
10
|
from byzerllm.utils.str2model import to_model
|
|
11
|
+
from autocoder.utils.auto_coder_utils.chat_stream_out import stream_out
|
|
11
12
|
from autocoder.utils.llms import get_llm_names, get_model_info
|
|
12
13
|
from autocoder.common.types import CodeGenerateResult, MergeCodeWithoutEffect
|
|
13
14
|
import os
|
|
15
|
+
from autocoder.rag.token_counter import count_tokens
|
|
14
16
|
|
|
15
17
|
class RankResult(BaseModel):
|
|
16
18
|
rank_result: List[int]
|
|
@@ -133,6 +135,15 @@ class CodeModificationRanker:
|
|
|
133
135
|
else:
|
|
134
136
|
raise Exception(f"Invalid rank strategy: {self.args.rank_strategy}")
|
|
135
137
|
|
|
138
|
+
# 计算 query 的 token 数量
|
|
139
|
+
token_count = count_tokens(query)
|
|
140
|
+
|
|
141
|
+
# 打印 token 统计信息
|
|
142
|
+
self.printer.print_in_terminal(
|
|
143
|
+
"estimated_input_tokens_in_ranking",
|
|
144
|
+
estimated_input_tokens=token_count
|
|
145
|
+
)
|
|
146
|
+
|
|
136
147
|
input_tokens_count = 0
|
|
137
148
|
generated_tokens_count = 0
|
|
138
149
|
try:
|
|
@@ -145,16 +156,25 @@ class CodeModificationRanker:
|
|
|
145
156
|
self.printer.print_in_terminal(
|
|
146
157
|
"ranking_start", style="blue", count=len(generate_result.contents), model_name=model_name)
|
|
147
158
|
|
|
148
|
-
for
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
159
|
+
for i in range(rank_times):
|
|
160
|
+
if i == 0:
|
|
161
|
+
futures.append(
|
|
162
|
+
executor.submit(
|
|
163
|
+
stream_chat_with_continue,
|
|
164
|
+
llm,
|
|
165
|
+
[{"role": "user", "content": query}],
|
|
166
|
+
{}
|
|
167
|
+
)
|
|
168
|
+
)
|
|
169
|
+
else:
|
|
170
|
+
futures.append(
|
|
171
|
+
executor.submit(
|
|
172
|
+
chat_with_continue,
|
|
173
|
+
llm,
|
|
174
|
+
[{"role": "user", "content": query}],
|
|
175
|
+
{}
|
|
176
|
+
)
|
|
156
177
|
)
|
|
157
|
-
)
|
|
158
178
|
|
|
159
179
|
# Collect all results
|
|
160
180
|
results = []
|
|
@@ -180,7 +200,31 @@ class CodeModificationRanker:
|
|
|
180
200
|
total_input_cost = 0.0
|
|
181
201
|
total_output_cost = 0.0
|
|
182
202
|
|
|
183
|
-
|
|
203
|
+
# 第一个future使用流式输出
|
|
204
|
+
stream_future = futures[0]
|
|
205
|
+
model_name = model_names[0]
|
|
206
|
+
stream_generator = stream_future.result()
|
|
207
|
+
full_response, last_meta = stream_out(
|
|
208
|
+
stream_generator,
|
|
209
|
+
model_name=model_name,
|
|
210
|
+
title=self.printer.get_message_from_key_with_format(
|
|
211
|
+
"rank_code_modification_title", model_name=model_name),
|
|
212
|
+
args=self.args
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
if last_meta:
|
|
216
|
+
input_tokens_count += last_meta.input_tokens_count
|
|
217
|
+
generated_tokens_count += last_meta.generated_tokens_count
|
|
218
|
+
# 计算成本
|
|
219
|
+
info = model_info_map.get(model_name, {})
|
|
220
|
+
# 计算公式:token数 * 单价 / 1000000
|
|
221
|
+
total_input_cost += (last_meta.input_tokens_count * info.get("input_cost", 0.0)) / 1000000
|
|
222
|
+
total_output_cost += (last_meta.generated_tokens_count * info.get("output_cost", 0.0)) / 1000000
|
|
223
|
+
|
|
224
|
+
v = to_model(full_response,RankResult)
|
|
225
|
+
results.append(v.rank_result)
|
|
226
|
+
|
|
227
|
+
for future, model_name in zip(futures[1:], model_names[1:]):
|
|
184
228
|
try:
|
|
185
229
|
result = future.result()
|
|
186
230
|
input_tokens_count += result.input_tokens_count
|
|
@@ -174,9 +174,8 @@ def base_base(source_dir:str,project_type:str)->str:
|
|
|
174
174
|
source_dir: {{ source_dir }}
|
|
175
175
|
target_file: {{ target_file }}
|
|
176
176
|
|
|
177
|
-
model: v3_chat
|
|
178
|
-
model_max_input_length:
|
|
179
|
-
model_max_input_length: 120000
|
|
177
|
+
model: v3_chat
|
|
178
|
+
model_max_input_length: 60000
|
|
180
179
|
enable_multi_round_generate: false
|
|
181
180
|
index_filter_workers: 100
|
|
182
181
|
index_build_workers: 100
|