auto-coder 0.1.4__tar.gz → 0.1.6__tar.gz
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.
- {auto-coder-0.1.4 → auto-coder-0.1.6}/PKG-INFO +27 -10
- {auto-coder-0.1.4 → auto-coder-0.1.6}/README.md +26 -9
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/auto_coder.egg-info/PKG-INFO +27 -10
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/auto_coder.egg-info/SOURCES.txt +2 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/auto_coder.py +3 -2
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/common/__init__.py +38 -2
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/dispacher/actions/copilot.py +34 -51
- auto-coder-0.1.6/src/autocoder/index/__init__.py +0 -0
- auto-coder-0.1.6/src/autocoder/index/index.py +156 -0
- auto-coder-0.1.6/src/autocoder/version.py +1 -0
- auto-coder-0.1.4/src/autocoder/version.py +0 -1
- {auto-coder-0.1.4 → auto-coder-0.1.6}/setup.cfg +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/setup.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/auto_coder.egg-info/dependency_links.txt +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/auto_coder.egg-info/entry_points.txt +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/auto_coder.egg-info/top_level.txt +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/__init__.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/common/JupyterClient.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/common/ShellClient.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/common/cleaner.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/common/const.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/dispacher/__init__.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/dispacher/actions/__init__.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/pyproject/__init__.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/suffixproject/__init__.py +0 -0
- {auto-coder-0.1.4 → auto-coder-0.1.6}/src/autocoder/tsproject/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: auto-coder
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: AutoCoder: AutoCoder
|
|
5
5
|
Author: allwefantasy
|
|
6
6
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
@@ -27,13 +27,34 @@ Auto-Coder (powered by Byzer-LLM)
|
|
|
27
27
|
|
|
28
28
|
*Latest News* 🔥
|
|
29
29
|
|
|
30
|
-
- [2024/03] Release Auto-Coder 0.1.
|
|
30
|
+
- [2024/03] Release Auto-Coder 0.1.6
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
🚀 Attention developers! 🚨 The game-changing Auto-Coder has arrived, and it's about to take your AI programming to a whole new level! 🌟
|
|
37
|
+
|
|
38
|
+
Fueled by the incredible power of Byzer-LLM, this command-line tool is packed with features that will blow your mind:
|
|
39
|
+
|
|
40
|
+
📂 Say goodbye to manual context gathering! Auto-Coder intelligently generates code based on the context of your source directory. It's like having a genius assistant that knows exactly what you need!
|
|
41
|
+
|
|
42
|
+
💡 Two modes, endless possibilities! Generate perfect prompts to paste into web-based large models, or let Auto-Coder work its magic directly with private models via Byzer-LLM. The choice is yours, and the results are always spectacular!
|
|
43
|
+
|
|
44
|
+
💻 Python? TypeScript? No problem! Auto-Coder supports all the cool kids on the programming block.
|
|
45
|
+
|
|
46
|
+
🌍 Going global is a breeze! Auto-Coder automatically translates your project files, so your code can conquer the world!
|
|
47
|
+
|
|
48
|
+
🤖 Copilot mode is here, and it's your new best friend! With its built-in shell/Jupyter engine, Auto-Coder breaks down tasks, sets up environments, creates projects, and even modifies code for you. It's like having a super-smart sidekick that never sleeps!
|
|
49
|
+
|
|
50
|
+
🧑💻 Developers, prepare to have your minds blown! Auto-Coder integrates seamlessly with the hottest AI models like ChatGPT, turbocharging your development process to lightning speeds! 🚀
|
|
51
|
+
|
|
52
|
+
🌟 Don't wait another second! Experience the raw power of Auto-Coder today and let AI be your ultimate coding companion! https://github.com/allwefantasy/auto-coder 🔥
|
|
53
|
+
|
|
54
|
+
#AutoCoder #AIProgramming #GameChanger #ByzerLLM #DevTools
|
|
55
|
+
|
|
34
56
|
## Table of Contents
|
|
35
57
|
|
|
36
|
-
- [Introduction](#introduction)
|
|
37
58
|
- [Brand new Installation](#brand-new-installation)
|
|
38
59
|
- [Existing Installation](#existing-installation)
|
|
39
60
|
- [Usage](#usage)
|
|
@@ -44,11 +65,7 @@ Auto-Coder (powered by Byzer-LLM)
|
|
|
44
65
|
- [Real-Auto](#real-auto)
|
|
45
66
|
|
|
46
67
|
|
|
47
|
-
## Introduction
|
|
48
68
|
|
|
49
|
-
Auto-Coder is a powerful tool powered by Byzer-LLM that streamlines code generation and project management. It collects source code from a specified directory and generates context based on user queries, which can be used with ChatGPT or other AI models. Auto-Coder also integrates with Byzer-LLM to generate results directly. It supports various project types, including Python, TypeScript, and offers advanced features like file translation and targeted code generation within specific modules and packages. With Auto-Coder, developers can significantly enhance their productivity and efficiently manage their projects, leveraging the power of AI-assisted coding.
|
|
50
|
-
|
|
51
|
-
The copilot project type can automatically do environment setup and project creation or create new classes and methods based on user queries. It is a powerful tool for developers to quickly create new projects and manage existing ones.
|
|
52
69
|
|
|
53
70
|
## Brand new Installation
|
|
54
71
|
|
|
@@ -219,8 +236,8 @@ Conda环境: byzerllm-dev
|
|
|
219
236
|
用户的问题是:用python打印你好,中国
|
|
220
237
|
|
|
221
238
|
每次生成一个执行步骤,然后询问我是否继续,当我回复继续,继续生成下一个执行步骤。
|
|
222
|
-
|
|
223
|
-
assistant:
|
|
239
|
+
|
|
240
|
+
assistant:
|
|
224
241
|
{
|
|
225
242
|
"code": "print('你好,中国')",
|
|
226
243
|
"lang": "python",
|
|
@@ -230,7 +247,7 @@ assistant: ```json
|
|
|
230
247
|
"timeout": -1,
|
|
231
248
|
"ignore_error": false
|
|
232
249
|
}
|
|
233
|
-
|
|
250
|
+
|
|
234
251
|
是否继续?
|
|
235
252
|
user: 继续
|
|
236
253
|
=================RESULT==================
|
|
@@ -18,13 +18,34 @@ Auto-Coder (powered by Byzer-LLM)
|
|
|
18
18
|
|
|
19
19
|
*Latest News* 🔥
|
|
20
20
|
|
|
21
|
-
- [2024/03] Release Auto-Coder 0.1.
|
|
21
|
+
- [2024/03] Release Auto-Coder 0.1.6
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
🚀 Attention developers! 🚨 The game-changing Auto-Coder has arrived, and it's about to take your AI programming to a whole new level! 🌟
|
|
28
|
+
|
|
29
|
+
Fueled by the incredible power of Byzer-LLM, this command-line tool is packed with features that will blow your mind:
|
|
30
|
+
|
|
31
|
+
📂 Say goodbye to manual context gathering! Auto-Coder intelligently generates code based on the context of your source directory. It's like having a genius assistant that knows exactly what you need!
|
|
32
|
+
|
|
33
|
+
💡 Two modes, endless possibilities! Generate perfect prompts to paste into web-based large models, or let Auto-Coder work its magic directly with private models via Byzer-LLM. The choice is yours, and the results are always spectacular!
|
|
34
|
+
|
|
35
|
+
💻 Python? TypeScript? No problem! Auto-Coder supports all the cool kids on the programming block.
|
|
36
|
+
|
|
37
|
+
🌍 Going global is a breeze! Auto-Coder automatically translates your project files, so your code can conquer the world!
|
|
38
|
+
|
|
39
|
+
🤖 Copilot mode is here, and it's your new best friend! With its built-in shell/Jupyter engine, Auto-Coder breaks down tasks, sets up environments, creates projects, and even modifies code for you. It's like having a super-smart sidekick that never sleeps!
|
|
40
|
+
|
|
41
|
+
🧑💻 Developers, prepare to have your minds blown! Auto-Coder integrates seamlessly with the hottest AI models like ChatGPT, turbocharging your development process to lightning speeds! 🚀
|
|
42
|
+
|
|
43
|
+
🌟 Don't wait another second! Experience the raw power of Auto-Coder today and let AI be your ultimate coding companion! https://github.com/allwefantasy/auto-coder 🔥
|
|
44
|
+
|
|
45
|
+
#AutoCoder #AIProgramming #GameChanger #ByzerLLM #DevTools
|
|
46
|
+
|
|
25
47
|
## Table of Contents
|
|
26
48
|
|
|
27
|
-
- [Introduction](#introduction)
|
|
28
49
|
- [Brand new Installation](#brand-new-installation)
|
|
29
50
|
- [Existing Installation](#existing-installation)
|
|
30
51
|
- [Usage](#usage)
|
|
@@ -35,11 +56,7 @@ Auto-Coder (powered by Byzer-LLM)
|
|
|
35
56
|
- [Real-Auto](#real-auto)
|
|
36
57
|
|
|
37
58
|
|
|
38
|
-
## Introduction
|
|
39
59
|
|
|
40
|
-
Auto-Coder is a powerful tool powered by Byzer-LLM that streamlines code generation and project management. It collects source code from a specified directory and generates context based on user queries, which can be used with ChatGPT or other AI models. Auto-Coder also integrates with Byzer-LLM to generate results directly. It supports various project types, including Python, TypeScript, and offers advanced features like file translation and targeted code generation within specific modules and packages. With Auto-Coder, developers can significantly enhance their productivity and efficiently manage their projects, leveraging the power of AI-assisted coding.
|
|
41
|
-
|
|
42
|
-
The copilot project type can automatically do environment setup and project creation or create new classes and methods based on user queries. It is a powerful tool for developers to quickly create new projects and manage existing ones.
|
|
43
60
|
|
|
44
61
|
## Brand new Installation
|
|
45
62
|
|
|
@@ -210,8 +227,8 @@ Conda环境: byzerllm-dev
|
|
|
210
227
|
用户的问题是:用python打印你好,中国
|
|
211
228
|
|
|
212
229
|
每次生成一个执行步骤,然后询问我是否继续,当我回复继续,继续生成下一个执行步骤。
|
|
213
|
-
|
|
214
|
-
assistant:
|
|
230
|
+
|
|
231
|
+
assistant:
|
|
215
232
|
{
|
|
216
233
|
"code": "print('你好,中国')",
|
|
217
234
|
"lang": "python",
|
|
@@ -221,7 +238,7 @@ assistant: ```json
|
|
|
221
238
|
"timeout": -1,
|
|
222
239
|
"ignore_error": false
|
|
223
240
|
}
|
|
224
|
-
|
|
241
|
+
|
|
225
242
|
是否继续?
|
|
226
243
|
user: 继续
|
|
227
244
|
=================RESULT==================
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: auto-coder
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: AutoCoder: AutoCoder
|
|
5
5
|
Author: allwefantasy
|
|
6
6
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
@@ -27,13 +27,34 @@ Auto-Coder (powered by Byzer-LLM)
|
|
|
27
27
|
|
|
28
28
|
*Latest News* 🔥
|
|
29
29
|
|
|
30
|
-
- [2024/03] Release Auto-Coder 0.1.
|
|
30
|
+
- [2024/03] Release Auto-Coder 0.1.6
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
🚀 Attention developers! 🚨 The game-changing Auto-Coder has arrived, and it's about to take your AI programming to a whole new level! 🌟
|
|
37
|
+
|
|
38
|
+
Fueled by the incredible power of Byzer-LLM, this command-line tool is packed with features that will blow your mind:
|
|
39
|
+
|
|
40
|
+
📂 Say goodbye to manual context gathering! Auto-Coder intelligently generates code based on the context of your source directory. It's like having a genius assistant that knows exactly what you need!
|
|
41
|
+
|
|
42
|
+
💡 Two modes, endless possibilities! Generate perfect prompts to paste into web-based large models, or let Auto-Coder work its magic directly with private models via Byzer-LLM. The choice is yours, and the results are always spectacular!
|
|
43
|
+
|
|
44
|
+
💻 Python? TypeScript? No problem! Auto-Coder supports all the cool kids on the programming block.
|
|
45
|
+
|
|
46
|
+
🌍 Going global is a breeze! Auto-Coder automatically translates your project files, so your code can conquer the world!
|
|
47
|
+
|
|
48
|
+
🤖 Copilot mode is here, and it's your new best friend! With its built-in shell/Jupyter engine, Auto-Coder breaks down tasks, sets up environments, creates projects, and even modifies code for you. It's like having a super-smart sidekick that never sleeps!
|
|
49
|
+
|
|
50
|
+
🧑💻 Developers, prepare to have your minds blown! Auto-Coder integrates seamlessly with the hottest AI models like ChatGPT, turbocharging your development process to lightning speeds! 🚀
|
|
51
|
+
|
|
52
|
+
🌟 Don't wait another second! Experience the raw power of Auto-Coder today and let AI be your ultimate coding companion! https://github.com/allwefantasy/auto-coder 🔥
|
|
53
|
+
|
|
54
|
+
#AutoCoder #AIProgramming #GameChanger #ByzerLLM #DevTools
|
|
55
|
+
|
|
34
56
|
## Table of Contents
|
|
35
57
|
|
|
36
|
-
- [Introduction](#introduction)
|
|
37
58
|
- [Brand new Installation](#brand-new-installation)
|
|
38
59
|
- [Existing Installation](#existing-installation)
|
|
39
60
|
- [Usage](#usage)
|
|
@@ -44,11 +65,7 @@ Auto-Coder (powered by Byzer-LLM)
|
|
|
44
65
|
- [Real-Auto](#real-auto)
|
|
45
66
|
|
|
46
67
|
|
|
47
|
-
## Introduction
|
|
48
68
|
|
|
49
|
-
Auto-Coder is a powerful tool powered by Byzer-LLM that streamlines code generation and project management. It collects source code from a specified directory and generates context based on user queries, which can be used with ChatGPT or other AI models. Auto-Coder also integrates with Byzer-LLM to generate results directly. It supports various project types, including Python, TypeScript, and offers advanced features like file translation and targeted code generation within specific modules and packages. With Auto-Coder, developers can significantly enhance their productivity and efficiently manage their projects, leveraging the power of AI-assisted coding.
|
|
50
|
-
|
|
51
|
-
The copilot project type can automatically do environment setup and project creation or create new classes and methods based on user queries. It is a powerful tool for developers to quickly create new projects and manage existing ones.
|
|
52
69
|
|
|
53
70
|
## Brand new Installation
|
|
54
71
|
|
|
@@ -219,8 +236,8 @@ Conda环境: byzerllm-dev
|
|
|
219
236
|
用户的问题是:用python打印你好,中国
|
|
220
237
|
|
|
221
238
|
每次生成一个执行步骤,然后询问我是否继续,当我回复继续,继续生成下一个执行步骤。
|
|
222
|
-
|
|
223
|
-
assistant:
|
|
239
|
+
|
|
240
|
+
assistant:
|
|
224
241
|
{
|
|
225
242
|
"code": "print('你好,中国')",
|
|
226
243
|
"lang": "python",
|
|
@@ -230,7 +247,7 @@ assistant: ```json
|
|
|
230
247
|
"timeout": -1,
|
|
231
248
|
"ignore_error": false
|
|
232
249
|
}
|
|
233
|
-
|
|
250
|
+
|
|
234
251
|
是否继续?
|
|
235
252
|
user: 继续
|
|
236
253
|
=================RESULT==================
|
|
@@ -16,6 +16,8 @@ src/autocoder/common/const.py
|
|
|
16
16
|
src/autocoder/dispacher/__init__.py
|
|
17
17
|
src/autocoder/dispacher/actions/__init__.py
|
|
18
18
|
src/autocoder/dispacher/actions/copilot.py
|
|
19
|
+
src/autocoder/index/__init__.py
|
|
20
|
+
src/autocoder/index/index.py
|
|
19
21
|
src/autocoder/pyproject/__init__.py
|
|
20
22
|
src/autocoder/suffixproject/__init__.py
|
|
21
23
|
src/autocoder/tsproject/__init__.py
|
|
@@ -18,8 +18,9 @@ def parse_args() -> AutoCoderArgs:
|
|
|
18
18
|
parser.add_argument("--script_path", default="", help="only works for py-script project type. The path to the Python script. default is empty.")
|
|
19
19
|
parser.add_argument("--model", default="", help="the model name to use")
|
|
20
20
|
parser.add_argument("--model_max_length", type=int, default=1024, help="the maximum length generated by the model. default is 1024 this only works when model is specified.")
|
|
21
|
-
parser.add_argument("--file", help="Path to the YAML configuration file")
|
|
21
|
+
parser.add_argument("--file", default=None, required=False, help="Path to the YAML configuration file")
|
|
22
22
|
parser.add_argument("--anti_quota_limit",type=int, default=1, help="After how much time to wait for the next request. default is 1s")
|
|
23
|
+
parser.add_argument("--skip_build_index", action='store_true', help="Skip building index or not. default is True")
|
|
23
24
|
|
|
24
25
|
args = parser.parse_args()
|
|
25
26
|
return AutoCoderArgs(**vars(args))
|
|
@@ -36,7 +37,7 @@ def main():
|
|
|
36
37
|
|
|
37
38
|
if args.model:
|
|
38
39
|
byzerllm.connect_cluster()
|
|
39
|
-
llm = byzerllm.ByzerLLM()
|
|
40
|
+
llm = byzerllm.ByzerLLM(verbose=True)
|
|
40
41
|
llm.setup_template(model=args.model,template="auto")
|
|
41
42
|
llm.setup_default_model_name(args.model)
|
|
42
43
|
llm.setup_max_output_length(args.model,args.model_max_length)
|
|
@@ -3,6 +3,7 @@ import ast
|
|
|
3
3
|
import sys
|
|
4
4
|
import subprocess
|
|
5
5
|
import os
|
|
6
|
+
import time
|
|
6
7
|
from typing import List,Dict,Any,Optional
|
|
7
8
|
|
|
8
9
|
class SourceCode(pydantic.BaseModel):
|
|
@@ -63,8 +64,9 @@ class AutoCoderArgs(pydantic.BaseModel):
|
|
|
63
64
|
script_path: str = pydantic.Field("", description="only works for py-script project type. The path to the Python script. default is empty.")
|
|
64
65
|
model: str = pydantic.Field("", description="the model name to use")
|
|
65
66
|
model_max_length: int = pydantic.Field(1024, description="the maximum length generated by the model. default is 1024 this only works when model is specified.")
|
|
66
|
-
file: str = pydantic.Field(
|
|
67
|
+
file: Optional[str] = pydantic.Field(None, description="the configuration file to use")
|
|
67
68
|
anti_quota_limit: Optional[int] = pydantic.Field(1, description="After how much time to wait for the next request. default is 1s")
|
|
69
|
+
skip_build_index: bool = pydantic.Field(True, description="Skip building index or not. default is True")
|
|
68
70
|
|
|
69
71
|
|
|
70
72
|
def is_likely_useful_file(file_path):
|
|
@@ -150,4 +152,38 @@ def detect_env() -> EnvInfo:
|
|
|
150
152
|
conda_env=conda_env,
|
|
151
153
|
virtualenv=virtualenv,
|
|
152
154
|
has_bash=has_bash
|
|
153
|
-
)
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def chat_with_llm_step_by_step(llm,conversations, response_class, max_steps=30, anti_quota_limit=1):
|
|
159
|
+
result = []
|
|
160
|
+
t = llm.chat_oai(conversations=conversations, response_class=response_class)
|
|
161
|
+
total_steps = max_steps
|
|
162
|
+
current_step = 0
|
|
163
|
+
|
|
164
|
+
if not t[0].value:
|
|
165
|
+
total_steps = t[0].value.total_steps
|
|
166
|
+
if total_steps == 1:
|
|
167
|
+
current_step = 1
|
|
168
|
+
|
|
169
|
+
while current_step < total_steps and max_steps > 0 and t[0].value:
|
|
170
|
+
total_steps = t[0].value.total_steps
|
|
171
|
+
result.append(t[0].value)
|
|
172
|
+
conversations.append({
|
|
173
|
+
"role": "assistant",
|
|
174
|
+
"content": t[0].response.output
|
|
175
|
+
})
|
|
176
|
+
print(f"{conversations[-1]['role']}: {conversations[-1]['content']}\n", flush=True)
|
|
177
|
+
|
|
178
|
+
conversations.append({
|
|
179
|
+
"role": "user",
|
|
180
|
+
"content": "继续"
|
|
181
|
+
})
|
|
182
|
+
print(f"{conversations[-1]['role']}: {conversations[-1]['content']}\n", flush=True)
|
|
183
|
+
|
|
184
|
+
t = llm.chat_oai(conversations=conversations, response_class=response_class)
|
|
185
|
+
max_steps -= 1
|
|
186
|
+
current_step += 1
|
|
187
|
+
time.sleep(anti_quota_limit)
|
|
188
|
+
|
|
189
|
+
return result, conversations
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
from autocoder.common import AutoCoderArgs,ExecuteSteps,ExecuteStep,EnvInfo,detect_env
|
|
1
|
+
from autocoder.common import AutoCoderArgs,ExecuteSteps,ExecuteStep,EnvInfo,detect_env,chat_with_llm_step_by_step
|
|
2
2
|
from autocoder.common.JupyterClient import JupyterNotebook
|
|
3
3
|
from autocoder.common.ShellClient import ShellClient
|
|
4
4
|
from autocoder.suffixproject import SuffixProject
|
|
5
|
+
from autocoder.index.index import IndexManager
|
|
5
6
|
from typing import Optional,Dict,Any,List
|
|
6
7
|
import byzerllm
|
|
7
8
|
import time
|
|
@@ -11,7 +12,7 @@ import re
|
|
|
11
12
|
class ActionCopilot():
|
|
12
13
|
def __init__(self,args:AutoCoderArgs,llm:Optional[byzerllm.ByzerLLM]=None) -> None:
|
|
13
14
|
self.args = args
|
|
14
|
-
self.llm = llm
|
|
15
|
+
self.llm = llm
|
|
15
16
|
self.env_info = detect_env()
|
|
16
17
|
|
|
17
18
|
@byzerllm.prompt(render="jinja2")
|
|
@@ -42,25 +43,12 @@ class ActionCopilot():
|
|
|
42
43
|
用户的问题是:{{ s }}
|
|
43
44
|
|
|
44
45
|
每次生成一个执行步骤,然后询问我是否继续,当我回复继续,继续生成下一个执行步骤。
|
|
45
|
-
'''
|
|
46
|
-
|
|
47
|
-
@byzerllm.prompt(lambda self:self.llm,render="jinja2")
|
|
48
|
-
def get_all_file_symbols(self,path:str,code:str)->str:
|
|
49
|
-
'''
|
|
50
|
-
下列是文件 {{ path }} 的源码:
|
|
51
|
-
|
|
52
|
-
{{ code }}
|
|
53
|
-
|
|
54
|
-
从上述内容中获取文件中的符号。需要获取的符号类型包括:函数、类、变量、模块、包
|
|
55
|
-
按如下格式返回:
|
|
56
|
-
|
|
57
|
-
符号类型: 符号名称
|
|
58
|
-
'''
|
|
46
|
+
'''
|
|
59
47
|
|
|
60
48
|
def execute_steps(self, steps: ExecuteSteps) -> str:
|
|
61
49
|
jupyter_client = JupyterNotebook()
|
|
62
50
|
shell_client = ShellClient()
|
|
63
|
-
|
|
51
|
+
|
|
64
52
|
output = ""
|
|
65
53
|
for step in steps.steps:
|
|
66
54
|
if step.lang == "python":
|
|
@@ -117,10 +105,27 @@ class ActionCopilot():
|
|
|
117
105
|
file_filter=None
|
|
118
106
|
)
|
|
119
107
|
pp.run()
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if
|
|
123
|
-
|
|
108
|
+
final_files = []
|
|
109
|
+
|
|
110
|
+
if not args.skip_build_index:
|
|
111
|
+
index_manager = IndexManager(llm=self.llm,sources=pp.sources,args=args)
|
|
112
|
+
index_manager.build_index()
|
|
113
|
+
target_files = index_manager.get_target_files_by_query(args.query)
|
|
114
|
+
print(f"Target Files: {target_files.file_list}",flush=True)
|
|
115
|
+
related_fiels = index_manager.get_related_files([file.file_path for file in target_files.file_list])
|
|
116
|
+
print(f"Related Files: {related_fiels.file_list}",flush=True)
|
|
117
|
+
|
|
118
|
+
for file in target_files.file_list + related_fiels.file_list:
|
|
119
|
+
if file.file_path.strip().startswith("##"):
|
|
120
|
+
final_files.append(file.file_path.strip()[2:])
|
|
121
|
+
else:
|
|
122
|
+
final_files = [file.module_name for file in pp.sources]
|
|
123
|
+
|
|
124
|
+
source_code = ""
|
|
125
|
+
for file in pp.sources:
|
|
126
|
+
if file.module_name in final_files:
|
|
127
|
+
source_code += f"##File: {file.module_name}\n"
|
|
128
|
+
source_code += f"{file.source_code}\n\n"
|
|
124
129
|
|
|
125
130
|
final_v = ExecuteSteps(steps=[])
|
|
126
131
|
q = self.get_execute_steps(args.query,env_info = self.env_info.dict(),source_code=source_code)
|
|
@@ -130,36 +135,14 @@ class ActionCopilot():
|
|
|
130
135
|
}]
|
|
131
136
|
|
|
132
137
|
print(f"{conversations[0]['role']}: {conversations[0]['content']}\n",flush=True)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if total_steps == 1:
|
|
142
|
-
current_step = 1
|
|
143
|
-
|
|
144
|
-
while current_step < total_steps and max_steps>0 and t[0].value:
|
|
145
|
-
total_steps = t[0].value.total_steps
|
|
146
|
-
final_v.steps.append(t[0].value)
|
|
147
|
-
conversations.append({
|
|
148
|
-
"role":"assistant",
|
|
149
|
-
"content":t[0].response.output
|
|
150
|
-
})
|
|
151
|
-
print(f"{conversations[-1]['role']}: {conversations[-1]['content']}\n",flush=True)
|
|
152
|
-
|
|
153
|
-
conversations.append({
|
|
154
|
-
"role":"user",
|
|
155
|
-
"content":"继续"
|
|
156
|
-
})
|
|
157
|
-
print(f"{conversations[-1]['role']}: {conversations[-1]['content']}\n",flush=True)
|
|
158
|
-
|
|
159
|
-
t = self.llm.chat_oai(conversations=conversations,response_class=ExecuteStep)
|
|
160
|
-
max_steps -= 1
|
|
161
|
-
current_step += 1
|
|
162
|
-
time.sleep(args.anti_quota_limit)
|
|
138
|
+
|
|
139
|
+
(result,_) = chat_with_llm_step_by_step(self.llm,conversations=conversations,
|
|
140
|
+
response_class=ExecuteStep,
|
|
141
|
+
max_steps=30,
|
|
142
|
+
anti_quota_limit=args.anti_quota_limit)
|
|
143
|
+
|
|
144
|
+
for item in result:
|
|
145
|
+
final_v.steps.append(item)
|
|
163
146
|
|
|
164
147
|
# 执行步骤并保存结果
|
|
165
148
|
result = self.execute_steps(final_v)
|
|
File without changes
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
import time
|
|
4
|
+
from typing import List
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from autocoder.common import SourceCode, AutoCoderArgs
|
|
7
|
+
|
|
8
|
+
import pydantic
|
|
9
|
+
import byzerllm
|
|
10
|
+
import hashlib
|
|
11
|
+
|
|
12
|
+
class IndexItem(pydantic.BaseModel):
|
|
13
|
+
module_name: str
|
|
14
|
+
symbols: str
|
|
15
|
+
last_modified: str
|
|
16
|
+
md5: str # 新增文件内容的MD5哈希值字段
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TargetFile(pydantic.BaseModel):
|
|
20
|
+
file_path: str
|
|
21
|
+
reason: str = pydantic.Field(...,description="The reason why the file is the target file")
|
|
22
|
+
|
|
23
|
+
class FileList(pydantic.BaseModel):
|
|
24
|
+
file_list: List[TargetFile]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class IndexManager:
|
|
28
|
+
def __init__(self, llm, sources: List[SourceCode], args:AutoCoderArgs):
|
|
29
|
+
self.sources = sources
|
|
30
|
+
self.source_dir = args.source_dir
|
|
31
|
+
self.anti_quota_limit = args.anti_quota_limit
|
|
32
|
+
self.index_dir = os.path.join(self.source_dir, ".auto-coder")
|
|
33
|
+
self.index_file = os.path.join(self.index_dir, "index.json")
|
|
34
|
+
self.llm = llm
|
|
35
|
+
|
|
36
|
+
# 如果索引目录不存在,则创建它
|
|
37
|
+
if not os.path.exists(self.index_dir):
|
|
38
|
+
os.makedirs(self.index_dir)
|
|
39
|
+
|
|
40
|
+
@byzerllm.prompt(lambda self: self.llm, render="jinja2")
|
|
41
|
+
def _get_related_files(self,indices:str, file_paths: str) -> FileList:
|
|
42
|
+
'''
|
|
43
|
+
下面是所有文件以及对应的符号信息:
|
|
44
|
+
|
|
45
|
+
{{ indices }}
|
|
46
|
+
|
|
47
|
+
请参考上面的信息,找到被下列文件使用或者引用到的文件列表:
|
|
48
|
+
|
|
49
|
+
{{ file_paths }}
|
|
50
|
+
|
|
51
|
+
如果没有相关的文件,返回空即可
|
|
52
|
+
'''
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@byzerllm.prompt(lambda self: self.llm, render="jinja2")
|
|
56
|
+
def get_all_file_symbols(self, path: str, code: str) -> str:
|
|
57
|
+
'''
|
|
58
|
+
下列是文件 {{ path }} 的源码:
|
|
59
|
+
|
|
60
|
+
{{ code }}
|
|
61
|
+
|
|
62
|
+
从上述内容中获取文件中的符号。需要获取的符号类型包括:
|
|
63
|
+
|
|
64
|
+
1. 函数
|
|
65
|
+
2. 类
|
|
66
|
+
3. 变量
|
|
67
|
+
4. 所有导入语句
|
|
68
|
+
|
|
69
|
+
如果没有任何符号,返回"没有任何符号"。
|
|
70
|
+
最终结果按如下格式返回:
|
|
71
|
+
|
|
72
|
+
符号类型: 符号名称, 符号名称, ...
|
|
73
|
+
'''
|
|
74
|
+
|
|
75
|
+
def build_index(self):
|
|
76
|
+
if os.path.exists(self.index_file):
|
|
77
|
+
with open(self.index_file, "r") as file:
|
|
78
|
+
index_data = json.load(file)
|
|
79
|
+
else:
|
|
80
|
+
index_data = {}
|
|
81
|
+
|
|
82
|
+
updated_sources = []
|
|
83
|
+
|
|
84
|
+
for source in self.sources:
|
|
85
|
+
file_path = source.module_name
|
|
86
|
+
md5 = hashlib.md5(source.source_code.encode('utf-8')).hexdigest()
|
|
87
|
+
print(f"build index for {file_path} md5: {md5}")
|
|
88
|
+
if source.source_code.strip() == "":
|
|
89
|
+
continue
|
|
90
|
+
|
|
91
|
+
if source.module_name in index_data and index_data[source.module_name]["md5"] == md5:
|
|
92
|
+
continue
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
symbols = self.get_all_file_symbols(source.module_name, source.source_code)
|
|
96
|
+
time.sleep(self.anti_quota_limit)
|
|
97
|
+
except Exception as e:
|
|
98
|
+
print(f"Error: {e}")
|
|
99
|
+
continue
|
|
100
|
+
|
|
101
|
+
index_data[source.module_name] = {
|
|
102
|
+
"symbols": symbols,
|
|
103
|
+
"last_modified": os.path.getmtime(file_path),
|
|
104
|
+
"md5": md5
|
|
105
|
+
}
|
|
106
|
+
updated_sources.append(source)
|
|
107
|
+
|
|
108
|
+
if updated_sources:
|
|
109
|
+
with open(self.index_file, "w") as file:
|
|
110
|
+
json.dump(index_data, file, ensure_ascii=False, indent=2)
|
|
111
|
+
|
|
112
|
+
return index_data
|
|
113
|
+
|
|
114
|
+
def read_index(self) -> List[IndexItem]:
|
|
115
|
+
if not os.path.exists(self.index_file):
|
|
116
|
+
return []
|
|
117
|
+
|
|
118
|
+
with open(self.index_file, "r") as file:
|
|
119
|
+
index_data = json.load(file)
|
|
120
|
+
|
|
121
|
+
index_items = []
|
|
122
|
+
for module_name, data in index_data.items():
|
|
123
|
+
index_item = IndexItem(
|
|
124
|
+
module_name=module_name,
|
|
125
|
+
symbols=data["symbols"],
|
|
126
|
+
last_modified=data["last_modified"],
|
|
127
|
+
md5=data["md5"]
|
|
128
|
+
)
|
|
129
|
+
index_items.append(index_item)
|
|
130
|
+
|
|
131
|
+
return index_items
|
|
132
|
+
|
|
133
|
+
def _get_meta_str(self):
|
|
134
|
+
index_items = self.read_index()
|
|
135
|
+
output = []
|
|
136
|
+
for item in index_items:
|
|
137
|
+
output.append(f"##{item.module_name}\n{item.symbols}\n\n")
|
|
138
|
+
return "".join(output)
|
|
139
|
+
|
|
140
|
+
def get_related_files(self,file_paths:List[str]):
|
|
141
|
+
return self._get_related_files(self._get_meta_str(),"\n".join(file_paths))
|
|
142
|
+
|
|
143
|
+
@byzerllm.prompt(lambda self: self.llm, render="jinja2",print_prompt=True)
|
|
144
|
+
def _get_target_files_by_query(self,indices:str,query:str)->FileList:
|
|
145
|
+
'''
|
|
146
|
+
下面是所有文件以及对应的符号信息:
|
|
147
|
+
|
|
148
|
+
{{ indices }}
|
|
149
|
+
|
|
150
|
+
请参考上面的信息,根据用户的问题寻找相关文件。如果没有相关的文件,返回空即可。
|
|
151
|
+
|
|
152
|
+
用户的问题是:{{ query }}
|
|
153
|
+
'''
|
|
154
|
+
|
|
155
|
+
def get_target_files_by_query(self,query:str)->FileList:
|
|
156
|
+
return self._get_target_files_by_query(self._get_meta_str(),query)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.6"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.4"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|