auto-coder 0.1.205__py3-none-any.whl → 0.1.207__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.205.dist-info → auto_coder-0.1.207.dist-info}/METADATA +1 -1
- {auto_coder-0.1.205.dist-info → auto_coder-0.1.207.dist-info}/RECORD +16 -10
- autocoder/agent/auto_filegroup.py +202 -0
- autocoder/auto_coder_rag.py +168 -33
- autocoder/benchmark.py +138 -0
- autocoder/chat_auto_coder.py +9 -3
- autocoder/common/chunk_validation.py +91 -0
- autocoder/common/recall_validation.py +58 -0
- autocoder/data/tokenizer.json +199865 -0
- autocoder/rag/token_counter.py +3 -3
- autocoder/utils/operate_config_api.py +148 -0
- autocoder/version.py +1 -1
- {auto_coder-0.1.205.dist-info → auto_coder-0.1.207.dist-info}/LICENSE +0 -0
- {auto_coder-0.1.205.dist-info → auto_coder-0.1.207.dist-info}/WHEEL +0 -0
- {auto_coder-0.1.205.dist-info → auto_coder-0.1.207.dist-info}/entry_points.txt +0 -0
- {auto_coder-0.1.205.dist-info → auto_coder-0.1.207.dist-info}/top_level.txt +0 -0
autocoder/rag/token_counter.py
CHANGED
|
@@ -21,11 +21,11 @@ class RemoteTokenCounter:
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def initialize_tokenizer(tokenizer_path):
|
|
24
|
-
global tokenizer_model
|
|
24
|
+
global tokenizer_model
|
|
25
25
|
tokenizer_model = Tokenizer.from_file(tokenizer_path)
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
def count_tokens(text: str) -> int:
|
|
28
|
+
def count_tokens(text: str) -> int:
|
|
29
29
|
try:
|
|
30
30
|
# start_time = time.time_ns()
|
|
31
31
|
encoded = VariableHolder.TOKENIZER_MODEL.encode('{"role":"user","content":"' + text + '"}')
|
|
@@ -33,7 +33,7 @@ def count_tokens(text: str) -> int:
|
|
|
33
33
|
# elapsed_time = time.time_ns() - start_time
|
|
34
34
|
# logger.info(f"Token counting took {elapsed_time/1000000} ms")
|
|
35
35
|
return v
|
|
36
|
-
except Exception as e:
|
|
36
|
+
except Exception as e:
|
|
37
37
|
logger.error(f"Error counting tokens: {str(e)}")
|
|
38
38
|
return -1
|
|
39
39
|
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
from autocoder.utils import get_last_yaml_file
|
|
2
|
+
import os
|
|
3
|
+
import uuid
|
|
4
|
+
import byzerllm
|
|
5
|
+
from autocoder.common import AutoCoderArgs
|
|
6
|
+
from typing import List, Optional
|
|
7
|
+
import yaml
|
|
8
|
+
from autocoder.auto_coder import AutoCoderArgs, load_include_files, Template
|
|
9
|
+
from autocoder.common import git_utils
|
|
10
|
+
import hashlib
|
|
11
|
+
|
|
12
|
+
# 该文件要给 chat,rag, web 等上层交互层使用
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def convert_yaml_to_config(yaml_file: str):
|
|
16
|
+
|
|
17
|
+
args = AutoCoderArgs()
|
|
18
|
+
with open(yaml_file, "r") as f:
|
|
19
|
+
config = yaml.safe_load(f)
|
|
20
|
+
config = load_include_files(config, yaml_file)
|
|
21
|
+
for key, value in config.items():
|
|
22
|
+
if key != "file": # 排除 --file 参数本身
|
|
23
|
+
# key: ENV {{VARIABLE_NAME}}
|
|
24
|
+
if isinstance(value, str) and value.startswith("ENV"):
|
|
25
|
+
template = Template(value.removeprefix("ENV").strip())
|
|
26
|
+
value = template.render(os.environ)
|
|
27
|
+
setattr(args, key, value)
|
|
28
|
+
return args
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def convert_yaml_config_to_str(yaml_config):
|
|
32
|
+
yaml_content = yaml.safe_dump(
|
|
33
|
+
yaml_config,
|
|
34
|
+
allow_unicode=True,
|
|
35
|
+
default_flow_style=False,
|
|
36
|
+
default_style=None,
|
|
37
|
+
)
|
|
38
|
+
return yaml_content
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def get_llm_friendly_package_docs(memory,
|
|
42
|
+
package_name: Optional[str] = None, return_paths: bool = False
|
|
43
|
+
) -> List[str]:
|
|
44
|
+
lib_dir = os.path.join(".auto-coder", "libs")
|
|
45
|
+
llm_friendly_packages_dir = os.path.join(lib_dir, "llm_friendly_packages")
|
|
46
|
+
docs = []
|
|
47
|
+
|
|
48
|
+
if not os.path.exists(llm_friendly_packages_dir):
|
|
49
|
+
print("llm_friendly_packages directory not found.")
|
|
50
|
+
return docs
|
|
51
|
+
|
|
52
|
+
libs = list(memory.get("libs", {}).keys())
|
|
53
|
+
|
|
54
|
+
for domain in os.listdir(llm_friendly_packages_dir):
|
|
55
|
+
domain_path = os.path.join(llm_friendly_packages_dir, domain)
|
|
56
|
+
if os.path.isdir(domain_path):
|
|
57
|
+
for username in os.listdir(domain_path):
|
|
58
|
+
username_path = os.path.join(domain_path, username)
|
|
59
|
+
if os.path.isdir(username_path):
|
|
60
|
+
for lib_name in os.listdir(username_path):
|
|
61
|
+
lib_path = os.path.join(username_path, lib_name)
|
|
62
|
+
if (
|
|
63
|
+
os.path.isdir(lib_path)
|
|
64
|
+
and (
|
|
65
|
+
package_name is None
|
|
66
|
+
or lib_name == package_name
|
|
67
|
+
or package_name == os.path.join(username, lib_name)
|
|
68
|
+
)
|
|
69
|
+
and lib_name in libs
|
|
70
|
+
):
|
|
71
|
+
for root, _, files in os.walk(lib_path):
|
|
72
|
+
for file in files:
|
|
73
|
+
if file.endswith(".md"):
|
|
74
|
+
file_path = os.path.join(root, file)
|
|
75
|
+
if return_paths:
|
|
76
|
+
docs.append(file_path)
|
|
77
|
+
else:
|
|
78
|
+
with open(file_path, "r") as f:
|
|
79
|
+
docs.append(f.read())
|
|
80
|
+
|
|
81
|
+
return docs
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def convert_config_value(key, value):
|
|
85
|
+
field_info = AutoCoderArgs.model_fields.get(key)
|
|
86
|
+
if field_info:
|
|
87
|
+
if value.lower() in ["true", "false"]:
|
|
88
|
+
return value.lower() == "true"
|
|
89
|
+
elif "int" in str(field_info.annotation):
|
|
90
|
+
return int(value)
|
|
91
|
+
elif "float" in str(field_info.annotation):
|
|
92
|
+
return float(value)
|
|
93
|
+
else:
|
|
94
|
+
return value
|
|
95
|
+
else:
|
|
96
|
+
print(f"Invalid configuration key: {key}")
|
|
97
|
+
return None
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def get_llm(memory, model:Optional[str]=None):
|
|
101
|
+
latest_yaml_file = get_last_yaml_file("actions")
|
|
102
|
+
|
|
103
|
+
conf = memory.get("conf", {})
|
|
104
|
+
current_files = memory["current_files"]["files"]
|
|
105
|
+
execute_file = None
|
|
106
|
+
|
|
107
|
+
if latest_yaml_file:
|
|
108
|
+
try:
|
|
109
|
+
execute_file = os.path.join("actions", latest_yaml_file)
|
|
110
|
+
yaml_config = {
|
|
111
|
+
"include_file": ["./base/base.yml"],
|
|
112
|
+
"auto_merge": conf.get("auto_merge", "editblock"),
|
|
113
|
+
"human_as_model": conf.get("human_as_model", "false") == "true",
|
|
114
|
+
"skip_build_index": conf.get("skip_build_index", "true") == "true",
|
|
115
|
+
"skip_confirm": conf.get("skip_confirm", "true") == "true",
|
|
116
|
+
"silence": conf.get("silence", "true") == "true",
|
|
117
|
+
"include_project_structure": conf.get("include_project_structure", "true")
|
|
118
|
+
== "true",
|
|
119
|
+
}
|
|
120
|
+
for key, value in conf.items():
|
|
121
|
+
converted_value = convert_config_value(key, value)
|
|
122
|
+
if converted_value is not None:
|
|
123
|
+
yaml_config[key] = converted_value
|
|
124
|
+
|
|
125
|
+
yaml_config["urls"] = current_files + get_llm_friendly_package_docs(
|
|
126
|
+
memory=memory,
|
|
127
|
+
return_paths=True
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# 临时保存yaml文件,然后读取yaml文件,转换为args
|
|
131
|
+
temp_yaml = os.path.join("actions", f"{uuid.uuid4()}.yml")
|
|
132
|
+
try:
|
|
133
|
+
with open(temp_yaml, "w") as f:
|
|
134
|
+
f.write(convert_yaml_config_to_str(
|
|
135
|
+
yaml_config=yaml_config))
|
|
136
|
+
args = convert_yaml_to_config(temp_yaml)
|
|
137
|
+
finally:
|
|
138
|
+
if os.path.exists(temp_yaml):
|
|
139
|
+
os.remove(temp_yaml)
|
|
140
|
+
|
|
141
|
+
llm = byzerllm.ByzerLLM.from_default_model(model or
|
|
142
|
+
args.code_model or args.model)
|
|
143
|
+
return llm
|
|
144
|
+
except Exception as e:
|
|
145
|
+
print(f"Failed to commit: {e}")
|
|
146
|
+
if execute_file:
|
|
147
|
+
os.remove(execute_file)
|
|
148
|
+
return None
|
autocoder/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.1.
|
|
1
|
+
__version__ = "0.1.207"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|