auto-coder 0.1.305__py3-none-any.whl → 0.1.307__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.305.dist-info → auto_coder-0.1.307.dist-info}/METADATA +1 -1
- {auto_coder-0.1.305.dist-info → auto_coder-0.1.307.dist-info}/RECORD +43 -38
- autocoder/agent/auto_demand_organizer.py +13 -20
- autocoder/agent/auto_filegroup.py +10 -16
- autocoder/agent/auto_learn_from_commit.py +25 -33
- autocoder/agent/auto_review_commit.py +15 -64
- autocoder/auto_coder.py +6 -8
- autocoder/auto_coder_runner.py +153 -8
- autocoder/chat_auto_coder.py +9 -1
- autocoder/chat_auto_coder_lang.py +552 -278
- autocoder/commands/auto_command.py +31 -7
- autocoder/common/__init__.py +6 -0
- autocoder/common/action_yml_file_manager.py +75 -37
- autocoder/common/auto_coder_lang.py +737 -401
- autocoder/common/code_auto_generate.py +104 -16
- autocoder/common/code_auto_generate_diff.py +101 -10
- autocoder/common/code_auto_generate_editblock.py +103 -9
- autocoder/common/code_auto_generate_strict_diff.py +99 -9
- autocoder/common/code_auto_merge.py +8 -0
- autocoder/common/code_auto_merge_diff.py +8 -0
- autocoder/common/code_auto_merge_editblock.py +7 -0
- autocoder/common/code_auto_merge_strict_diff.py +5 -0
- autocoder/common/code_modification_ranker.py +9 -3
- autocoder/common/command_completer.py +12 -0
- autocoder/common/command_generator.py +5 -4
- autocoder/common/git_utils.py +86 -63
- autocoder/common/stream_out_type.py +8 -1
- autocoder/common/utils_code_auto_generate.py +29 -3
- autocoder/dispacher/__init__.py +18 -19
- autocoder/dispacher/actions/action.py +0 -132
- autocoder/index/filter/quick_filter.py +6 -3
- autocoder/memory/__init__.py +7 -0
- autocoder/memory/active_context_manager.py +649 -0
- autocoder/memory/active_package.py +469 -0
- autocoder/memory/async_processor.py +161 -0
- autocoder/memory/directory_mapper.py +67 -0
- autocoder/utils/auto_coder_utils/chat_stream_out.py +5 -0
- autocoder/utils/project_structure.py +35 -1
- autocoder/version.py +1 -1
- {auto_coder-0.1.305.dist-info → auto_coder-0.1.307.dist-info}/LICENSE +0 -0
- {auto_coder-0.1.305.dist-info → auto_coder-0.1.307.dist-info}/WHEEL +0 -0
- {auto_coder-0.1.305.dist-info → auto_coder-0.1.307.dist-info}/entry_points.txt +0 -0
- {auto_coder-0.1.305.dist-info → auto_coder-0.1.307.dist-info}/top_level.txt +0 -0
|
@@ -6,13 +6,17 @@ from autocoder.utils.queue_communicate import queue_communicate, CommunicateEven
|
|
|
6
6
|
from autocoder.common import sys_prompt
|
|
7
7
|
from concurrent.futures import ThreadPoolExecutor
|
|
8
8
|
from autocoder.common.types import CodeGenerateResult
|
|
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,ChatWithContinueResult
|
|
10
|
+
from autocoder.utils.auto_coder_utils.chat_stream_out import stream_out
|
|
11
|
+
from autocoder.common.stream_out_type import CodeGenerateStreamOutType
|
|
12
|
+
from autocoder.common.auto_coder_lang import get_message_with_format
|
|
10
13
|
import json
|
|
11
14
|
from autocoder.common.printer import Printer
|
|
12
15
|
from autocoder.rag.token_counter import count_tokens
|
|
13
16
|
from autocoder.utils import llms as llm_utils
|
|
14
17
|
from autocoder.common import SourceCodeList
|
|
15
18
|
from autocoder.privacy.model_filter import ModelPathFilter
|
|
19
|
+
from autocoder.memory.active_context_manager import ActiveContextManager
|
|
16
20
|
|
|
17
21
|
|
|
18
22
|
class CodeAutoGenerate:
|
|
@@ -50,7 +54,7 @@ class CodeAutoGenerate:
|
|
|
50
54
|
|
|
51
55
|
@byzerllm.prompt(llm=lambda self: self.llm)
|
|
52
56
|
def multi_round_instruction(
|
|
53
|
-
self, instruction: str, content: str, context: str = ""
|
|
57
|
+
self, instruction: str, content: str, context: str = "", package_context: str = ""
|
|
54
58
|
) -> str:
|
|
55
59
|
"""
|
|
56
60
|
{%- if structure %}
|
|
@@ -64,6 +68,13 @@ class CodeAutoGenerate:
|
|
|
64
68
|
</files>
|
|
65
69
|
{%- endif %}
|
|
66
70
|
|
|
71
|
+
{%- if package_context %}
|
|
72
|
+
下面是上面文件的一些信息(包括最近的变更情况):
|
|
73
|
+
<package_context>
|
|
74
|
+
{{ package_context }}
|
|
75
|
+
</package_context>
|
|
76
|
+
{%- endif %}
|
|
77
|
+
|
|
67
78
|
{%- if context %}
|
|
68
79
|
<extra_context>
|
|
69
80
|
{{ context }}
|
|
@@ -106,7 +117,7 @@ class CodeAutoGenerate:
|
|
|
106
117
|
|
|
107
118
|
@byzerllm.prompt(llm=lambda self: self.llm)
|
|
108
119
|
def single_round_instruction(
|
|
109
|
-
self, instruction: str, content: str, context: str = ""
|
|
120
|
+
self, instruction: str, content: str, context: str = "", package_context: str = ""
|
|
110
121
|
) -> str:
|
|
111
122
|
"""
|
|
112
123
|
{%- if structure %}
|
|
@@ -119,6 +130,13 @@ class CodeAutoGenerate:
|
|
|
119
130
|
{{ content }}
|
|
120
131
|
{%- endif %}
|
|
121
132
|
|
|
133
|
+
{%- if package_context %}
|
|
134
|
+
下面是上面文件的一些信息(包括最近的变更情况):
|
|
135
|
+
<package_context>
|
|
136
|
+
{{ package_context }}
|
|
137
|
+
</package_context>
|
|
138
|
+
{%- endif %}
|
|
139
|
+
|
|
122
140
|
{%- if context %}
|
|
123
141
|
{{ context }}
|
|
124
142
|
{%- endif %}
|
|
@@ -188,9 +206,28 @@ class CodeAutoGenerate:
|
|
|
188
206
|
),
|
|
189
207
|
)
|
|
190
208
|
|
|
209
|
+
# 获取包上下文信息
|
|
210
|
+
package_context = ""
|
|
211
|
+
|
|
212
|
+
if self.args.enable_active_context:
|
|
213
|
+
# 初始化活动上下文管理器
|
|
214
|
+
active_context_manager = ActiveContextManager(self.llm, self.args.source_dir)
|
|
215
|
+
# 获取活动上下文信息
|
|
216
|
+
result = active_context_manager.load_active_contexts_for_files(
|
|
217
|
+
[source.module_name for source in source_code_list.sources]
|
|
218
|
+
)
|
|
219
|
+
# 将活动上下文信息格式化为文本
|
|
220
|
+
if result.contexts:
|
|
221
|
+
package_context_parts = []
|
|
222
|
+
for dir_path, context in result.contexts.items():
|
|
223
|
+
package_context_parts.append(f"<package_info>{context.content}</package_info>")
|
|
224
|
+
|
|
225
|
+
package_context = "\n".join(package_context_parts)
|
|
226
|
+
|
|
191
227
|
if self.args.template == "common":
|
|
192
228
|
init_prompt = self.single_round_instruction.prompt(
|
|
193
|
-
instruction=query, content=source_content, context=self.args.context
|
|
229
|
+
instruction=query, content=source_content, context=self.args.context,
|
|
230
|
+
package_context=package_context
|
|
194
231
|
)
|
|
195
232
|
elif self.args.template == "auto_implement":
|
|
196
233
|
init_prompt = self.auto_implement_function.prompt(
|
|
@@ -228,17 +265,44 @@ class CodeAutoGenerate:
|
|
|
228
265
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
229
266
|
futures = []
|
|
230
267
|
for llm in self.llms:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
model_name =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
268
|
+
model_names_list = llm_utils.get_llm_names(llm)
|
|
269
|
+
model_name = None
|
|
270
|
+
if model_names_list:
|
|
271
|
+
model_name = model_names_list[0]
|
|
272
|
+
|
|
273
|
+
for i in range(self.generate_times_same_model):
|
|
274
|
+
model_names.append(model_name)
|
|
275
|
+
if i==0:
|
|
276
|
+
def job():
|
|
277
|
+
stream_generator = stream_chat_with_continue(
|
|
278
|
+
llm=llm,
|
|
279
|
+
conversations=conversations,
|
|
280
|
+
llm_config=llm_config,
|
|
281
|
+
args=self.args
|
|
282
|
+
)
|
|
283
|
+
full_response, last_meta = stream_out(
|
|
284
|
+
stream_generator,
|
|
285
|
+
model_name=model_name,
|
|
286
|
+
title=get_message_with_format(
|
|
287
|
+
"code_generate_title", model_name=model_name),
|
|
288
|
+
args=self.args,
|
|
289
|
+
extra_meta={
|
|
290
|
+
"stream_out_type": CodeGenerateStreamOutType.CODE_GENERATE.value
|
|
291
|
+
})
|
|
292
|
+
return ChatWithContinueResult(
|
|
293
|
+
content=full_response,
|
|
294
|
+
input_tokens_count=last_meta.input_tokens_count,
|
|
295
|
+
generated_tokens_count=last_meta.generated_tokens_count
|
|
296
|
+
)
|
|
297
|
+
futures.append(executor.submit(job))
|
|
298
|
+
else:
|
|
240
299
|
futures.append(executor.submit(
|
|
241
|
-
chat_with_continue,
|
|
300
|
+
chat_with_continue,
|
|
301
|
+
llm=llm,
|
|
302
|
+
conversations=conversations,
|
|
303
|
+
llm_config=llm_config,
|
|
304
|
+
args=self.args
|
|
305
|
+
))
|
|
242
306
|
|
|
243
307
|
temp_results = [future.result() for future in futures]
|
|
244
308
|
for result in temp_results:
|
|
@@ -256,7 +320,12 @@ class CodeAutoGenerate:
|
|
|
256
320
|
conversations + [{"role": "assistant", "content": result}])
|
|
257
321
|
else:
|
|
258
322
|
for _ in range(self.args.human_model_num):
|
|
259
|
-
single_result = chat_with_continue(
|
|
323
|
+
single_result = chat_with_continue(
|
|
324
|
+
llm=self.llms[0],
|
|
325
|
+
conversations=conversations,
|
|
326
|
+
llm_config=llm_config,
|
|
327
|
+
args=self.args
|
|
328
|
+
)
|
|
260
329
|
results.append(single_result.content)
|
|
261
330
|
input_tokens_count += single_result.input_tokens_count
|
|
262
331
|
generated_tokens_count += single_result.generated_tokens_count
|
|
@@ -287,9 +356,28 @@ class CodeAutoGenerate:
|
|
|
287
356
|
result = []
|
|
288
357
|
source_content = source_code_list.to_str()
|
|
289
358
|
|
|
359
|
+
# 获取包上下文信息
|
|
360
|
+
package_context = ""
|
|
361
|
+
|
|
362
|
+
if self.args.enable_active_context:
|
|
363
|
+
# 初始化活动上下文管理器
|
|
364
|
+
active_context_manager = ActiveContextManager(self.llm, self.args.source_dir)
|
|
365
|
+
# 获取活动上下文信息
|
|
366
|
+
result = active_context_manager.load_active_contexts_for_files(
|
|
367
|
+
[source.module_name for source in source_code_list.sources]
|
|
368
|
+
)
|
|
369
|
+
# 将活动上下文信息格式化为文本
|
|
370
|
+
if result.contexts:
|
|
371
|
+
package_context_parts = []
|
|
372
|
+
for dir_path, context in result.contexts.items():
|
|
373
|
+
package_context_parts.append(f"<package_info>{context.content}</package_info>")
|
|
374
|
+
|
|
375
|
+
package_context = "\n".join(package_context_parts)
|
|
376
|
+
|
|
290
377
|
if self.args.template == "common":
|
|
291
378
|
init_prompt = self.multi_round_instruction.prompt(
|
|
292
|
-
instruction=query, content=source_content, context=self.args.context
|
|
379
|
+
instruction=query, content=source_content, context=self.args.context,
|
|
380
|
+
package_context=package_context
|
|
293
381
|
)
|
|
294
382
|
elif self.args.template == "auto_implement":
|
|
295
383
|
init_prompt = self.auto_implement_function.prompt(
|
|
@@ -7,11 +7,15 @@ from autocoder.utils.queue_communicate import queue_communicate, CommunicateEven
|
|
|
7
7
|
from autocoder.common import sys_prompt
|
|
8
8
|
from concurrent.futures import ThreadPoolExecutor
|
|
9
9
|
import json
|
|
10
|
-
from autocoder.common.utils_code_auto_generate import chat_with_continue
|
|
10
|
+
from autocoder.common.utils_code_auto_generate import chat_with_continue,stream_chat_with_continue,ChatWithContinueResult
|
|
11
|
+
from autocoder.utils.auto_coder_utils.chat_stream_out import stream_out
|
|
12
|
+
from autocoder.common.stream_out_type import CodeGenerateStreamOutType
|
|
13
|
+
from autocoder.common.auto_coder_lang import get_message_with_format
|
|
11
14
|
from autocoder.common.printer import Printer
|
|
12
15
|
from autocoder.rag.token_counter import count_tokens
|
|
13
16
|
from autocoder.utils import llms as llm_utils
|
|
14
17
|
from autocoder.common import SourceCodeList
|
|
18
|
+
from autocoder.memory.active_context_manager import ActiveContextManager
|
|
15
19
|
|
|
16
20
|
class CodeAutoGenerateDiff:
|
|
17
21
|
def __init__(
|
|
@@ -32,7 +36,7 @@ class CodeAutoGenerateDiff:
|
|
|
32
36
|
|
|
33
37
|
@byzerllm.prompt(llm=lambda self: self.llm)
|
|
34
38
|
def multi_round_instruction(
|
|
35
|
-
self, instruction: str, content: str, context: str = ""
|
|
39
|
+
self, instruction: str, content: str, context: str = "", package_context: str = ""
|
|
36
40
|
) -> str:
|
|
37
41
|
"""
|
|
38
42
|
如果你需要生成代码,对于每个需要更改的文件,写出类似于 unified diff 的更改,就像`diff -U0`会产生的那样。
|
|
@@ -141,6 +145,13 @@ class CodeAutoGenerateDiff:
|
|
|
141
145
|
</files>
|
|
142
146
|
{%- endif %}
|
|
143
147
|
|
|
148
|
+
{%- if package_context %}
|
|
149
|
+
下面是上面文件的一些信息(包括最近的变更情况):
|
|
150
|
+
<package_context>
|
|
151
|
+
{{ package_context }}
|
|
152
|
+
</package_context>
|
|
153
|
+
{%- endif %}
|
|
154
|
+
|
|
144
155
|
{%- if context %}
|
|
145
156
|
<extra_context>
|
|
146
157
|
{{ context }}
|
|
@@ -169,7 +180,7 @@ class CodeAutoGenerateDiff:
|
|
|
169
180
|
|
|
170
181
|
@byzerllm.prompt(llm=lambda self: self.llm)
|
|
171
182
|
def single_round_instruction(
|
|
172
|
-
self, instruction: str, content: str, context: str = ""
|
|
183
|
+
self, instruction: str, content: str, context: str = "", package_context: str = ""
|
|
173
184
|
) -> str:
|
|
174
185
|
"""
|
|
175
186
|
如果你需要生成代码,对于每个需要更改的文件,写出类似于 unified diff 的更改,就像`diff -U0`会产生的那样。
|
|
@@ -278,6 +289,13 @@ class CodeAutoGenerateDiff:
|
|
|
278
289
|
</files>
|
|
279
290
|
{%- endif %}
|
|
280
291
|
|
|
292
|
+
{%- if package_context %}
|
|
293
|
+
下面是上面文件的一些信息(包括最近的变更情况):
|
|
294
|
+
<package_context>
|
|
295
|
+
{{ package_context }}
|
|
296
|
+
</package_context>
|
|
297
|
+
{%- endif %}
|
|
298
|
+
|
|
281
299
|
{%- if context %}
|
|
282
300
|
<extra_context>
|
|
283
301
|
{{ context }}
|
|
@@ -308,14 +326,33 @@ class CodeAutoGenerateDiff:
|
|
|
308
326
|
llm_config = {"human_as_model": self.args.human_as_model}
|
|
309
327
|
source_content = source_code_list.to_str()
|
|
310
328
|
|
|
329
|
+
# 获取包上下文信息
|
|
330
|
+
package_context = ""
|
|
331
|
+
|
|
332
|
+
if self.args.enable_active_context:
|
|
333
|
+
# 初始化活动上下文管理器
|
|
334
|
+
active_context_manager = ActiveContextManager(self.llm, self.args.source_dir)
|
|
335
|
+
# 获取活动上下文信息
|
|
336
|
+
result = active_context_manager.load_active_contexts_for_files(
|
|
337
|
+
[source.module_name for source in source_code_list.sources]
|
|
338
|
+
)
|
|
339
|
+
# 将活动上下文信息格式化为文本
|
|
340
|
+
if result.contexts:
|
|
341
|
+
package_context_parts = []
|
|
342
|
+
for dir_path, context in result.contexts.items():
|
|
343
|
+
package_context_parts.append(f"<package_info>{context.content}</package_info>")
|
|
344
|
+
|
|
345
|
+
package_context = "\n".join(package_context_parts)
|
|
346
|
+
|
|
311
347
|
if self.args.template == "common":
|
|
312
348
|
init_prompt = self.single_round_instruction.prompt(
|
|
313
|
-
instruction=query, content=source_content, context=self.args.context
|
|
349
|
+
instruction=query, content=source_content, context=self.args.context,
|
|
350
|
+
package_context=package_context
|
|
314
351
|
)
|
|
315
352
|
elif self.args.template == "auto_implement":
|
|
316
353
|
init_prompt = self.auto_implement_function.prompt(
|
|
317
354
|
instruction=query, content=source_content
|
|
318
|
-
)
|
|
355
|
+
)
|
|
319
356
|
|
|
320
357
|
conversations = []
|
|
321
358
|
|
|
@@ -362,10 +399,39 @@ class CodeAutoGenerateDiff:
|
|
|
362
399
|
if model_names_list:
|
|
363
400
|
model_name = model_names_list[0]
|
|
364
401
|
|
|
365
|
-
for
|
|
402
|
+
for i in range(self.generate_times_same_model):
|
|
366
403
|
model_names.append(model_name)
|
|
367
|
-
|
|
368
|
-
|
|
404
|
+
if i==0:
|
|
405
|
+
def job():
|
|
406
|
+
stream_generator = stream_chat_with_continue(
|
|
407
|
+
llm=llm,
|
|
408
|
+
conversations=conversations,
|
|
409
|
+
llm_config=llm_config,
|
|
410
|
+
args=self.args
|
|
411
|
+
)
|
|
412
|
+
full_response, last_meta = stream_out(
|
|
413
|
+
stream_generator,
|
|
414
|
+
model_name=model_name,
|
|
415
|
+
title=get_message_with_format(
|
|
416
|
+
"code_generate_title", model_name=model_name),
|
|
417
|
+
args=self.args,
|
|
418
|
+
extra_meta={
|
|
419
|
+
"stream_out_type": CodeGenerateStreamOutType.CODE_GENERATE.value
|
|
420
|
+
})
|
|
421
|
+
return ChatWithContinueResult(
|
|
422
|
+
content=full_response,
|
|
423
|
+
input_tokens_count=last_meta.input_tokens_count,
|
|
424
|
+
generated_tokens_count=last_meta.generated_tokens_count
|
|
425
|
+
)
|
|
426
|
+
futures.append(executor.submit(job))
|
|
427
|
+
else:
|
|
428
|
+
futures.append(executor.submit(
|
|
429
|
+
chat_with_continue,
|
|
430
|
+
llm=llm,
|
|
431
|
+
conversations=conversations,
|
|
432
|
+
llm_config=llm_config,
|
|
433
|
+
args=self.args
|
|
434
|
+
))
|
|
369
435
|
|
|
370
436
|
temp_results = [future.result() for future in futures]
|
|
371
437
|
for result in temp_results:
|
|
@@ -383,7 +449,12 @@ class CodeAutoGenerateDiff:
|
|
|
383
449
|
conversations + [{"role": "assistant", "content": result}])
|
|
384
450
|
else:
|
|
385
451
|
for _ in range(self.args.human_model_num):
|
|
386
|
-
single_result = chat_with_continue(
|
|
452
|
+
single_result = chat_with_continue(
|
|
453
|
+
llm=self.llms[0],
|
|
454
|
+
conversations=conversations,
|
|
455
|
+
llm_config=llm_config,
|
|
456
|
+
args=self.args
|
|
457
|
+
)
|
|
387
458
|
results.append(single_result.content)
|
|
388
459
|
input_tokens_count += single_result.input_tokens_count
|
|
389
460
|
generated_tokens_count += single_result.generated_tokens_count
|
|
@@ -431,9 +502,29 @@ class CodeAutoGenerateDiff:
|
|
|
431
502
|
llm_config = {"human_as_model": self.args.human_as_model}
|
|
432
503
|
result = []
|
|
433
504
|
source_content = source_code_list.to_str()
|
|
505
|
+
|
|
506
|
+
# 获取包上下文信息
|
|
507
|
+
package_context = ""
|
|
508
|
+
|
|
509
|
+
if self.args.enable_active_context:
|
|
510
|
+
# 初始化活动上下文管理器
|
|
511
|
+
active_context_manager = ActiveContextManager(self.llm, self.args.source_dir)
|
|
512
|
+
# 获取活动上下文信息
|
|
513
|
+
result = active_context_manager.load_active_contexts_for_files(
|
|
514
|
+
[source.module_name for source in source_code_list.sources]
|
|
515
|
+
)
|
|
516
|
+
# 将活动上下文信息格式化为文本
|
|
517
|
+
if result.contexts:
|
|
518
|
+
package_context_parts = []
|
|
519
|
+
for dir_path, context in result.contexts.items():
|
|
520
|
+
package_context_parts.append(f"<package_info>{context.content}</package_info>")
|
|
521
|
+
|
|
522
|
+
package_context = "\n".join(package_context_parts)
|
|
523
|
+
|
|
434
524
|
if self.args.template == "common":
|
|
435
525
|
init_prompt = self.multi_round_instruction.prompt(
|
|
436
|
-
instruction=query, content=source_content, context=self.args.context
|
|
526
|
+
instruction=query, content=source_content, context=self.args.context,
|
|
527
|
+
package_context=package_context
|
|
437
528
|
)
|
|
438
529
|
elif self.args.template == "auto_implement":
|
|
439
530
|
init_prompt = self.auto_implement_function.prompt(
|
|
@@ -11,11 +11,16 @@ from autocoder.utils.queue_communicate import (
|
|
|
11
11
|
)
|
|
12
12
|
import json
|
|
13
13
|
from concurrent.futures import ThreadPoolExecutor
|
|
14
|
-
from autocoder.common.utils_code_auto_generate import chat_with_continue
|
|
14
|
+
from autocoder.common.utils_code_auto_generate import chat_with_continue,stream_chat_with_continue,ChatWithContinueResult
|
|
15
|
+
from autocoder.utils.auto_coder_utils.chat_stream_out import stream_out
|
|
16
|
+
from autocoder.common.stream_out_type import CodeGenerateStreamOutType
|
|
17
|
+
from autocoder.common.auto_coder_lang import get_message_with_format
|
|
15
18
|
from autocoder.common.printer import Printer
|
|
16
19
|
from autocoder.rag.token_counter import count_tokens
|
|
17
20
|
from autocoder.utils import llms as llm_utils
|
|
18
21
|
from autocoder.common import SourceCodeList
|
|
22
|
+
from autocoder.memory.active_context_manager import ActiveContextManager
|
|
23
|
+
|
|
19
24
|
|
|
20
25
|
|
|
21
26
|
class CodeAutoGenerateEditBlock:
|
|
@@ -59,7 +64,7 @@ class CodeAutoGenerateEditBlock:
|
|
|
59
64
|
"""
|
|
60
65
|
|
|
61
66
|
@byzerllm.prompt()
|
|
62
|
-
def multi_round_instruction(self, instruction: str, content: str, context: str = "") -> str:
|
|
67
|
+
def multi_round_instruction(self, instruction: str, content: str, context: str = "", package_context: str = "") -> str:
|
|
63
68
|
"""
|
|
64
69
|
如果你需要生成代码,对于每个需要更改的文件,你需要按 *SEARCH/REPLACE block* 的格式进行生成。
|
|
65
70
|
|
|
@@ -193,6 +198,13 @@ class CodeAutoGenerateEditBlock:
|
|
|
193
198
|
</files>
|
|
194
199
|
{%- endif %}
|
|
195
200
|
|
|
201
|
+
{%- if package_context %}
|
|
202
|
+
下面是上面文件的一些信息(包括最近的变更情况):
|
|
203
|
+
<package_context>
|
|
204
|
+
{{ package_context }}
|
|
205
|
+
</package_context>
|
|
206
|
+
{%- endif %}
|
|
207
|
+
|
|
196
208
|
{%- if context %}
|
|
197
209
|
<extra_context>
|
|
198
210
|
{{ context }}
|
|
@@ -224,7 +236,11 @@ class CodeAutoGenerateEditBlock:
|
|
|
224
236
|
}
|
|
225
237
|
|
|
226
238
|
@byzerllm.prompt()
|
|
227
|
-
def single_round_instruction(self, instruction: str,
|
|
239
|
+
def single_round_instruction(self, instruction: str,
|
|
240
|
+
content: str,
|
|
241
|
+
context: str = "",
|
|
242
|
+
package_context: str = ""
|
|
243
|
+
) -> str:
|
|
228
244
|
"""
|
|
229
245
|
如果你需要生成代码,对于每个需要更改的文件,你需要按 *SEARCH/REPLACE block* 的格式进行生成。
|
|
230
246
|
|
|
@@ -357,6 +373,13 @@ class CodeAutoGenerateEditBlock:
|
|
|
357
373
|
</files>
|
|
358
374
|
{%- endif %}
|
|
359
375
|
|
|
376
|
+
{%- if package_context %}
|
|
377
|
+
下面是上面文件的一些信息(包括最近的变更情况):
|
|
378
|
+
<package_context>
|
|
379
|
+
{{ package_context }}
|
|
380
|
+
</package_context>
|
|
381
|
+
{%- endif %}
|
|
382
|
+
|
|
360
383
|
{%- if context %}
|
|
361
384
|
<extra_context>
|
|
362
385
|
{{ context }}
|
|
@@ -409,9 +432,28 @@ class CodeAutoGenerateEditBlock:
|
|
|
409
432
|
|
|
410
433
|
source_content = source_code_list.to_str()
|
|
411
434
|
|
|
435
|
+
active_context_manager = ActiveContextManager(self.llm, self.args.source_dir)
|
|
436
|
+
|
|
412
437
|
if self.args.template == "common":
|
|
438
|
+
# 获取包上下文信息
|
|
439
|
+
package_context = ""
|
|
440
|
+
|
|
441
|
+
if self.args.enable_active_context:
|
|
442
|
+
# 获取活动上下文信息
|
|
443
|
+
result = active_context_manager.load_active_contexts_for_files(
|
|
444
|
+
[source.module_name for source in source_code_list.sources]
|
|
445
|
+
)
|
|
446
|
+
# 将活动上下文信息格式化为文本
|
|
447
|
+
if result.contexts:
|
|
448
|
+
package_context_parts = []
|
|
449
|
+
for dir_path, context in result.contexts.items():
|
|
450
|
+
package_context_parts.append(f"<package_info>{context.content}</package_info>")
|
|
451
|
+
|
|
452
|
+
package_context = "\n".join(package_context_parts)
|
|
453
|
+
|
|
413
454
|
init_prompt = self.single_round_instruction.prompt(
|
|
414
|
-
instruction=query, content=source_content, context=self.args.context
|
|
455
|
+
instruction=query, content=source_content, context=self.args.context,
|
|
456
|
+
package_context=package_context
|
|
415
457
|
)
|
|
416
458
|
elif self.args.template == "auto_implement":
|
|
417
459
|
init_prompt = self.auto_implement_function.prompt(
|
|
@@ -470,10 +512,39 @@ class CodeAutoGenerateEditBlock:
|
|
|
470
512
|
if model_names_list:
|
|
471
513
|
model_name = model_names_list[0]
|
|
472
514
|
|
|
473
|
-
for
|
|
515
|
+
for i in range(self.generate_times_same_model):
|
|
474
516
|
model_names.append(model_name)
|
|
475
|
-
|
|
476
|
-
|
|
517
|
+
if i==0:
|
|
518
|
+
def job():
|
|
519
|
+
stream_generator = stream_chat_with_continue(
|
|
520
|
+
llm=llm,
|
|
521
|
+
conversations=conversations,
|
|
522
|
+
llm_config=llm_config,
|
|
523
|
+
args=self.args
|
|
524
|
+
)
|
|
525
|
+
full_response, last_meta = stream_out(
|
|
526
|
+
stream_generator,
|
|
527
|
+
model_name=model_name,
|
|
528
|
+
title=get_message_with_format(
|
|
529
|
+
"code_generate_title", model_name=model_name),
|
|
530
|
+
args=self.args,
|
|
531
|
+
extra_meta={
|
|
532
|
+
"stream_out_type": CodeGenerateStreamOutType.CODE_GENERATE.value
|
|
533
|
+
})
|
|
534
|
+
return ChatWithContinueResult(
|
|
535
|
+
content=full_response,
|
|
536
|
+
input_tokens_count=last_meta.input_tokens_count,
|
|
537
|
+
generated_tokens_count=last_meta.generated_tokens_count
|
|
538
|
+
)
|
|
539
|
+
futures.append(executor.submit(job))
|
|
540
|
+
else:
|
|
541
|
+
futures.append(executor.submit(
|
|
542
|
+
chat_with_continue,
|
|
543
|
+
llm=llm,
|
|
544
|
+
conversations=conversations,
|
|
545
|
+
llm_config=llm_config,
|
|
546
|
+
args=self.args
|
|
547
|
+
))
|
|
477
548
|
|
|
478
549
|
temp_results = [future.result() for future in futures]
|
|
479
550
|
|
|
@@ -493,7 +564,11 @@ class CodeAutoGenerateEditBlock:
|
|
|
493
564
|
else:
|
|
494
565
|
for _ in range(self.args.human_model_num):
|
|
495
566
|
single_result = chat_with_continue(
|
|
496
|
-
llm=self.llms[0],
|
|
567
|
+
llm=self.llms[0],
|
|
568
|
+
conversations=conversations,
|
|
569
|
+
llm_config=llm_config,
|
|
570
|
+
args=self.args
|
|
571
|
+
)
|
|
497
572
|
results.append(single_result.content)
|
|
498
573
|
input_tokens_count += single_result.input_tokens_count
|
|
499
574
|
generated_tokens_count += single_result.generated_tokens_count
|
|
@@ -525,9 +600,28 @@ class CodeAutoGenerateEditBlock:
|
|
|
525
600
|
result = []
|
|
526
601
|
source_content = source_code_list.to_str()
|
|
527
602
|
|
|
603
|
+
# 获取包上下文信息
|
|
604
|
+
package_context = ""
|
|
605
|
+
|
|
606
|
+
if self.args.enable_active_context:
|
|
607
|
+
# 初始化活动上下文管理器
|
|
608
|
+
active_context_manager = ActiveContextManager(self.llm, self.args.source_dir)
|
|
609
|
+
# 获取活动上下文信息
|
|
610
|
+
result = active_context_manager.load_active_contexts_for_files(
|
|
611
|
+
[source.module_name for source in source_code_list.sources]
|
|
612
|
+
)
|
|
613
|
+
# 将活动上下文信息格式化为文本
|
|
614
|
+
if result.contexts:
|
|
615
|
+
package_context_parts = []
|
|
616
|
+
for dir_path, context in result.contexts.items():
|
|
617
|
+
package_context_parts.append(f"<package_info>{context.content}</package_info>")
|
|
618
|
+
|
|
619
|
+
package_context = "\n".join(package_context_parts)
|
|
620
|
+
|
|
528
621
|
if self.args.template == "common":
|
|
529
622
|
init_prompt = self.multi_round_instruction.prompt(
|
|
530
|
-
instruction=query, content=source_content, context=self.args.context
|
|
623
|
+
instruction=query, content=source_content, context=self.args.context,
|
|
624
|
+
package_context=package_context
|
|
531
625
|
)
|
|
532
626
|
elif self.args.template == "auto_implement":
|
|
533
627
|
init_prompt = self.auto_implement_function.prompt(
|