auto-coder 0.1.183__py3-none-any.whl → 0.1.184__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.183.dist-info → auto_coder-0.1.184.dist-info}/METADATA +2 -2
- {auto_coder-0.1.183.dist-info → auto_coder-0.1.184.dist-info}/RECORD +20 -14
- autocoder/auto_coder.py +136 -17
- autocoder/auto_coder_lang.py +14 -2
- autocoder/auto_coder_rag.py +92 -1
- autocoder/chat_auto_coder.py +25 -32
- autocoder/common/__init__.py +2 -0
- autocoder/rag/cache/__init__.py +0 -0
- autocoder/rag/cache/base_cache.py +14 -0
- autocoder/rag/cache/byzer_storage_cache.py +394 -0
- autocoder/rag/cache/file_monitor_cache.py +146 -0
- autocoder/rag/cache/simple_cache.py +204 -0
- autocoder/rag/document_retriever.py +56 -475
- autocoder/rag/long_context_rag.py +16 -6
- autocoder/rag/utils.py +133 -0
- autocoder/version.py +1 -1
- {auto_coder-0.1.183.dist-info → auto_coder-0.1.184.dist-info}/LICENSE +0 -0
- {auto_coder-0.1.183.dist-info → auto_coder-0.1.184.dist-info}/WHEEL +0 -0
- {auto_coder-0.1.183.dist-info → auto_coder-0.1.184.dist-info}/entry_points.txt +0 -0
- {auto_coder-0.1.183.dist-info → auto_coder-0.1.184.dist-info}/top_level.txt +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.184
|
|
4
4
|
Summary: AutoCoder: AutoCoder
|
|
5
5
|
Author: allwefantasy
|
|
6
6
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
@@ -26,7 +26,7 @@ Requires-Dist: tabulate
|
|
|
26
26
|
Requires-Dist: jupyter-client
|
|
27
27
|
Requires-Dist: prompt-toolkit
|
|
28
28
|
Requires-Dist: tokenizers
|
|
29
|
-
Requires-Dist: byzerllm[saas] >=0.1.
|
|
29
|
+
Requires-Dist: byzerllm[saas] >=0.1.137
|
|
30
30
|
Requires-Dist: patch
|
|
31
31
|
Requires-Dist: diff-match-patch
|
|
32
32
|
Requires-Dist: GitPython
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
autocoder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
autocoder/auto_coder.py,sha256=
|
|
3
|
-
autocoder/auto_coder_lang.py,sha256=
|
|
4
|
-
autocoder/auto_coder_rag.py,sha256=
|
|
2
|
+
autocoder/auto_coder.py,sha256=IyAWLMfw0ZoSkW3xXsc-XfC8feYbUYRQd5w49Z6I1Wg,36928
|
|
3
|
+
autocoder/auto_coder_lang.py,sha256=Rtupq6N3_HT7JRhDKdgCBcwRaiAnyCOR_Gsp4jUomrI,3229
|
|
4
|
+
autocoder/auto_coder_rag.py,sha256=flIIf-oj8Dkr8gk049rG0itze_M64SnfUsFGfdDIKa8,16034
|
|
5
5
|
autocoder/auto_coder_server.py,sha256=qRY88mkBnqSGFDcwYE5gwpe2WPhIw1nEH6LdbjCQhQk,20306
|
|
6
|
-
autocoder/chat_auto_coder.py,sha256=
|
|
6
|
+
autocoder/chat_auto_coder.py,sha256=1jCx-J83mj_8JnojYSTfPjYide-thbmsFbr12E_kgcQ,81773
|
|
7
7
|
autocoder/chat_auto_coder_lang.py,sha256=QYtu5gWEQmWKVovR_qUZ8plySZarNFX_Onk-1vN9IiA,8524
|
|
8
8
|
autocoder/command_args.py,sha256=ftWw6HnFUZPiQPt1oV-SfpHQe69XN3knaFy1lpROBcU,26854
|
|
9
9
|
autocoder/lang.py,sha256=e-07rYTgimpxS8sm-AxKSmH4kKQX4N05YFHJBg9trVs,12598
|
|
10
|
-
autocoder/version.py,sha256=
|
|
10
|
+
autocoder/version.py,sha256=QIoV_M2rk6XDGECmjmRmCu9WBMJogF97jr_VxixP1hc,23
|
|
11
11
|
autocoder/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
autocoder/agent/auto_tool.py,sha256=DBzip-P_T6ZtT2eHexPcusmKYD0h7ufzp7TLwXAY10E,11554
|
|
13
13
|
autocoder/agent/coder.py,sha256=dnITYHqkcOip8zV4lywbkYNH9w7Q3qyYaUArJ4WPrTs,866
|
|
@@ -17,7 +17,7 @@ autocoder/agent/project_reader.py,sha256=-MWRqsr7O4mvU0PIpAhOUBb29htZAvA37pa_GeE
|
|
|
17
17
|
autocoder/chat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
autocoder/common/JupyterClient.py,sha256=O-wi6pXeAEYhAY24kDa0BINrLYvKS6rKyWe98pDClS0,2816
|
|
19
19
|
autocoder/common/ShellClient.py,sha256=fM1q8t_XMSbLBl2zkCNC2J9xuyKN3eXzGm6hHhqL2WY,2286
|
|
20
|
-
autocoder/common/__init__.py,sha256=
|
|
20
|
+
autocoder/common/__init__.py,sha256=AeO4fr0guA87tgYoE-pwKe0d5tc3yu-Z58UbYU2G_b4,10360
|
|
21
21
|
autocoder/common/anything2images.py,sha256=0ILBbWzY02M-CiWB-vzuomb_J1hVdxRcenAfIrAXq9M,25283
|
|
22
22
|
autocoder/common/audio.py,sha256=Kn9nWKQddWnUrAz0a_ZUgjcu4VUU_IcZBigT7n3N3qc,7439
|
|
23
23
|
autocoder/common/cleaner.py,sha256=NU72i8C6o9m0vXExab7nao5bstBUsfJFcj11cXa9l4U,1089
|
|
@@ -60,9 +60,9 @@ autocoder/pyproject/__init__.py,sha256=-2-ImQVw6e3NQZQOyDlHEP5b4xVs5ur2G5izB-JCa
|
|
|
60
60
|
autocoder/rag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
61
61
|
autocoder/rag/api_server.py,sha256=zokIlDJlk7ucRorSLQm80uICO1mecfmn4J2zVqEBskE,6786
|
|
62
62
|
autocoder/rag/doc_filter.py,sha256=Ha0Yae_G_hF72YzvrO7NoDZcG18K4hRcqGAEqfrIwAs,9330
|
|
63
|
-
autocoder/rag/document_retriever.py,sha256=
|
|
63
|
+
autocoder/rag/document_retriever.py,sha256=_jCbCEX0I-5UPWuHocESaWHatQcv1r_DqA0yOfOAiZ0,9092
|
|
64
64
|
autocoder/rag/llm_wrapper.py,sha256=xRbTBpLUH43Ah5jplL8WWWU-kjKfNgEJoUntLGBq5F4,2484
|
|
65
|
-
autocoder/rag/long_context_rag.py,sha256=
|
|
65
|
+
autocoder/rag/long_context_rag.py,sha256=8mcw4KarLI1MkmFvxyh44YVOJnbbEAnosVE19mKEJPE,21090
|
|
66
66
|
autocoder/rag/rag_config.py,sha256=8LwFcTd8OJWWwi1_WY4IzjqgtT6RyE2j4PjxS5cCTDE,802
|
|
67
67
|
autocoder/rag/rag_entry.py,sha256=V1RJ8RGqM30DNPmzymv64rZjNRGWn6kfc8sRy_LECg0,2451
|
|
68
68
|
autocoder/rag/raw_rag.py,sha256=yS2Ur6kG0IRjhCj2_VonwxjY_xls_E62jO5Gz5j2nqE,2952
|
|
@@ -73,7 +73,13 @@ autocoder/rag/token_checker.py,sha256=jc76x6KWmvVxds6W8juZfQGaoErudc2HenG3sNQfSL
|
|
|
73
73
|
autocoder/rag/token_counter.py,sha256=LReZEYXmWriDI3KYjUvK0E4Gn4MeDJX6RPCfJCmluGY,2110
|
|
74
74
|
autocoder/rag/token_limiter.py,sha256=4cGy2kFCvbsM5CtONfuvLmXgpK_1HZTHehLTob08eks,10959
|
|
75
75
|
autocoder/rag/types.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
76
|
+
autocoder/rag/utils.py,sha256=6LkPuMglUw_Wl0RdQI5x6TnQ4K_J3U8Siia4d1LdPy4,4963
|
|
76
77
|
autocoder/rag/variable_holder.py,sha256=PFvBjFcR7-fNDD4Vcsc8CpH2Te057vcpwJMxtrfUgKI,75
|
|
78
|
+
autocoder/rag/cache/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
79
|
+
autocoder/rag/cache/base_cache.py,sha256=Dsx4JhNgEh_Scgb0ZMms-QtjGNyYGi_8KYxijHmqJe4,398
|
|
80
|
+
autocoder/rag/cache/byzer_storage_cache.py,sha256=wEwagiQw8SDM2Opy0AAhQKfCMw304FV3D8JP4Nyx7i0,14625
|
|
81
|
+
autocoder/rag/cache/file_monitor_cache.py,sha256=-h679zDz3mgqk5VWvCqELn-FBCT4vUZzmLyry2nkImo,4930
|
|
82
|
+
autocoder/rag/cache/simple_cache.py,sha256=6jR_-l_n_nJaF6crSHHCnIHpcA8sI6je9Q8ppYJXLrA,7399
|
|
77
83
|
autocoder/rag/loaders/__init__.py,sha256=EQHEZ5Cmz-mGP2SllUTvcIbYCnF7W149dNpNItfs0yE,304
|
|
78
84
|
autocoder/rag/loaders/docx_loader.py,sha256=g6Ta8rMUbfgwB8N1qiajhyO6wpaWl7zygAZiKShuioI,174
|
|
79
85
|
autocoder/rag/loaders/excel_loader.py,sha256=Ue8YB1z_kBs8SjIPuBskyM08Q1JiONs_BJZPrzi59oo,896
|
|
@@ -95,9 +101,9 @@ autocoder/utils/request_event_queue.py,sha256=r3lo5qGsB1dIjzVQ05dnr0z_9Z3zOkBdP1
|
|
|
95
101
|
autocoder/utils/request_queue.py,sha256=nwp6PMtgTCiuwJI24p8OLNZjUiprC-TsefQrhMI-yPE,3889
|
|
96
102
|
autocoder/utils/rest.py,sha256=3tXA8KZG6jKz_tddHNLGx77Icee88WcUeesfNsgPno4,8790
|
|
97
103
|
autocoder/utils/tests.py,sha256=BqphrwyycGAvs-5mhH8pKtMZdObwhFtJ5MC_ZAOiLq8,1340
|
|
98
|
-
auto_coder-0.1.
|
|
99
|
-
auto_coder-0.1.
|
|
100
|
-
auto_coder-0.1.
|
|
101
|
-
auto_coder-0.1.
|
|
102
|
-
auto_coder-0.1.
|
|
103
|
-
auto_coder-0.1.
|
|
104
|
+
auto_coder-0.1.184.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
105
|
+
auto_coder-0.1.184.dist-info/METADATA,sha256=EdhJTLk-vUjeGVeiqRMrHL9uskG3IcVXWLZ1ZRYBlBg,2352
|
|
106
|
+
auto_coder-0.1.184.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
107
|
+
auto_coder-0.1.184.dist-info/entry_points.txt,sha256=0nzHtHH4pNcM7xq4EBA2toS28Qelrvcbrr59GqD_0Ak,350
|
|
108
|
+
auto_coder-0.1.184.dist-info/top_level.txt,sha256=Jqc0_uJSw2GwoFQAa9iJxYns-2mWla-9ok_Y3Gcznjk,10
|
|
109
|
+
auto_coder-0.1.184.dist-info/RECORD,,
|
autocoder/auto_coder.py
CHANGED
|
@@ -385,7 +385,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
385
385
|
|
|
386
386
|
llm.setup_template(model=args.model, template="auto")
|
|
387
387
|
llm.setup_default_model_name(args.model)
|
|
388
|
-
|
|
388
|
+
|
|
389
389
|
llm.setup_max_output_length(args.model, args.model_max_length)
|
|
390
390
|
llm.setup_max_input_length(args.model, args.model_max_input_length)
|
|
391
391
|
llm.setup_extra_generation_params(
|
|
@@ -395,7 +395,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
395
395
|
if args.chat_model:
|
|
396
396
|
chat_model = byzerllm.ByzerLLM()
|
|
397
397
|
chat_model.setup_default_model_name(args.chat_model)
|
|
398
|
-
llm.setup_sub_client("chat_model", chat_model)
|
|
398
|
+
llm.setup_sub_client("chat_model", chat_model)
|
|
399
399
|
|
|
400
400
|
if args.vl_model:
|
|
401
401
|
vl_model = byzerllm.ByzerLLM()
|
|
@@ -642,22 +642,24 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
642
642
|
)
|
|
643
643
|
)
|
|
644
644
|
return
|
|
645
|
-
|
|
645
|
+
|
|
646
646
|
elif raw_args.agent_command == "designer":
|
|
647
|
-
from autocoder.agent.designer import SVGDesigner, SDDesigner
|
|
647
|
+
from autocoder.agent.designer import SVGDesigner, SDDesigner
|
|
648
|
+
|
|
648
649
|
if args.agent_designer_mode == "svg":
|
|
649
650
|
designer = SVGDesigner(args, llm)
|
|
650
|
-
designer.run(args.query)
|
|
651
|
+
designer.run(args.query)
|
|
651
652
|
print("Successfully generated image in output.png")
|
|
652
653
|
elif args.agent_designer_mode == "sd":
|
|
653
654
|
designer = SDDesigner(args, llm)
|
|
654
|
-
designer.run(args.query)
|
|
655
|
+
designer.run(args.query)
|
|
655
656
|
print("Successfully generated image in output.jpg")
|
|
656
657
|
if args.request_id:
|
|
657
658
|
request_queue.add_request(
|
|
658
659
|
args.request_id,
|
|
659
660
|
RequestValue(
|
|
660
|
-
value=DefaultValue(value=
|
|
661
|
+
value=DefaultValue(value="Successfully generated image"),
|
|
662
|
+
status=RequestOption.COMPLETED,
|
|
661
663
|
),
|
|
662
664
|
)
|
|
663
665
|
return
|
|
@@ -693,6 +695,12 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
693
695
|
{"role": "user", "content": args.query}
|
|
694
696
|
)
|
|
695
697
|
|
|
698
|
+
if llm.get_sub_client("chat_model"):
|
|
699
|
+
chat_llm = llm.get_sub_client("chat_model")
|
|
700
|
+
else:
|
|
701
|
+
chat_llm = llm
|
|
702
|
+
|
|
703
|
+
source_count = 0
|
|
696
704
|
pre_conversations = []
|
|
697
705
|
if args.context:
|
|
698
706
|
context = json.loads(args.context)
|
|
@@ -701,25 +709,136 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
701
709
|
pre_conversations.append(
|
|
702
710
|
{
|
|
703
711
|
"role": "user",
|
|
704
|
-
"content": f"
|
|
712
|
+
"content": f"下面是一些文档和源码,如果用户的问题和他们相关,请参考他们:\n{file_content}",
|
|
705
713
|
},
|
|
706
714
|
)
|
|
707
715
|
pre_conversations.append({"role": "assistant", "content": "read"})
|
|
716
|
+
source_count += 1
|
|
708
717
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
718
|
+
from autocoder.index.index import IndexManager, build_index_and_filter_files
|
|
719
|
+
from autocoder.pyproject import PyProject
|
|
720
|
+
from autocoder.tsproject import TSProject
|
|
721
|
+
from autocoder.suffixproject import SuffixProject
|
|
712
722
|
|
|
713
|
-
if
|
|
714
|
-
|
|
723
|
+
if args.project_type == "ts":
|
|
724
|
+
pp = TSProject(args=args, llm=llm)
|
|
725
|
+
elif args.project_type == "py":
|
|
726
|
+
pp = PyProject(args=args, llm=llm)
|
|
715
727
|
else:
|
|
716
|
-
|
|
728
|
+
pp = SuffixProject(args=args, llm=llm, file_filter=None)
|
|
729
|
+
pp.run()
|
|
730
|
+
sources = pp.sources
|
|
731
|
+
s = build_index_and_filter_files(llm=llm, args=args, sources=sources)
|
|
732
|
+
if s:
|
|
733
|
+
pre_conversations.append(
|
|
734
|
+
{
|
|
735
|
+
"role": "user",
|
|
736
|
+
"content": f"下面是一些文档和源码,如果用户的问题和他们相关,请参考他们:\n{s}",
|
|
737
|
+
}
|
|
738
|
+
)
|
|
739
|
+
pre_conversations.append({"role": "assistant", "content": "read"})
|
|
740
|
+
source_count += 1
|
|
741
|
+
|
|
742
|
+
loaded_conversations = pre_conversations + chat_history["ask_conversation"]
|
|
743
|
+
|
|
744
|
+
if args.human_as_model:
|
|
745
|
+
console = Console()
|
|
746
|
+
|
|
747
|
+
@byzerllm.prompt()
|
|
748
|
+
def chat_with_human_as_model(
|
|
749
|
+
source_codes, pre_conversations, last_conversation
|
|
750
|
+
):
|
|
751
|
+
"""
|
|
752
|
+
{% if source_codes %}
|
|
753
|
+
{{ source_codes }}
|
|
754
|
+
{% endif %}
|
|
755
|
+
|
|
756
|
+
{% if pre_conversations %}
|
|
757
|
+
历史对话:
|
|
758
|
+
{% for conv in pre_conversations %}
|
|
759
|
+
[{{ conv.role }}]: {{ conv.content }}
|
|
760
|
+
{% endfor %}
|
|
761
|
+
{% endif %}
|
|
762
|
+
|
|
763
|
+
用户的问题: {{ last_conversation.content }}
|
|
764
|
+
"""
|
|
765
|
+
|
|
766
|
+
source_codes_conversations = loaded_conversations[0 : source_count * 2]
|
|
767
|
+
source_codes = ""
|
|
768
|
+
for conv in source_codes_conversations:
|
|
769
|
+
if conv["role"] == "user":
|
|
770
|
+
source_codes += conv["content"]
|
|
771
|
+
|
|
772
|
+
chat_content = chat_with_human_as_model.prompt(
|
|
773
|
+
source_codes=source_codes,
|
|
774
|
+
pre_conversations=loaded_conversations[source_count * 2 : -1],
|
|
775
|
+
last_conversation=loaded_conversations[-1],
|
|
776
|
+
)
|
|
777
|
+
try:
|
|
778
|
+
import pyperclip
|
|
779
|
+
|
|
780
|
+
pyperclip.copy(chat_content)
|
|
781
|
+
console.print(
|
|
782
|
+
Panel(
|
|
783
|
+
get_message("chat_human_as_model_instructions"),
|
|
784
|
+
title="Instructions",
|
|
785
|
+
border_style="blue",
|
|
786
|
+
expand=False,
|
|
787
|
+
)
|
|
788
|
+
)
|
|
789
|
+
except Exception:
|
|
790
|
+
logger.warning(get_message("clipboard_not_supported"))
|
|
791
|
+
console.print(
|
|
792
|
+
Panel(
|
|
793
|
+
get_message("human_as_model_instructions_no_clipboard"),
|
|
794
|
+
title="Instructions",
|
|
795
|
+
border_style="blue",
|
|
796
|
+
expand=False,
|
|
797
|
+
)
|
|
798
|
+
)
|
|
799
|
+
return
|
|
800
|
+
# Save chat content to file
|
|
801
|
+
with open(args.target_file, "w") as f:
|
|
802
|
+
f.write(chat_content)
|
|
803
|
+
|
|
804
|
+
lines = []
|
|
805
|
+
while True:
|
|
806
|
+
line = prompt(FormattedText([("#00FF00", "> ")]), multiline=False)
|
|
807
|
+
line_lower = line.strip().lower()
|
|
808
|
+
if line_lower in ["eof", "/eof"]:
|
|
809
|
+
break
|
|
810
|
+
elif line_lower in ["/clear"]:
|
|
811
|
+
lines = []
|
|
812
|
+
print("\033[2J\033[H") # Clear terminal screen
|
|
813
|
+
continue
|
|
814
|
+
elif line_lower in ["/break"]:
|
|
815
|
+
raise Exception("User requested to break the operation.")
|
|
816
|
+
lines.append(line)
|
|
817
|
+
|
|
818
|
+
result = "\n".join(lines)
|
|
819
|
+
|
|
820
|
+
# Update chat history with user's response
|
|
821
|
+
chat_history["ask_conversation"].append(
|
|
822
|
+
{"role": "assistant", "content": result}
|
|
823
|
+
)
|
|
824
|
+
|
|
825
|
+
with open(memory_file, "w") as f:
|
|
826
|
+
json.dump(chat_history, f, ensure_ascii=False)
|
|
827
|
+
|
|
828
|
+
request_queue.add_request(
|
|
829
|
+
args.request_id,
|
|
830
|
+
RequestValue(
|
|
831
|
+
value=DefaultValue(value=result), status=RequestOption.COMPLETED
|
|
832
|
+
),
|
|
833
|
+
)
|
|
834
|
+
|
|
835
|
+
return {}
|
|
717
836
|
|
|
718
837
|
if args.enable_rag_search or args.enable_rag_context:
|
|
719
838
|
rag = RAGFactory.get_rag(llm=chat_llm, args=args, path="")
|
|
720
839
|
response = rag.stream_chat_oai(conversations=loaded_conversations)[0]
|
|
721
840
|
v = ([item, None] for item in response)
|
|
722
|
-
else:
|
|
841
|
+
else:
|
|
723
842
|
v = chat_llm.stream_chat_oai(
|
|
724
843
|
conversations=loaded_conversations, delta_mode=True
|
|
725
844
|
)
|
|
@@ -813,7 +932,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
813
932
|
llm, args, code_auto_execute.Mode.SINGLE_ROUND
|
|
814
933
|
)
|
|
815
934
|
executor.run(query=args.query, context=s, source_code="")
|
|
816
|
-
return
|
|
935
|
+
return
|
|
817
936
|
elif raw_args.doc_command == "serve":
|
|
818
937
|
|
|
819
938
|
from autocoder.rag.llm_wrapper import LLWrapper
|
|
@@ -838,7 +957,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
838
957
|
llm_wrapper = LLWrapper(llm=llm, rag=rag)
|
|
839
958
|
serve(llm=llm_wrapper, args=server_args)
|
|
840
959
|
return
|
|
841
|
-
|
|
960
|
+
|
|
842
961
|
elif raw_args.doc_command == "chat":
|
|
843
962
|
from autocoder.rag.rag_entry import RAGFactory
|
|
844
963
|
|
autocoder/auto_coder_lang.py
CHANGED
|
@@ -16,7 +16,13 @@ MESSAGES = {
|
|
|
16
16
|
"The system is waiting for your input. When finished, enter 'EOF' on a new line to submit.\n"
|
|
17
17
|
"Use '/break' to exit this mode. If you have issues with copy-paste, use '/clear' to clean and paste again."
|
|
18
18
|
),
|
|
19
|
-
|
|
19
|
+
"chat_human_as_model_instructions": (
|
|
20
|
+
"Chat is now in Human as Model mode.\n"
|
|
21
|
+
"The question has been copied to your clipboard.\n"
|
|
22
|
+
"Please use Web version model to get the answer.\n"
|
|
23
|
+
"Or use /conf human_as_model:false to close this mode and get the answer in terminal directly."
|
|
24
|
+
"Paste the answer to the input box below, use '/break' to exit, '/clear' to clear the screen, '/eof' to submit."
|
|
25
|
+
)
|
|
20
26
|
},
|
|
21
27
|
"zh": {
|
|
22
28
|
"human_as_model_instructions": (
|
|
@@ -33,7 +39,13 @@ MESSAGES = {
|
|
|
33
39
|
"系统正在等待您的输入。完成后,在新行输入'EOF'提交。\n"
|
|
34
40
|
"使用'/break'退出此模式。如果复制粘贴有问题,使用'/clear'清理并重新粘贴。"
|
|
35
41
|
),
|
|
36
|
-
|
|
42
|
+
"chat_human_as_model_instructions": (
|
|
43
|
+
"\n============= Chat 处于 Human as Model 模式 =============\n"
|
|
44
|
+
"问题已复制到剪贴板\n"
|
|
45
|
+
"请使用Web版本模型获取答案\n"
|
|
46
|
+
"或者使用 /conf human_as_model:false 关闭该模式直接在终端获得答案。"
|
|
47
|
+
"将获得答案黏贴到下面的输入框,换行后,使用 '/break' 退出,'/clear' 清屏,'/eof' 提交。"
|
|
48
|
+
),
|
|
37
49
|
}
|
|
38
50
|
}
|
|
39
51
|
|
autocoder/auto_coder_rag.py
CHANGED
|
@@ -17,6 +17,7 @@ import shlex
|
|
|
17
17
|
from rich.console import Console
|
|
18
18
|
from rich.table import Table
|
|
19
19
|
import os
|
|
20
|
+
from loguru import logger
|
|
20
21
|
|
|
21
22
|
from autocoder.rag.document_retriever import process_file_local
|
|
22
23
|
from autocoder.rag.token_counter import TokenCounter
|
|
@@ -144,6 +145,20 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
144
145
|
parser = argparse.ArgumentParser(description="Auto Coder RAG Server")
|
|
145
146
|
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
146
147
|
|
|
148
|
+
# Build hybrid index command
|
|
149
|
+
build_index_parser = subparsers.add_parser("build_hybrid_index", help="Build hybrid index for RAG")
|
|
150
|
+
build_index_parser.add_argument("--quick", action="store_true", help="Skip system initialization")
|
|
151
|
+
build_index_parser.add_argument("--file", default="", help=desc["file"])
|
|
152
|
+
build_index_parser.add_argument("--model", default="deepseek_chat", help=desc["model"])
|
|
153
|
+
build_index_parser.add_argument("--index_model", default="", help=desc["index_model"])
|
|
154
|
+
build_index_parser.add_argument("--emb_model", default="", help=desc["emb_model"])
|
|
155
|
+
build_index_parser.add_argument("--ray_address", default="auto", help=desc["ray_address"])
|
|
156
|
+
build_index_parser.add_argument("--required_exts", default="", help=desc["doc_build_parse_required_exts"])
|
|
157
|
+
build_index_parser.add_argument("--source_dir", default=".", help="Source directory path")
|
|
158
|
+
build_index_parser.add_argument("--tokenizer_path", default="", help="Path to tokenizer file")
|
|
159
|
+
build_index_parser.add_argument("--doc_dir", default="", help="Document directory path")
|
|
160
|
+
build_index_parser.add_argument("--enable_hybrid_index", action="store_true", help="Enable hybrid index")
|
|
161
|
+
|
|
147
162
|
# Serve command
|
|
148
163
|
serve_parser = subparsers.add_parser("serve", help="Start the RAG server")
|
|
149
164
|
serve_parser.add_argument(
|
|
@@ -242,6 +257,18 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
242
257
|
help="Enable deep thought in inference mode",
|
|
243
258
|
)
|
|
244
259
|
|
|
260
|
+
serve_parser.add_argument(
|
|
261
|
+
"--enable_hybrid_index",
|
|
262
|
+
action="store_true",
|
|
263
|
+
help="Enable hybrid index",
|
|
264
|
+
)
|
|
265
|
+
serve_parser.add_argument(
|
|
266
|
+
"--hybrid_index_max_output_tokens",
|
|
267
|
+
type=int,
|
|
268
|
+
default=1000000,
|
|
269
|
+
help="The maximum number of tokens in the output. This is only used when enable_hybrid_index is true.",
|
|
270
|
+
)
|
|
271
|
+
|
|
245
272
|
# Tools command
|
|
246
273
|
tools_parser = subparsers.add_parser("tools", help="Various tools")
|
|
247
274
|
tools_subparsers = tools_parser.add_subparsers(dest="tool", help="Available tools")
|
|
@@ -275,10 +302,28 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
275
302
|
}
|
|
276
303
|
)
|
|
277
304
|
|
|
278
|
-
|
|
305
|
+
if auto_coder_args.enable_hybrid_index:
|
|
306
|
+
# 尝试连接storage
|
|
307
|
+
try:
|
|
308
|
+
from byzerllm.apps.byzer_storage.simple_api import ByzerStorage
|
|
309
|
+
storage = ByzerStorage("byzerai_store", "rag", "files")
|
|
310
|
+
storage.retrieval.cluster_info("byzerai_store")
|
|
311
|
+
except Exception as e:
|
|
312
|
+
logger.error("When enable_hybrid_index is true, ByzerStorage must be started")
|
|
313
|
+
logger.error("Please run 'byzerllm storage start' first")
|
|
314
|
+
return
|
|
315
|
+
else:
|
|
316
|
+
byzerllm.connect_cluster(address=args.ray_address)
|
|
279
317
|
llm = byzerllm.ByzerLLM()
|
|
280
318
|
llm.setup_default_model_name(args.model)
|
|
281
319
|
|
|
320
|
+
# 当启用hybrid_index时,检查必要的组件
|
|
321
|
+
if auto_coder_args.enable_hybrid_index:
|
|
322
|
+
if not llm.is_model_exist("emb"):
|
|
323
|
+
logger.error("When enable_hybrid_index is true, an 'emb' model must be deployed")
|
|
324
|
+
return
|
|
325
|
+
llm.setup_default_emb_model_name("emb")
|
|
326
|
+
|
|
282
327
|
if server_args.doc_dir:
|
|
283
328
|
auto_coder_args.rag_type = "simple"
|
|
284
329
|
rag = RAGFactory.get_rag(
|
|
@@ -292,6 +337,52 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
292
337
|
|
|
293
338
|
llm_wrapper = LLWrapper(llm=llm, rag=rag)
|
|
294
339
|
serve(llm=llm_wrapper, args=server_args)
|
|
340
|
+
elif args.command == "build_hybrid_index":
|
|
341
|
+
if not args.quick:
|
|
342
|
+
initialize_system()
|
|
343
|
+
|
|
344
|
+
auto_coder_args = AutoCoderArgs(
|
|
345
|
+
**{
|
|
346
|
+
arg: getattr(args, arg)
|
|
347
|
+
for arg in vars(AutoCoderArgs())
|
|
348
|
+
if hasattr(args, arg)
|
|
349
|
+
}
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
auto_coder_args.enable_hybrid_index = True
|
|
353
|
+
auto_coder_args.rag_type = "simple"
|
|
354
|
+
|
|
355
|
+
try:
|
|
356
|
+
from byzerllm.apps.byzer_storage.simple_api import ByzerStorage
|
|
357
|
+
storage = ByzerStorage("byzerai_store", "rag", "files")
|
|
358
|
+
storage.retrieval.cluster_info("byzerai_store")
|
|
359
|
+
except Exception as e:
|
|
360
|
+
logger.error("When enable_hybrid_index is true, ByzerStorage must be started")
|
|
361
|
+
logger.error("Please run 'byzerllm storage start' first")
|
|
362
|
+
return
|
|
363
|
+
|
|
364
|
+
llm = byzerllm.ByzerLLM()
|
|
365
|
+
llm.setup_default_model_name(args.model)
|
|
366
|
+
|
|
367
|
+
# 当启用hybrid_index时,检查必要的组件
|
|
368
|
+
if auto_coder_args.enable_hybrid_index:
|
|
369
|
+
if not llm.is_model_exist("emb"):
|
|
370
|
+
logger.error("When enable_hybrid_index is true, an 'emb' model must be deployed")
|
|
371
|
+
return
|
|
372
|
+
llm.setup_default_emb_model_name("emb")
|
|
373
|
+
|
|
374
|
+
rag = RAGFactory.get_rag(
|
|
375
|
+
llm=llm,
|
|
376
|
+
args=auto_coder_args,
|
|
377
|
+
path=args.doc_dir,
|
|
378
|
+
tokenizer_path=args.tokenizer_path,
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
if hasattr(rag.document_retriever, "cacher"):
|
|
382
|
+
rag.document_retriever.cacher.build_cache()
|
|
383
|
+
else:
|
|
384
|
+
logger.error("The document retriever does not support hybrid index building")
|
|
385
|
+
|
|
295
386
|
elif args.command == "tools" and args.tool == "count":
|
|
296
387
|
# auto-coder.rag tools count --tokenizer_path /Users/allwefantasy/Downloads/tokenizer.json --file /Users/allwefantasy/data/yum/schema/schema.xlsx
|
|
297
388
|
count_tokens(args.tokenizer_path, args.file)
|
autocoder/chat_auto_coder.py
CHANGED
|
@@ -718,8 +718,8 @@ class CommandCompleter(Completer):
|
|
|
718
718
|
|
|
719
719
|
parser.coding()
|
|
720
720
|
current_word = parser.current_word()
|
|
721
|
-
|
|
722
|
-
if len(new_text.strip()) == 0 or new_text.strip()=="/":
|
|
721
|
+
|
|
722
|
+
if len(new_text.strip()) == 0 or new_text.strip() == "/":
|
|
723
723
|
for command in parser.get_sub_commands():
|
|
724
724
|
if command.startswith(current_word):
|
|
725
725
|
yield Completion(command, start_position=-len(current_word))
|
|
@@ -797,7 +797,7 @@ class CommandCompleter(Completer):
|
|
|
797
797
|
start_position=-len(name),
|
|
798
798
|
display=f"{symbol.symbol_name} ({display_name}/{symbol.symbol_type})",
|
|
799
799
|
)
|
|
800
|
-
|
|
800
|
+
|
|
801
801
|
tags = [tag for tag in parser.tags]
|
|
802
802
|
|
|
803
803
|
if current_word.startswith("<"):
|
|
@@ -810,7 +810,7 @@ class CommandCompleter(Completer):
|
|
|
810
810
|
)
|
|
811
811
|
elif tag.startswith(name):
|
|
812
812
|
yield Completion(tag, start_position=-len(current_word))
|
|
813
|
-
|
|
813
|
+
|
|
814
814
|
if tags and tags[-1].start_tag == "<img>" and tags[-1].end_tag == "":
|
|
815
815
|
raw_file_name = tags[0].content
|
|
816
816
|
file_name = raw_file_name.strip()
|
|
@@ -932,7 +932,7 @@ class CommandCompleter(Completer):
|
|
|
932
932
|
field_name + ":"
|
|
933
933
|
for field_name in AutoCoderArgs.model_fields.keys()
|
|
934
934
|
if field_name.startswith(current_word)
|
|
935
|
-
]
|
|
935
|
+
]
|
|
936
936
|
|
|
937
937
|
for completion in completions:
|
|
938
938
|
yield Completion(completion, start_position=-len(current_word))
|
|
@@ -1489,46 +1489,39 @@ def coding(query: str):
|
|
|
1489
1489
|
@byzerllm.prompt()
|
|
1490
1490
|
def code_review(query: str) -> str:
|
|
1491
1491
|
"""
|
|
1492
|
-
|
|
1493
|
-
|
|
1492
|
+
对代码进行review,参考如下检查点。
|
|
1494
1493
|
1. 有没有调用不符合方法,类的签名的调用
|
|
1495
|
-
2.
|
|
1494
|
+
2. 有没有未声明直接使用的变量,方法,类
|
|
1496
1495
|
3. 有没有明显的语法错误
|
|
1497
|
-
4.
|
|
1498
|
-
|
|
1499
|
-
|
|
1496
|
+
4. 如果是python代码,检查有没有缩进方面的错误
|
|
1497
|
+
5. 如果是python代码,检查是否 try 后面缺少 except 或者 finally
|
|
1498
|
+
{% if query %}
|
|
1499
|
+
6. 用户的额外的检查需求:{{ query }}
|
|
1500
|
+
{% endif %}
|
|
1501
|
+
|
|
1502
|
+
如果用户的需求包含了@一个文件名 或者 @@符号, 那么重点关注这些文件或者符号(函数,类)进行上述的review。
|
|
1503
|
+
review 过程中严格遵循上述的检查点,不要遗漏,没有发现异常的点直接跳过,只对发现的异常点,给出具体的修改后的代码。
|
|
1500
1504
|
"""
|
|
1501
1505
|
|
|
1502
1506
|
|
|
1503
1507
|
def chat(query: str):
|
|
1504
1508
|
conf = memory.get("conf", {})
|
|
1505
|
-
|
|
1506
|
-
return_paths=True
|
|
1507
|
-
)
|
|
1508
|
-
|
|
1509
|
-
file_contents = []
|
|
1510
|
-
for file in current_files:
|
|
1511
|
-
if os.path.exists(file):
|
|
1512
|
-
try:
|
|
1513
|
-
with open(file, "r") as f:
|
|
1514
|
-
content = f.read()
|
|
1515
|
-
s = f"##File: {file}\n{content}\n\n"
|
|
1516
|
-
file_contents.append(s)
|
|
1517
|
-
except Exception as e:
|
|
1518
|
-
print(f"Failed to read file: {file}. Error: {str(e)}")
|
|
1519
|
-
|
|
1520
|
-
all_file_content = "".join(file_contents)
|
|
1521
|
-
|
|
1509
|
+
|
|
1522
1510
|
yaml_config = {
|
|
1523
1511
|
"include_file": ["./base/base.yml"],
|
|
1524
|
-
"include_project_structure": conf.get("include_project_structure", "true")
|
|
1525
|
-
== "true",
|
|
1512
|
+
"include_project_structure": conf.get("include_project_structure", "true") in ["true","True"],
|
|
1513
|
+
"human_as_model": conf.get("human_as_model", "false") == "true",
|
|
1514
|
+
"skip_build_index": conf.get("skip_build_index", "true") == "true",
|
|
1515
|
+
"skip_confirm": conf.get("skip_confirm", "true") == "true",
|
|
1516
|
+
"silence": conf.get("silence", "true") == "true",
|
|
1526
1517
|
}
|
|
1527
1518
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1519
|
+
current_files = memory["current_files"]["files"] + get_llm_friendly_package_docs(
|
|
1520
|
+
return_paths=True
|
|
1530
1521
|
)
|
|
1531
1522
|
|
|
1523
|
+
yaml_config["urls"] = current_files
|
|
1524
|
+
|
|
1532
1525
|
if "emb_model" in conf:
|
|
1533
1526
|
yaml_config["emb_model"] = conf["emb_model"]
|
|
1534
1527
|
|
autocoder/common/__init__.py
CHANGED
|
@@ -282,8 +282,10 @@ class AutoCoderArgs(pydantic.BaseModel):
|
|
|
282
282
|
command: Optional[str] = None
|
|
283
283
|
doc_command: Optional[str] = None
|
|
284
284
|
required_exts: Optional[str] = None
|
|
285
|
+
hybrid_index_max_output_tokens: Optional[int] = 1000000
|
|
285
286
|
|
|
286
287
|
monitor_mode: bool = False
|
|
288
|
+
enable_hybrid_index: bool = False
|
|
287
289
|
disable_auto_window: bool = False
|
|
288
290
|
disable_segment_reorder: bool = False
|
|
289
291
|
rag_doc_filter_relevance: int = 5
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
from typing import List, Tuple,Dict,Optional,Any
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
|
|
5
|
+
class DeleteEvent(BaseModel):
|
|
6
|
+
file_paths: List[str]
|
|
7
|
+
|
|
8
|
+
class AddOrUpdateEvent(BaseModel):
|
|
9
|
+
file_infos: List[Tuple[str, str, float]]
|
|
10
|
+
|
|
11
|
+
class BaseCacheManager(ABC):
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def get_cache(self,options:Optional[Dict[str,Any]]=None) -> Dict[str, Dict]:
|
|
14
|
+
pass
|