auto-coder 0.1.250__py3-none-any.whl → 0.1.252__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.250.dist-info → auto_coder-0.1.252.dist-info}/METADATA +2 -2
- {auto_coder-0.1.250.dist-info → auto_coder-0.1.252.dist-info}/RECORD +31 -29
- autocoder/auto_coder.py +36 -4
- autocoder/auto_coder_rag.py +198 -35
- autocoder/chat_auto_coder.py +58 -5
- autocoder/chat_auto_coder_lang.py +21 -3
- autocoder/common/__init__.py +2 -1
- autocoder/common/auto_coder_lang.py +11 -5
- autocoder/common/code_auto_generate.py +10 -0
- autocoder/common/code_auto_generate_diff.py +10 -0
- autocoder/common/code_auto_generate_editblock.py +22 -8
- autocoder/common/code_auto_generate_strict_diff.py +10 -0
- autocoder/common/code_modification_ranker.py +3 -3
- autocoder/common/global_cancel.py +21 -0
- autocoder/common/printer.py +4 -1
- autocoder/dispacher/actions/action.py +29 -8
- autocoder/dispacher/actions/plugins/action_regex_project.py +17 -5
- autocoder/index/filter/quick_filter.py +4 -6
- autocoder/index/index.py +17 -6
- autocoder/models.py +87 -6
- autocoder/rag/doc_filter.py +1 -3
- autocoder/rag/long_context_rag.py +7 -5
- autocoder/rag/token_limiter.py +1 -3
- autocoder/utils/auto_coder_utils/chat_stream_out.py +13 -2
- autocoder/utils/llms.py +15 -1
- autocoder/utils/thread_utils.py +201 -0
- autocoder/version.py +1 -1
- {auto_coder-0.1.250.dist-info → auto_coder-0.1.252.dist-info}/LICENSE +0 -0
- {auto_coder-0.1.250.dist-info → auto_coder-0.1.252.dist-info}/WHEEL +0 -0
- {auto_coder-0.1.250.dist-info → auto_coder-0.1.252.dist-info}/entry_points.txt +0 -0
- {auto_coder-0.1.250.dist-info → auto_coder-0.1.252.dist-info}/top_level.txt +0 -0
autocoder/chat_auto_coder.py
CHANGED
|
@@ -54,7 +54,7 @@ import shlex
|
|
|
54
54
|
from autocoder.utils.llms import get_single_llm
|
|
55
55
|
import pkg_resources
|
|
56
56
|
from autocoder.common.printer import Printer
|
|
57
|
-
from
|
|
57
|
+
from autocoder.utils.thread_utils import run_in_thread,run_in_raw_thread
|
|
58
58
|
|
|
59
59
|
class SymbolItem(BaseModel):
|
|
60
60
|
symbol_name: str
|
|
@@ -136,6 +136,8 @@ commands = [
|
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
def show_help():
|
|
139
|
+
print(f"\033[1m{get_message('official_doc')}\033[0m")
|
|
140
|
+
print()
|
|
139
141
|
print(f"\033[1m{get_message('supported_commands')}\033[0m")
|
|
140
142
|
print()
|
|
141
143
|
print(
|
|
@@ -1713,7 +1715,7 @@ def commit(query: str):
|
|
|
1713
1715
|
if os.path.exists(temp_yaml):
|
|
1714
1716
|
os.remove(temp_yaml)
|
|
1715
1717
|
|
|
1716
|
-
target_model = args.
|
|
1718
|
+
target_model = args.commit_model or args.model
|
|
1717
1719
|
llm = get_single_llm(target_model, product_mode)
|
|
1718
1720
|
printer = Printer()
|
|
1719
1721
|
printer.print_in_terminal("commit_generating", style="yellow", model_name=target_model)
|
|
@@ -2208,6 +2210,9 @@ def manage_models(params, query: str):
|
|
|
2208
2210
|
table.add_column("Name", style="cyan", width=40, no_wrap=False)
|
|
2209
2211
|
table.add_column("Model Name", style="magenta", width=30, overflow="fold")
|
|
2210
2212
|
table.add_column("Base URL", style="white", width=50, overflow="fold")
|
|
2213
|
+
table.add_column("Input Price (M)", style="magenta", width=15)
|
|
2214
|
+
table.add_column("Output Price (M)", style="magenta", width=15)
|
|
2215
|
+
table.add_column("Speed (s/req)", style="blue", width=15)
|
|
2211
2216
|
for m in models_data:
|
|
2212
2217
|
# Check if api_key_path exists and file exists
|
|
2213
2218
|
is_api_key_set = "api_key" in m
|
|
@@ -2221,12 +2226,60 @@ def manage_models(params, query: str):
|
|
|
2221
2226
|
table.add_row(
|
|
2222
2227
|
name,
|
|
2223
2228
|
m.get("model_name", ""),
|
|
2224
|
-
m.get("base_url", "")
|
|
2229
|
+
m.get("base_url", ""),
|
|
2230
|
+
f"{m.get('input_price', 0.0):.2f}",
|
|
2231
|
+
f"{m.get('output_price', 0.0):.2f}",
|
|
2232
|
+
f"{m.get('average_speed', 0.0):.3f}"
|
|
2225
2233
|
)
|
|
2226
2234
|
console.print(table)
|
|
2227
2235
|
else:
|
|
2228
2236
|
printer.print_in_terminal("models_no_models", style="yellow")
|
|
2229
2237
|
|
|
2238
|
+
elif subcmd == "/input_price":
|
|
2239
|
+
args = query.strip().split()
|
|
2240
|
+
if len(args) >= 2:
|
|
2241
|
+
name = args[0]
|
|
2242
|
+
try:
|
|
2243
|
+
price = float(args[1])
|
|
2244
|
+
if models.update_model_input_price(name, price):
|
|
2245
|
+
printer.print_in_terminal("models_input_price_updated", style="green", name=name, price=price)
|
|
2246
|
+
else:
|
|
2247
|
+
printer.print_in_terminal("models_not_found", style="red", name=name)
|
|
2248
|
+
except ValueError as e:
|
|
2249
|
+
printer.print_in_terminal("models_invalid_price", style="red", error=str(e))
|
|
2250
|
+
else:
|
|
2251
|
+
printer.print_in_terminal("models_input_price_usage", style="red")
|
|
2252
|
+
|
|
2253
|
+
elif subcmd == "/output_price":
|
|
2254
|
+
args = query.strip().split()
|
|
2255
|
+
if len(args) >= 2:
|
|
2256
|
+
name = args[0]
|
|
2257
|
+
try:
|
|
2258
|
+
price = float(args[1])
|
|
2259
|
+
if models.update_model_output_price(name, price):
|
|
2260
|
+
printer.print_in_terminal("models_output_price_updated", style="green", name=name, price=price)
|
|
2261
|
+
else:
|
|
2262
|
+
printer.print_in_terminal("models_not_found", style="red", name=name)
|
|
2263
|
+
except ValueError as e:
|
|
2264
|
+
printer.print_in_terminal("models_invalid_price", style="red", error=str(e))
|
|
2265
|
+
else:
|
|
2266
|
+
printer.print_in_terminal("models_output_price_usage", style="red")
|
|
2267
|
+
|
|
2268
|
+
elif subcmd == "/speed":
|
|
2269
|
+
args = query.strip().split()
|
|
2270
|
+
if len(args) >= 2:
|
|
2271
|
+
name = args[0]
|
|
2272
|
+
try:
|
|
2273
|
+
speed = float(args[1])
|
|
2274
|
+
if models.update_model_speed(name, speed):
|
|
2275
|
+
printer.print_in_terminal("models_speed_updated", style="green", name=name, speed=speed)
|
|
2276
|
+
else:
|
|
2277
|
+
printer.print_in_terminal("models_not_found", style="red", name=name)
|
|
2278
|
+
except ValueError as e:
|
|
2279
|
+
printer.print_in_terminal("models_invalid_speed", style="red", error=str(e))
|
|
2280
|
+
else:
|
|
2281
|
+
printer.print_in_terminal("models_speed_usage", style="red")
|
|
2282
|
+
|
|
2230
2283
|
elif subcmd == "/add":
|
|
2231
2284
|
# Support both simplified and legacy formats
|
|
2232
2285
|
args = query.strip().split(" ")
|
|
@@ -2796,8 +2849,8 @@ def main():
|
|
|
2796
2849
|
command = user_input[len("/shell"):].strip()
|
|
2797
2850
|
if not command:
|
|
2798
2851
|
print("Please enter a shell command to execute.")
|
|
2799
|
-
|
|
2800
|
-
|
|
2852
|
+
else:
|
|
2853
|
+
execute_shell_command(command)
|
|
2801
2854
|
|
|
2802
2855
|
except KeyboardInterrupt:
|
|
2803
2856
|
continue
|
|
@@ -85,7 +85,7 @@ MESSAGES = {
|
|
|
85
85
|
"design_desc": "Generate SVG image based on the provided description",
|
|
86
86
|
"commit_desc": "Auto generate yaml file and commit changes based on user's manual changes",
|
|
87
87
|
"models_desc": "Manage model configurations, only available in lite mode",
|
|
88
|
-
"models_usage": "Usage: /models /list|/add|/add_model|/remove ...",
|
|
88
|
+
"models_usage": "Usage: /models /list|/add|/add_model|/remove|/price|/speed ...",
|
|
89
89
|
"models_added": "Added/Updated model '{{name}}' successfully.",
|
|
90
90
|
"models_add_failed": "Failed to add model '{{name}}'. Model not found in defaults.",
|
|
91
91
|
"models_add_usage": "Usage: /models /add <name> <api_key> or\n/models /add <name> <model_type> <model_name> <base_url> <api_key_path> [description]",
|
|
@@ -96,6 +96,14 @@ MESSAGES = {
|
|
|
96
96
|
"models_add_model_remove": "Model '{{name}}' not found.",
|
|
97
97
|
"models_add_model_removed": "Removed model: {{name}}",
|
|
98
98
|
"models_unknown_subcmd": "Unknown subcommand: {{subcmd}}",
|
|
99
|
+
"models_input_price_updated": "Updated input price for model {{name}} to {{price}} M/token",
|
|
100
|
+
"models_output_price_updated": "Updated output price for model {{name}} to {{price}} M/token",
|
|
101
|
+
"models_invalid_price": "Invalid price value: {{error}}",
|
|
102
|
+
"models_input_price_usage": "Usage: /models /input_price <name> <value>",
|
|
103
|
+
"models_output_price_usage": "Usage: /models /output_price <name> <value>",
|
|
104
|
+
"models_speed_updated": "Updated speed for model {{name}} to {{speed}} s/request",
|
|
105
|
+
"models_invalid_speed": "Invalid speed value: {{error}}",
|
|
106
|
+
"models_speed_usage": "Usage: /models /speed <name> <value>",
|
|
99
107
|
"models_title": "All Models (内置 + models.json)",
|
|
100
108
|
"models_no_models": "No models found.",
|
|
101
109
|
"models_lite_only": "The /models command is only available in lite mode",
|
|
@@ -117,6 +125,7 @@ MESSAGES = {
|
|
|
117
125
|
"commit_message": "{{ model_name }} Generated commit message: {{ message }}",
|
|
118
126
|
"commit_failed": "{{ model_name }} Failed to generate commit message: {{ error }}",
|
|
119
127
|
"confirm_execute": "Do you want to execute this script?",
|
|
128
|
+
"official_doc": "Official Documentation: https://uelng8wukz.feishu.cn/wiki/NhPNwSRcWimKFIkQINIckloBncI",
|
|
120
129
|
},
|
|
121
130
|
"zh": {
|
|
122
131
|
"commit_generating": "{{ model_name }} 正在生成提交信息...",
|
|
@@ -204,7 +213,7 @@ MESSAGES = {
|
|
|
204
213
|
"conf_value": "值",
|
|
205
214
|
"conf_title": "配置设置",
|
|
206
215
|
"conf_subtitle": "使用 /conf <key>:<value> 修改这些设置",
|
|
207
|
-
"models_usage": "用法: /models /list|/add|/add_model|/remove ...",
|
|
216
|
+
"models_usage": "用法: /models /list|/add|/add_model|/remove|/price|/speed ...",
|
|
208
217
|
"models_added": "成功添加/更新模型 '{{name}}'。",
|
|
209
218
|
"models_add_failed": "添加模型 '{{name}}' 失败。在默认模型中未找到该模型。",
|
|
210
219
|
"models_add_usage": "用法: /models /add <name> <api_key> 或\n/models /add <name> <model_type> <model_name> <base_url> <api_key_path> [description]",
|
|
@@ -215,6 +224,14 @@ MESSAGES = {
|
|
|
215
224
|
"models_add_model_remove": "找不到模型 '{{name}}'。",
|
|
216
225
|
"models_add_model_removed": "已移除模型: {{name}}",
|
|
217
226
|
"models_unknown_subcmd": "未知的子命令: {{subcmd}}",
|
|
227
|
+
"models_input_price_updated": "已更新模型 {{name}} 的输入价格为 {{price}} M/token",
|
|
228
|
+
"models_output_price_updated": "已更新模型 {{name}} 的输出价格为 {{price}} M/token",
|
|
229
|
+
"models_invalid_price": "无效的价格值: {{error}}",
|
|
230
|
+
"models_input_price_usage": "用法: /models /input_price <name> <value>",
|
|
231
|
+
"models_output_price_usage": "用法: /models /output_price <name> <value>",
|
|
232
|
+
"models_speed_updated": "已更新模型 {{name}} 的速度为 {{speed}} 秒/请求",
|
|
233
|
+
"models_invalid_speed": "无效的速度值: {{error}}",
|
|
234
|
+
"models_speed_usage": "用法: /models /speed <name> <value>",
|
|
218
235
|
"models_title": "所有模型 (内置 + models.json)",
|
|
219
236
|
"models_no_models": "未找到任何模型。",
|
|
220
237
|
"models_lite_only": "/models 命令仅在 lite 模式下可用",
|
|
@@ -232,7 +249,8 @@ MESSAGES = {
|
|
|
232
249
|
"remove_files_none": "没有文件被移除。",
|
|
233
250
|
"files_removed": "移除的文件",
|
|
234
251
|
"models_api_key_empty": "警告: {{name}} API key 为空。请设置一个有效的 API key。",
|
|
235
|
-
"confirm_execute": "
|
|
252
|
+
"confirm_execute": "是否执行此脚本?",
|
|
253
|
+
"official_doc": "官方文档: https://uelng8wukz.feishu.cn/wiki/NhPNwSRcWimKFIkQINIckloBncI",
|
|
236
254
|
}
|
|
237
255
|
}
|
|
238
256
|
|
autocoder/common/__init__.py
CHANGED
|
@@ -254,6 +254,7 @@ class AutoCoderArgs(pydantic.BaseModel):
|
|
|
254
254
|
planner_model: Optional[str] = ""
|
|
255
255
|
voice2text_model: Optional[str] = ""
|
|
256
256
|
text2voice_model: Optional[str] = ""
|
|
257
|
+
commit_model: Optional[str] = ""
|
|
257
258
|
|
|
258
259
|
skip_build_index: Optional[bool] = False
|
|
259
260
|
skip_filter_index: Optional[bool] = False
|
|
@@ -357,7 +358,7 @@ class AutoCoderArgs(pydantic.BaseModel):
|
|
|
357
358
|
enable_global_memory: Optional[bool] = True
|
|
358
359
|
product_mode: Optional[str] = "lite"
|
|
359
360
|
|
|
360
|
-
keep_reasoning_content: Optional[bool] =
|
|
361
|
+
keep_reasoning_content: Optional[bool] = False
|
|
361
362
|
|
|
362
363
|
in_code_apply: bool = False
|
|
363
364
|
|
|
@@ -3,6 +3,7 @@ from byzerllm.utils import format_str_jinja2
|
|
|
3
3
|
|
|
4
4
|
MESSAGES = {
|
|
5
5
|
"en": {
|
|
6
|
+
"generation_cancelled": "[Interrupted] Generation cancelled",
|
|
6
7
|
"model_not_found": "Model {{model_name}} not found",
|
|
7
8
|
"generating_shell_script": "Generating Shell Script",
|
|
8
9
|
"new_session_started": "New session started. Previous chat history has been archived.",
|
|
@@ -51,7 +52,7 @@ MESSAGES = {
|
|
|
51
52
|
"Paste the answer to the input box below, use '/break' to exit, '/clear' to clear the screen, '/eof' to submit."
|
|
52
53
|
),
|
|
53
54
|
"code_generation_start": "Auto generate the code...",
|
|
54
|
-
"code_generation_complete": "Code generation completed in {{ duration }} seconds, input_tokens_count: {{ input_tokens }}, generated_tokens_count: {{ output_tokens }}",
|
|
55
|
+
"code_generation_complete": "Code generation completed in {{ duration }} seconds, input_tokens_count: {{ input_tokens }}, generated_tokens_count: {{ output_tokens }}, speed: {{ speed }} tokens/s",
|
|
55
56
|
"code_merge_start": "Auto merge the code...",
|
|
56
57
|
"code_execution_warning": "Content(send to model) is {{ content_length }} tokens (you may collect too much files), which is larger than the maximum input length {{ max_length }}",
|
|
57
58
|
"quick_filter_start": "{{ model_name }} Starting filter context(quick_filter)...",
|
|
@@ -73,7 +74,7 @@ MESSAGES = {
|
|
|
73
74
|
"ranking_process_failed": "Ranking process failed: {{ error }}",
|
|
74
75
|
"ranking_failed": "Ranking failed in {{ elapsed }}s, using original order",
|
|
75
76
|
"begin_index_source_code": "🚀 Begin to index source code in {{ source_dir }}",
|
|
76
|
-
"stream_out_stats": "Elapsed time {{ elapsed_time }} seconds, input tokens: {{ input_tokens }}, output tokens: {{ output_tokens }}",
|
|
77
|
+
"stream_out_stats": "Elapsed time {{ elapsed_time }} seconds, first token time: {{ first_token_time }} seconds, input tokens: {{ input_tokens }}, output tokens: {{ output_tokens }}, speed: {{ speed }} tokens/s",
|
|
77
78
|
"quick_filter_stats": "快速过滤器完成,耗时 {{ elapsed_time }} 秒,输入token数: {{ input_tokens }}, 输出token数: {{ output_tokens }}",
|
|
78
79
|
"upsert_file": "✅ Updated file: {{ file_path }}",
|
|
79
80
|
"unmerged_blocks_title": "Unmerged Blocks",
|
|
@@ -86,9 +87,12 @@ MESSAGES = {
|
|
|
86
87
|
"git_init_required": "⚠️ auto_merge only applies to git repositories.\n\nPlease try using git init in the source directory:\n\n```shell\ncd {{ source_dir }}\ngit init.\n```\n\nThen run auto - coder again.\nError: {{ error }}",
|
|
87
88
|
"quick_filter_reason": "Auto get(quick_filter mode)",
|
|
88
89
|
"quick_filter_too_long": "⚠️ index file is too large ({{ tokens_len }}/{{ max_tokens }}). The query will be split into {{ split_size }} chunks.",
|
|
89
|
-
"quick_filter_tokens_len": "📊 Current index size: {{ tokens_len }} tokens"
|
|
90
|
+
"quick_filter_tokens_len": "📊 Current index size: {{ tokens_len }} tokens",
|
|
91
|
+
"estimated_chat_input_tokens": "Estimated chat input tokens: {{ estimated_input_tokens }}",
|
|
92
|
+
"estimated_input_tokens_in_generate": "Estimated input tokens in generate ({{ generate_mode }}): {{ estimated_input_tokens }}",
|
|
90
93
|
},
|
|
91
94
|
"zh": {
|
|
95
|
+
"generation_cancelled": "[已中断] 生成已取消",
|
|
92
96
|
"model_not_found": "未找到模型: {{model_name}}",
|
|
93
97
|
"generating_shell_script": "正在生成 Shell 脚本",
|
|
94
98
|
"new_session_started": "新会话已开始。之前的聊天历史已存档。",
|
|
@@ -137,7 +141,7 @@ MESSAGES = {
|
|
|
137
141
|
"将获得答案黏贴到下面的输入框,换行后,使用 '/break' 退出,'/clear' 清屏,'/eof' 提交。"
|
|
138
142
|
),
|
|
139
143
|
"code_generation_start": "正在自动生成代码...",
|
|
140
|
-
"code_generation_complete": "代码生成完成,耗时 {{ duration }} 秒,输入token数: {{ input_tokens }}, 输出token数: {{ output_tokens }}",
|
|
144
|
+
"code_generation_complete": "代码生成完成,耗时 {{ duration }} 秒,输入token数: {{ input_tokens }}, 输出token数: {{ output_tokens }}, 速度: {{ speed }} tokens/秒",
|
|
141
145
|
"code_merge_start": "正在自动合并代码...",
|
|
142
146
|
"code_execution_warning": "发送给模型的内容长度为 {{ content_length }} tokens(您可能收集了太多文件),超过了最大输入长度 {{ max_length }}",
|
|
143
147
|
"quick_filter_start": "{{ model_name }} 开始查找上下文(quick_filter)...",
|
|
@@ -169,10 +173,12 @@ MESSAGES = {
|
|
|
169
173
|
"ranking_complete": "排序完成,耗时 {{ elapsed }} 秒,总投票数: {{ total_tasks }},最佳候选索引: {{ best_candidate }},得分: {{ scores }},输入token数: {{ input_tokens }},输出token数: {{ output_tokens }}",
|
|
170
174
|
"ranking_process_failed": "排序过程失败: {{ error }}",
|
|
171
175
|
"ranking_failed": "排序失败,耗时 {{ elapsed }} 秒,使用原始顺序",
|
|
172
|
-
"stream_out_stats": "
|
|
176
|
+
"stream_out_stats": "总耗时 {{ elapsed_time }} 秒,首token时间: {{ first_token_time }} 秒,输入token数: {{ input_tokens }}, 输出token数: {{ output_tokens }}, 速度: {{ speed }} tokens/秒",
|
|
173
177
|
"quick_filter_stats": "Quick filter completed in {{ elapsed_time }} seconds, input tokens: {{ input_tokens }}, output tokens: {{ output_tokens }}",
|
|
174
178
|
"quick_filter_title": "{{ model_name }} 正在分析如何筛选上下文...",
|
|
175
179
|
"quick_filter_failed": "❌ 快速过滤器失败: {{ error }}. ",
|
|
180
|
+
"estimated_chat_input_tokens": "对话输入token预估为: {{ estimated_input_tokens }}",
|
|
181
|
+
"estimated_input_tokens_in_generate": "生成代码({{ generate_mode }})预计输入token数: {{ estimated_input_tokens_in_generate }}",
|
|
176
182
|
},
|
|
177
183
|
}
|
|
178
184
|
|
|
@@ -8,6 +8,8 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
8
8
|
from autocoder.common.types import CodeGenerateResult
|
|
9
9
|
from autocoder.common.utils_code_auto_generate import chat_with_continue
|
|
10
10
|
import json
|
|
11
|
+
from autocoder.common.printer import Printer
|
|
12
|
+
from autocoder.rag.token_counter import count_tokens
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
class CodeAutoGenerate:
|
|
@@ -191,6 +193,14 @@ class CodeAutoGenerate:
|
|
|
191
193
|
results = []
|
|
192
194
|
input_tokens_count = 0
|
|
193
195
|
generated_tokens_count = 0
|
|
196
|
+
|
|
197
|
+
printer = Printer()
|
|
198
|
+
estimated_input_tokens = count_tokens(json.dumps(conversations, ensure_ascii=False))
|
|
199
|
+
printer.print_in_terminal("estimated_input_tokens_in_generate", style="yellow",
|
|
200
|
+
estimated_input_tokens_in_generate=estimated_input_tokens,
|
|
201
|
+
generate_mode="wholefile"
|
|
202
|
+
)
|
|
203
|
+
|
|
194
204
|
if not self.args.human_as_model:
|
|
195
205
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
196
206
|
futures = []
|
|
@@ -7,6 +7,8 @@ from autocoder.common import sys_prompt
|
|
|
7
7
|
from concurrent.futures import ThreadPoolExecutor
|
|
8
8
|
import json
|
|
9
9
|
from autocoder.common.utils_code_auto_generate import chat_with_continue
|
|
10
|
+
from autocoder.common.printer import Printer
|
|
11
|
+
from autocoder.rag.token_counter import count_tokens
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
class CodeAutoGenerateDiff:
|
|
@@ -339,6 +341,14 @@ class CodeAutoGenerateDiff:
|
|
|
339
341
|
results = []
|
|
340
342
|
input_tokens_count = 0
|
|
341
343
|
generated_tokens_count = 0
|
|
344
|
+
|
|
345
|
+
printer = Printer()
|
|
346
|
+
estimated_input_tokens = count_tokens(json.dumps(conversations, ensure_ascii=False))
|
|
347
|
+
printer.print_in_terminal("estimated_input_tokens_in_generate", style="yellow",
|
|
348
|
+
estimated_input_tokens_in_generate=estimated_input_tokens,
|
|
349
|
+
generate_mode="diff"
|
|
350
|
+
)
|
|
351
|
+
|
|
342
352
|
if not self.args.human_as_model:
|
|
343
353
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
344
354
|
futures = []
|
|
@@ -11,6 +11,8 @@ from autocoder.utils.queue_communicate import (
|
|
|
11
11
|
import json
|
|
12
12
|
from concurrent.futures import ThreadPoolExecutor
|
|
13
13
|
from autocoder.common.utils_code_auto_generate import chat_with_continue
|
|
14
|
+
from autocoder.common.printer import Printer
|
|
15
|
+
from autocoder.rag.token_counter import count_tokens
|
|
14
16
|
|
|
15
17
|
|
|
16
18
|
class CodeAutoGenerateEditBlock:
|
|
@@ -421,35 +423,47 @@ class CodeAutoGenerateEditBlock:
|
|
|
421
423
|
results = []
|
|
422
424
|
input_tokens_count = 0
|
|
423
425
|
generated_tokens_count = 0
|
|
426
|
+
|
|
427
|
+
printer = Printer()
|
|
428
|
+
estimated_input_tokens = count_tokens(
|
|
429
|
+
json.dumps(conversations, ensure_ascii=False))
|
|
430
|
+
printer.print_in_terminal("estimated_input_tokens_in_generate",
|
|
431
|
+
style="yellow",
|
|
432
|
+
estimated_input_tokens_in_generate=estimated_input_tokens,
|
|
433
|
+
generate_mode="editblock"
|
|
434
|
+
)
|
|
435
|
+
|
|
424
436
|
if not self.args.human_as_model:
|
|
425
437
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
426
438
|
futures = []
|
|
427
439
|
for llm in self.llms:
|
|
428
440
|
for _ in range(self.generate_times_same_model):
|
|
429
441
|
futures.append(executor.submit(
|
|
430
|
-
chat_with_continue,llm=llm, conversations=conversations, llm_config=llm_config))
|
|
442
|
+
chat_with_continue, llm=llm, conversations=conversations, llm_config=llm_config))
|
|
431
443
|
temp_results = [future.result() for future in futures]
|
|
432
444
|
for result in temp_results:
|
|
433
445
|
results.append(result.content)
|
|
434
446
|
input_tokens_count += result.input_tokens_count
|
|
435
447
|
generated_tokens_count += result.generated_tokens_count
|
|
436
|
-
|
|
448
|
+
|
|
437
449
|
for result in results:
|
|
438
450
|
conversations_list.append(
|
|
439
451
|
conversations + [{"role": "assistant", "content": result}])
|
|
440
|
-
else:
|
|
452
|
+
else:
|
|
441
453
|
for _ in range(self.args.human_model_num):
|
|
442
|
-
single_result = chat_with_continue(
|
|
454
|
+
single_result = chat_with_continue(
|
|
455
|
+
llm=self.llms[0], conversations=conversations, llm_config=llm_config)
|
|
443
456
|
results.append(single_result.content)
|
|
444
457
|
input_tokens_count += single_result.input_tokens_count
|
|
445
458
|
generated_tokens_count += single_result.generated_tokens_count
|
|
446
|
-
conversations_list.append(
|
|
447
|
-
|
|
459
|
+
conversations_list.append(
|
|
460
|
+
conversations + [{"role": "assistant", "content": single_result.content}])
|
|
461
|
+
|
|
448
462
|
statistics = {
|
|
449
463
|
"input_tokens_count": input_tokens_count,
|
|
450
464
|
"generated_tokens_count": generated_tokens_count
|
|
451
|
-
}
|
|
452
|
-
|
|
465
|
+
}
|
|
466
|
+
|
|
453
467
|
if self.args.request_id and not self.args.skip_events:
|
|
454
468
|
_ = queue_communicate.send_event(
|
|
455
469
|
request_id=self.args.request_id,
|
|
@@ -7,6 +7,8 @@ from autocoder.common import sys_prompt
|
|
|
7
7
|
from concurrent.futures import ThreadPoolExecutor
|
|
8
8
|
import json
|
|
9
9
|
from autocoder.common.utils_code_auto_generate import chat_with_continue
|
|
10
|
+
from autocoder.common.printer import Printer
|
|
11
|
+
from autocoder.rag.token_counter import count_tokens
|
|
10
12
|
|
|
11
13
|
class CodeAutoGenerateStrictDiff:
|
|
12
14
|
def __init__(
|
|
@@ -309,6 +311,14 @@ class CodeAutoGenerateStrictDiff:
|
|
|
309
311
|
results = []
|
|
310
312
|
input_tokens_count = 0
|
|
311
313
|
generated_tokens_count = 0
|
|
314
|
+
|
|
315
|
+
printer = Printer()
|
|
316
|
+
estimated_input_tokens = count_tokens(json.dumps(conversations, ensure_ascii=False))
|
|
317
|
+
printer.print_in_terminal("estimated_input_tokens_in_generate", style="yellow",
|
|
318
|
+
estimated_input_tokens_in_generate=estimated_input_tokens,
|
|
319
|
+
generate_mode="strict_diff"
|
|
320
|
+
)
|
|
321
|
+
|
|
312
322
|
if not self.args.human_as_model:
|
|
313
323
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
314
324
|
futures = []
|
|
@@ -8,6 +8,8 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
8
8
|
import traceback
|
|
9
9
|
from autocoder.common.utils_code_auto_generate import chat_with_continue
|
|
10
10
|
from byzerllm.utils.str2model import to_model
|
|
11
|
+
|
|
12
|
+
from autocoder.utils.llms import get_llm_names
|
|
11
13
|
class RankResult(BaseModel):
|
|
12
14
|
rank_result: List[int]
|
|
13
15
|
|
|
@@ -78,9 +80,7 @@ class CodeModificationRanker:
|
|
|
78
80
|
# Submit tasks for each model and generate_times
|
|
79
81
|
futures = []
|
|
80
82
|
for llm in self.llms:
|
|
81
|
-
model_name =
|
|
82
|
-
if not model_name:
|
|
83
|
-
model_name = "unknown(without default model name)"
|
|
83
|
+
model_name = ",".join(get_llm_names(llm))
|
|
84
84
|
self.printer.print_in_terminal(
|
|
85
85
|
"ranking_start", style="blue", count=len(generate_result.contents), model_name=model_name)
|
|
86
86
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
|
|
3
|
+
class GlobalCancel:
|
|
4
|
+
def __init__(self):
|
|
5
|
+
self._flag = False
|
|
6
|
+
self._lock = threading.Lock()
|
|
7
|
+
|
|
8
|
+
@property
|
|
9
|
+
def requested(self):
|
|
10
|
+
with self._lock:
|
|
11
|
+
return self._flag
|
|
12
|
+
|
|
13
|
+
def set(self):
|
|
14
|
+
with self._lock:
|
|
15
|
+
self._flag = True
|
|
16
|
+
|
|
17
|
+
def reset(self):
|
|
18
|
+
with self._lock:
|
|
19
|
+
self._flag = False
|
|
20
|
+
|
|
21
|
+
global_cancel = GlobalCancel()
|
autocoder/common/printer.py
CHANGED
|
@@ -32,7 +32,10 @@ class Printer:
|
|
|
32
32
|
else:
|
|
33
33
|
self.console.print(format_str_jinja2(self.get_message_from_key(msg_key),**kwargs))
|
|
34
34
|
except Exception as e:
|
|
35
|
-
|
|
35
|
+
try:
|
|
36
|
+
print(self.get_message_from_key(msg_key))
|
|
37
|
+
except Exception as e:
|
|
38
|
+
print(f"text key: {msg_key} not found")
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
def print_str_in_terminal(self, content: str, style: str = None):
|
|
@@ -26,6 +26,7 @@ from autocoder.utils.conversation_store import store_code_model_conversation
|
|
|
26
26
|
from loguru import logger
|
|
27
27
|
import time
|
|
28
28
|
from autocoder.common.printer import Printer
|
|
29
|
+
from autocoder.utils.llms import get_llm_names
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
class BaseAction:
|
|
@@ -123,11 +124,16 @@ class ActionTSProject(BaseAction):
|
|
|
123
124
|
generate_result = generate.single_round_run(
|
|
124
125
|
query=args.query, source_content=content
|
|
125
126
|
)
|
|
127
|
+
elapsed_time = time.time() - start_time
|
|
128
|
+
speed = generate_result.metadata.get('generated_tokens_count', 0) / elapsed_time if elapsed_time > 0 else 0
|
|
129
|
+
model_names = ",".join(get_llm_names(self.llm))
|
|
126
130
|
self.printer.print_in_terminal(
|
|
127
131
|
"code_generation_complete",
|
|
128
|
-
duration=
|
|
132
|
+
duration=elapsed_time,
|
|
129
133
|
input_tokens=generate_result.metadata.get('input_tokens_count', 0),
|
|
130
|
-
output_tokens=generate_result.metadata.get('generated_tokens_count', 0)
|
|
134
|
+
output_tokens=generate_result.metadata.get('generated_tokens_count', 0),
|
|
135
|
+
speed=round(speed, 2),
|
|
136
|
+
model_names=model_names
|
|
131
137
|
)
|
|
132
138
|
merge_result = None
|
|
133
139
|
if args.execute and args.auto_merge:
|
|
@@ -213,11 +219,16 @@ class ActionPyScriptProject(BaseAction):
|
|
|
213
219
|
query=args.query, source_content=content
|
|
214
220
|
)
|
|
215
221
|
|
|
222
|
+
elapsed_time = time.time() - start_time
|
|
223
|
+
speed = generate_result.metadata.get('generated_tokens_count', 0) / elapsed_time if elapsed_time > 0 else 0
|
|
224
|
+
model_names = ",".join(get_llm_names(self.llm))
|
|
216
225
|
self.printer.print_in_terminal(
|
|
217
226
|
"code_generation_complete",
|
|
218
|
-
duration=
|
|
227
|
+
duration=elapsed_time,
|
|
219
228
|
input_tokens=generate_result.metadata.get('input_tokens_count', 0),
|
|
220
|
-
output_tokens=generate_result.metadata.get('generated_tokens_count', 0)
|
|
229
|
+
output_tokens=generate_result.metadata.get('generated_tokens_count', 0),
|
|
230
|
+
speed=round(speed, 2),
|
|
231
|
+
model_names=model_names
|
|
221
232
|
)
|
|
222
233
|
merge_result = None
|
|
223
234
|
if args.execute and args.auto_merge:
|
|
@@ -335,11 +346,16 @@ class ActionPyProject(BaseAction):
|
|
|
335
346
|
generate_result = generate.single_round_run(
|
|
336
347
|
query=args.query, source_content=content
|
|
337
348
|
)
|
|
349
|
+
elapsed_time = time.time() - start_time
|
|
350
|
+
speed = generate_result.metadata.get('generated_tokens_count', 0) / elapsed_time if elapsed_time > 0 else 0
|
|
351
|
+
model_names = ",".join(get_llm_names(self.llm))
|
|
338
352
|
self.printer.print_in_terminal(
|
|
339
353
|
"code_generation_complete",
|
|
340
|
-
duration=
|
|
354
|
+
duration=elapsed_time,
|
|
341
355
|
input_tokens=generate_result.metadata.get('input_tokens_count', 0),
|
|
342
|
-
output_tokens=generate_result.metadata.get('generated_tokens_count', 0)
|
|
356
|
+
output_tokens=generate_result.metadata.get('generated_tokens_count', 0),
|
|
357
|
+
speed=round(speed, 2),
|
|
358
|
+
model_names=model_names
|
|
343
359
|
)
|
|
344
360
|
merge_result = None
|
|
345
361
|
if args.execute and args.auto_merge:
|
|
@@ -440,11 +456,16 @@ class ActionSuffixProject(BaseAction):
|
|
|
440
456
|
query=args.query, source_content=content
|
|
441
457
|
)
|
|
442
458
|
|
|
459
|
+
elapsed_time = time.time() - start_time
|
|
460
|
+
speed = generate_result.metadata.get('generated_tokens_count', 0) / elapsed_time if elapsed_time > 0 else 0
|
|
461
|
+
model_names = ",".join(get_llm_names(self.llm))
|
|
443
462
|
self.printer.print_in_terminal(
|
|
444
463
|
"code_generation_complete",
|
|
445
|
-
duration=
|
|
464
|
+
duration=elapsed_time,
|
|
446
465
|
input_tokens=generate_result.metadata.get('input_tokens_count', 0),
|
|
447
|
-
output_tokens=generate_result.metadata.get('generated_tokens_count', 0)
|
|
466
|
+
output_tokens=generate_result.metadata.get('generated_tokens_count', 0),
|
|
467
|
+
speed=round(speed, 2),
|
|
468
|
+
model_names=model_names
|
|
448
469
|
)
|
|
449
470
|
merge_result = None
|
|
450
471
|
if args.execute and args.auto_merge:
|
|
@@ -12,9 +12,10 @@ from autocoder.common.code_auto_generate_editblock import CodeAutoGenerateEditBl
|
|
|
12
12
|
from autocoder.index.entry import build_index_and_filter_files
|
|
13
13
|
from autocoder.regexproject import RegexProject
|
|
14
14
|
from autocoder.utils.conversation_store import store_code_model_conversation
|
|
15
|
-
from
|
|
15
|
+
from autocoder.common.printer import Printer
|
|
16
16
|
import time
|
|
17
|
-
|
|
17
|
+
from autocoder.utils.llms import get_llm_names
|
|
18
|
+
from loguru import logger
|
|
18
19
|
class ActionRegexProject:
|
|
19
20
|
def __init__(
|
|
20
21
|
self, args: AutoCoderArgs, llm: Optional[byzerllm.ByzerLLM] = None
|
|
@@ -22,6 +23,7 @@ class ActionRegexProject:
|
|
|
22
23
|
self.args = args
|
|
23
24
|
self.llm = llm
|
|
24
25
|
self.pp = None
|
|
26
|
+
self.printer = Printer()
|
|
25
27
|
|
|
26
28
|
def run(self):
|
|
27
29
|
args = self.args
|
|
@@ -58,7 +60,7 @@ class ActionRegexProject:
|
|
|
58
60
|
|
|
59
61
|
start_time = time.time()
|
|
60
62
|
if args.execute:
|
|
61
|
-
|
|
63
|
+
self.printer.print_in_terminal("code_generation_start")
|
|
62
64
|
|
|
63
65
|
if args.auto_merge == "diff":
|
|
64
66
|
generate = CodeAutoGenerateDiff(
|
|
@@ -83,10 +85,20 @@ class ActionRegexProject:
|
|
|
83
85
|
query=args.query, source_content=content
|
|
84
86
|
)
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
elapsed_time = time.time() - start_time
|
|
89
|
+
speed = generate_result.metadata.get('generated_tokens_count', 0) / elapsed_time if elapsed_time > 0 else 0
|
|
90
|
+
model_names = ",".join(get_llm_names(self.llm))
|
|
91
|
+
self.printer.print_in_terminal(
|
|
92
|
+
"code_generation_complete",
|
|
93
|
+
duration=elapsed_time,
|
|
94
|
+
input_tokens=generate_result.metadata.get('input_tokens_count', 0),
|
|
95
|
+
output_tokens=generate_result.metadata.get('generated_tokens_count', 0),
|
|
96
|
+
speed=round(speed, 2),
|
|
97
|
+
model_names=model_names
|
|
98
|
+
)
|
|
87
99
|
merge_result = None
|
|
88
100
|
if args.execute and args.auto_merge:
|
|
89
|
-
|
|
101
|
+
self.printer.print_in_terminal("code_merge_start")
|
|
90
102
|
if args.auto_merge == "diff":
|
|
91
103
|
code_merge = CodeAutoMergeDiff(llm=self.llm, args=self.args)
|
|
92
104
|
merge_result = code_merge.merge_code(generate_result=generate_result)
|
|
@@ -17,6 +17,8 @@ from autocoder.common.printer import Printer
|
|
|
17
17
|
from concurrent.futures import ThreadPoolExecutor
|
|
18
18
|
import threading
|
|
19
19
|
|
|
20
|
+
from autocoder.utils.llms import get_llm_names
|
|
21
|
+
|
|
20
22
|
|
|
21
23
|
def get_file_path(file_path):
|
|
22
24
|
if file_path.startswith("##"):
|
|
@@ -70,9 +72,7 @@ class QuickFilter():
|
|
|
70
72
|
|
|
71
73
|
def process_chunk(chunk_index: int, chunk: List[IndexItem]) -> None:
|
|
72
74
|
try:
|
|
73
|
-
model_name =
|
|
74
|
-
if not model_name:
|
|
75
|
-
model_name = "unknown(without default model name)"
|
|
75
|
+
model_name = ",".join(get_llm_names(self.index_manager.index_filter_llm))
|
|
76
76
|
|
|
77
77
|
if chunk_index == 0:
|
|
78
78
|
# 第一个chunk使用流式输出
|
|
@@ -180,9 +180,7 @@ class QuickFilter():
|
|
|
180
180
|
return self.big_filter(index_items)
|
|
181
181
|
|
|
182
182
|
try:
|
|
183
|
-
model_name =
|
|
184
|
-
if not model_name:
|
|
185
|
-
model_name = "unknown(without default model name)"
|
|
183
|
+
model_name = ",".join(get_llm_names(self.index_manager.index_filter_llm))
|
|
186
184
|
|
|
187
185
|
# 渲染 Prompt 模板
|
|
188
186
|
query = self.quick_filter_files.prompt(index_items, self.args.query)
|