auto-coder 0.1.222__py3-none-any.whl → 0.1.224__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.
- {auto_coder-0.1.222.dist-info → auto_coder-0.1.224.dist-info}/METADATA +1 -1
- {auto_coder-0.1.222.dist-info → auto_coder-0.1.224.dist-info}/RECORD +16 -13
- autocoder/auto_coder.py +28 -11
- autocoder/auto_coder_rag_client_mcp.py +170 -0
- autocoder/auto_coder_rag_mcp.py +193 -0
- autocoder/chat_auto_coder.py +24 -4
- autocoder/common/__init__.py +2 -1
- autocoder/common/command_completer.py +1 -1
- autocoder/common/mcp_hub.py +4 -4
- autocoder/common/mcp_server.py +38 -38
- autocoder/common/memory_manager.py +112 -0
- autocoder/version.py +1 -1
- {auto_coder-0.1.222.dist-info → auto_coder-0.1.224.dist-info}/LICENSE +0 -0
- {auto_coder-0.1.222.dist-info → auto_coder-0.1.224.dist-info}/WHEEL +0 -0
- {auto_coder-0.1.222.dist-info → auto_coder-0.1.224.dist-info}/entry_points.txt +0 -0
- {auto_coder-0.1.222.dist-info → auto_coder-0.1.224.dist-info}/top_level.txt +0 -0
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
autocoder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
autocoder/auto_coder.py,sha256=
|
|
2
|
+
autocoder/auto_coder.py,sha256=Y6PqkMBr2ySUZkpik0XQxBNPA-QSwfn1-c2X7FZzU8g,44514
|
|
3
3
|
autocoder/auto_coder_lang.py,sha256=Rtupq6N3_HT7JRhDKdgCBcwRaiAnyCOR_Gsp4jUomrI,3229
|
|
4
4
|
autocoder/auto_coder_rag.py,sha256=illKgzP2bv-Tq50ujsofJnOHdI4pzr0ALtfR8NHHWdQ,22351
|
|
5
|
+
autocoder/auto_coder_rag_client_mcp.py,sha256=WV7j5JUiQge0x4-B7Hp5-pSAFXLbvLpzQMcCovbauIM,6276
|
|
6
|
+
autocoder/auto_coder_rag_mcp.py,sha256=-RrjNwFaS2e5v8XDIrKR-zlUNUE8UBaeOtojffBrvJo,8521
|
|
5
7
|
autocoder/auto_coder_server.py,sha256=XU9b4SBH7zjPPXaTWWHV4_zJm-XYa6njuLQaplYJH_c,20290
|
|
6
8
|
autocoder/benchmark.py,sha256=Ypomkdzd1T3GE6dRICY3Hj547dZ6_inqJbBJIp5QMco,4423
|
|
7
|
-
autocoder/chat_auto_coder.py,sha256=
|
|
9
|
+
autocoder/chat_auto_coder.py,sha256=kg2EwnM_uow4GuJJTpqQFZlWKEHfvJqRrq8VDiU422M,96173
|
|
8
10
|
autocoder/chat_auto_coder_lang.py,sha256=ReWukXKVvuzVvpbYk5O9kc1ev7XNmAv3DnuQhmpLmnc,8717
|
|
9
11
|
autocoder/command_args.py,sha256=9aYJ-AmPxP1sQh6ciw04FWHjSn31f2W9afXFwo8wgx4,30441
|
|
10
12
|
autocoder/lang.py,sha256=U6AjVV8Rs1uLyjFCZ8sT6WWuNUxMBqkXXIOs4S120uk,14511
|
|
11
|
-
autocoder/version.py,sha256=
|
|
13
|
+
autocoder/version.py,sha256=pM0K3Dh7ms0MYZItkrZfi3XRUP5_QdzhzyMOVUBuG8w,24
|
|
12
14
|
autocoder/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
15
|
autocoder/agent/auto_demand_organizer.py,sha256=NWSAEsEk94vT3lGjfo25kKLMwYdPcpy9e-i21txPasQ,6942
|
|
14
16
|
autocoder/agent/auto_filegroup.py,sha256=CW7bqp0FW1GIEMnl-blyAc2UGT7O9Mom0q66ITz1ckM,6635
|
|
@@ -21,7 +23,7 @@ autocoder/agent/project_reader.py,sha256=tWLaPoLw1gI6kO_NzivQj28KbobU2ceOLuppHMb
|
|
|
21
23
|
autocoder/chat/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
24
|
autocoder/common/JupyterClient.py,sha256=O-wi6pXeAEYhAY24kDa0BINrLYvKS6rKyWe98pDClS0,2816
|
|
23
25
|
autocoder/common/ShellClient.py,sha256=fM1q8t_XMSbLBl2zkCNC2J9xuyKN3eXzGm6hHhqL2WY,2286
|
|
24
|
-
autocoder/common/__init__.py,sha256=
|
|
26
|
+
autocoder/common/__init__.py,sha256=eKIjHf7oyERJxIkySycm9ZjLQcsS2s6zgy9xHFgJKy0,11534
|
|
25
27
|
autocoder/common/anything2images.py,sha256=0ILBbWzY02M-CiWB-vzuomb_J1hVdxRcenAfIrAXq9M,25283
|
|
26
28
|
autocoder/common/anything2img.py,sha256=4TREa-sOA-iargieUy7MpyCYVUE-9Mmq0wJtwomPqnE,7662
|
|
27
29
|
autocoder/common/audio.py,sha256=Kn9nWKQddWnUrAz0a_ZUgjcu4VUU_IcZBigT7n3N3qc,7439
|
|
@@ -38,7 +40,7 @@ autocoder/common/code_auto_merge_diff.py,sha256=5SI6ggklJ0QDHvsS0cpNXFuIkFRQxp1i
|
|
|
38
40
|
autocoder/common/code_auto_merge_editblock.py,sha256=l6yEiZqXyIlUNIIPXvkHOnLCIInXR78TzSjF-jtJkkg,17035
|
|
39
41
|
autocoder/common/code_auto_merge_strict_diff.py,sha256=ABYOTDUQYA4Bn4BwT1Rw812y49cHW3UH_JSpM9uJ6ig,9399
|
|
40
42
|
autocoder/common/code_modification_ranker.py,sha256=DFlbwgdg8GK47zVcvfZSzkyniEKmTVLTOWejjcVIgaw,5121
|
|
41
|
-
autocoder/common/command_completer.py,sha256=
|
|
43
|
+
autocoder/common/command_completer.py,sha256=sqCA4RkNJr8kkzUmsdMHz1oW5YRqb8Q_2oTq2D6GHlg,9194
|
|
42
44
|
autocoder/common/command_generator.py,sha256=v4LmU7sO-P7jEZIXCWHUC6P-vT7AvBi_x_PTwCqBAE8,1323
|
|
43
45
|
autocoder/common/command_templates.py,sha256=3G-pCNbL6iHbnkG6v1JZpbIK3Mc9d373_RYGmCcDPMY,8548
|
|
44
46
|
autocoder/common/const.py,sha256=eTjhjh4Aj4CUzviJ81jaf3Y5cwqsLATySn2wJxaS6RQ,2911
|
|
@@ -46,9 +48,10 @@ autocoder/common/git_utils.py,sha256=btK45sxvfm4tX3fBRNUPRZoGQuZuOEQrWSAwLy1yoLw
|
|
|
46
48
|
autocoder/common/image_to_page.py,sha256=O0cNO_vHHUP-fP4GXiVojShmNqkPnZXeIyiY1MRLpKg,13936
|
|
47
49
|
autocoder/common/interpreter.py,sha256=62-dIakOunYB4yjmX8SHC0Gdy2h8NtxdgbpdqRZJ5vk,2833
|
|
48
50
|
autocoder/common/llm_rerank.py,sha256=FbvtCzaR661Mt2wn0qsuiEL1Y3puD6jeIJS4zg_e7Bs,3260
|
|
49
|
-
autocoder/common/mcp_hub.py,sha256=
|
|
50
|
-
autocoder/common/mcp_server.py,sha256=
|
|
51
|
+
autocoder/common/mcp_hub.py,sha256=2ZyJv3Aiv4Y97UHut49oYhIFcu7ICR-mptDEBSgT3uE,14234
|
|
52
|
+
autocoder/common/mcp_server.py,sha256=QCFa-15kx7rbNsinwdGFFX2y47pww0fVdI-ldKFSSWI,12267
|
|
51
53
|
autocoder/common/mcp_tools.py,sha256=KsLvRrB6pvmebqd-lDaSH6IBJR0AIxWRE-dtCEG_w9k,12485
|
|
54
|
+
autocoder/common/memory_manager.py,sha256=2ZjYG7BPyvbYalZBF6AM_G5e10Qkw_zrqtD4Zd7GSsQ,3663
|
|
52
55
|
autocoder/common/recall_validation.py,sha256=Avt9Q9dX3kG6Pf2zsdlOHmsjd-OeSj7U1PFBDp_Cve0,1700
|
|
53
56
|
autocoder/common/screenshots.py,sha256=_gA-z1HxGjPShBrtgkdideq58MG6rqFB2qMUJKjrycs,3769
|
|
54
57
|
autocoder/common/search.py,sha256=245iPFgWhMldoUK3CqCP89ltaxZiNPK73evoG6Fp1h8,16518
|
|
@@ -122,9 +125,9 @@ autocoder/utils/request_event_queue.py,sha256=r3lo5qGsB1dIjzVQ05dnr0z_9Z3zOkBdP1
|
|
|
122
125
|
autocoder/utils/request_queue.py,sha256=nwp6PMtgTCiuwJI24p8OLNZjUiprC-TsefQrhMI-yPE,3889
|
|
123
126
|
autocoder/utils/rest.py,sha256=HawagAap3wMIDROGhY1730zSZrJR_EycODAA5qOj83c,8807
|
|
124
127
|
autocoder/utils/tests.py,sha256=BqphrwyycGAvs-5mhH8pKtMZdObwhFtJ5MC_ZAOiLq8,1340
|
|
125
|
-
auto_coder-0.1.
|
|
126
|
-
auto_coder-0.1.
|
|
127
|
-
auto_coder-0.1.
|
|
128
|
-
auto_coder-0.1.
|
|
129
|
-
auto_coder-0.1.
|
|
130
|
-
auto_coder-0.1.
|
|
128
|
+
auto_coder-0.1.224.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
129
|
+
auto_coder-0.1.224.dist-info/METADATA,sha256=SYaMyXGePmPYllfXaO9OJeGxrXQXyGBP1REPYottO6A,2615
|
|
130
|
+
auto_coder-0.1.224.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
131
|
+
auto_coder-0.1.224.dist-info/entry_points.txt,sha256=0nzHtHH4pNcM7xq4EBA2toS28Qelrvcbrr59GqD_0Ak,350
|
|
132
|
+
auto_coder-0.1.224.dist-info/top_level.txt,sha256=Jqc0_uJSw2GwoFQAa9iJxYns-2mWla-9ok_Y3Gcznjk,10
|
|
133
|
+
auto_coder-0.1.224.dist-info/RECORD,,
|
autocoder/auto_coder.py
CHANGED
|
@@ -40,6 +40,7 @@ from rich.panel import Panel
|
|
|
40
40
|
from rich.markdown import Markdown
|
|
41
41
|
from rich.live import Live
|
|
42
42
|
from autocoder.auto_coder_lang import get_message
|
|
43
|
+
from autocoder.common.memory_manager import save_to_memory_file
|
|
43
44
|
|
|
44
45
|
console = Console()
|
|
45
46
|
|
|
@@ -792,7 +793,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
792
793
|
pre_conversations.append(
|
|
793
794
|
{
|
|
794
795
|
"role": "user",
|
|
795
|
-
"content": f"
|
|
796
|
+
"content": f"请阅读下面的代码和文档:\n\n <files>\n{file_content}\n</files>",
|
|
796
797
|
},
|
|
797
798
|
)
|
|
798
799
|
pre_conversations.append(
|
|
@@ -819,7 +820,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
819
820
|
pre_conversations.append(
|
|
820
821
|
{
|
|
821
822
|
"role": "user",
|
|
822
|
-
"content": f"
|
|
823
|
+
"content": f"请阅读下面的代码和文档:\n\n <files>\n{s}\n</files>",
|
|
823
824
|
}
|
|
824
825
|
)
|
|
825
826
|
pre_conversations.append(
|
|
@@ -827,7 +828,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
827
828
|
source_count += 1
|
|
828
829
|
|
|
829
830
|
loaded_conversations = pre_conversations + \
|
|
830
|
-
chat_history["ask_conversation"]
|
|
831
|
+
chat_history["ask_conversation"]
|
|
831
832
|
|
|
832
833
|
if args.human_as_model:
|
|
833
834
|
console = Console()
|
|
@@ -836,12 +837,10 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
836
837
|
def chat_with_human_as_model(
|
|
837
838
|
source_codes, pre_conversations, last_conversation
|
|
838
839
|
):
|
|
839
|
-
"""
|
|
840
|
-
|
|
841
|
-
{% if source_codes %}
|
|
840
|
+
"""
|
|
841
|
+
{% if source_codes %}
|
|
842
842
|
{{ source_codes }}
|
|
843
|
-
{% endif %}
|
|
844
|
-
</files>
|
|
843
|
+
{% endif %}
|
|
845
844
|
|
|
846
845
|
{% if pre_conversations %}
|
|
847
846
|
下面是我们之间的历史对话,假设我是A,你是B。
|
|
@@ -853,7 +852,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
853
852
|
{% endif %}
|
|
854
853
|
|
|
855
854
|
|
|
856
|
-
|
|
855
|
+
参考上面的文件以及历史对话,回答用户的问题。
|
|
857
856
|
用户的问题: {{ last_conversation.content }}
|
|
858
857
|
"""
|
|
859
858
|
|
|
@@ -942,9 +941,14 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
942
941
|
),
|
|
943
942
|
)
|
|
944
943
|
|
|
944
|
+
if "save" in args.action:
|
|
945
|
+
save_to_memory_file(ask_conversation=chat_history["ask_conversation"],
|
|
946
|
+
query=args.query,
|
|
947
|
+
response=result)
|
|
948
|
+
print("Saved to your memory")
|
|
945
949
|
return {}
|
|
946
950
|
|
|
947
|
-
if args.action
|
|
951
|
+
if "rag" in args.action:
|
|
948
952
|
args.enable_rag_search = True
|
|
949
953
|
args.enable_rag_context = False
|
|
950
954
|
rag = RAGFactory.get_rag(llm=chat_llm, args=args, path="")
|
|
@@ -952,7 +956,7 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
952
956
|
conversations=[{"role": "user", "content": args.query}])[0]
|
|
953
957
|
v = ([item, None] for item in response)
|
|
954
958
|
|
|
955
|
-
elif args.action
|
|
959
|
+
elif "mcp" in args.action:
|
|
956
960
|
from autocoder.common.mcp_server import get_mcp_server, McpRequest, McpInstallRequest, McpRemoveRequest, McpListRequest, McpListRunningRequest, McpRefreshRequest
|
|
957
961
|
mcp_server = get_mcp_server()
|
|
958
962
|
response = mcp_server.send_request(
|
|
@@ -1027,6 +1031,19 @@ def main(input_args: Optional[List[str]] = None):
|
|
|
1027
1031
|
with open(memory_file, "w") as f:
|
|
1028
1032
|
json.dump(chat_history, f, ensure_ascii=False)
|
|
1029
1033
|
|
|
1034
|
+
if "copy" in args.action:
|
|
1035
|
+
#copy assistant_response to clipboard
|
|
1036
|
+
import pyperclip
|
|
1037
|
+
try:
|
|
1038
|
+
pyperclip.copy(assistant_response)
|
|
1039
|
+
except:
|
|
1040
|
+
print("pyperclip not installed or clipboard is not supported, instruction will not be copied to clipboard.")
|
|
1041
|
+
|
|
1042
|
+
if "save" in args.action:
|
|
1043
|
+
save_to_memory_file(ask_conversation=chat_history["ask_conversation"],
|
|
1044
|
+
query=args.query,
|
|
1045
|
+
response=assistant_response)
|
|
1046
|
+
print("Saved to your memory")
|
|
1030
1047
|
return
|
|
1031
1048
|
|
|
1032
1049
|
else:
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
from typing import Any, List, Dict, Generator, Optional
|
|
2
|
+
import asyncio
|
|
3
|
+
import httpx
|
|
4
|
+
import argparse
|
|
5
|
+
from mcp.server.models import InitializationOptions
|
|
6
|
+
import mcp.types as types
|
|
7
|
+
from mcp.server import NotificationOptions, Server
|
|
8
|
+
import mcp.server.stdio
|
|
9
|
+
from autocoder.common import AutoCoderArgs
|
|
10
|
+
from byzerllm import ByzerLLM
|
|
11
|
+
from autocoder.lang import lang_desc
|
|
12
|
+
import locale
|
|
13
|
+
import pkg_resources
|
|
14
|
+
from openai import OpenAI
|
|
15
|
+
|
|
16
|
+
class AutoCoderRAGClientMCP:
|
|
17
|
+
def __init__(self, llm: ByzerLLM, args: AutoCoderArgs):
|
|
18
|
+
self.llm = llm
|
|
19
|
+
self.args = args
|
|
20
|
+
|
|
21
|
+
if not args.rag_url:
|
|
22
|
+
raise ValueError("rag_url is required for RAG client mode")
|
|
23
|
+
|
|
24
|
+
if not args.rag_url.startswith("http://"):
|
|
25
|
+
args.rag_url = f"http://{args.rag_url}"
|
|
26
|
+
|
|
27
|
+
if not args.rag_url.endswith("/v1"):
|
|
28
|
+
args.rag_url = args.rag_url.rstrip("/") + "/v1"
|
|
29
|
+
|
|
30
|
+
if not args.rag_token:
|
|
31
|
+
raise ValueError("rag_token is required for RAG client mode")
|
|
32
|
+
|
|
33
|
+
self.client = OpenAI(api_key=args.rag_token, base_url=args.rag_url)
|
|
34
|
+
|
|
35
|
+
self.server = Server("auto_coder_rag_client")
|
|
36
|
+
|
|
37
|
+
async def setup_server(self):
|
|
38
|
+
@self.server.list_tools()
|
|
39
|
+
async def handle_list_tools() -> List[types.Tool]:
|
|
40
|
+
return [
|
|
41
|
+
types.Tool(
|
|
42
|
+
name="rag-search",
|
|
43
|
+
description="Search documents using RAG",
|
|
44
|
+
inputSchema={
|
|
45
|
+
"type": "object",
|
|
46
|
+
"properties": {
|
|
47
|
+
"query": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "Search query",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
"required": ["query"],
|
|
53
|
+
},
|
|
54
|
+
),
|
|
55
|
+
types.Tool(
|
|
56
|
+
name="rag-chat",
|
|
57
|
+
description="Chat with documents using RAG",
|
|
58
|
+
inputSchema={
|
|
59
|
+
"type": "object",
|
|
60
|
+
"properties": {
|
|
61
|
+
"query": {
|
|
62
|
+
"type": "string",
|
|
63
|
+
"description": "Chat query",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
"required": ["query"],
|
|
67
|
+
},
|
|
68
|
+
),
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
@self.server.call_tool()
|
|
72
|
+
async def handle_call_tool(
|
|
73
|
+
name: str, arguments: Dict[str, Any] | None
|
|
74
|
+
) -> List[types.TextContent | types.ImageContent | types.EmbeddedResource]:
|
|
75
|
+
if not arguments:
|
|
76
|
+
raise ValueError("Missing arguments")
|
|
77
|
+
|
|
78
|
+
if name == "rag-search":
|
|
79
|
+
query = arguments.get("query")
|
|
80
|
+
if not query:
|
|
81
|
+
raise ValueError("Missing query parameter")
|
|
82
|
+
|
|
83
|
+
response = self.client.chat.completions.create(
|
|
84
|
+
messages=[{"role": "user", "content": json.dumps({
|
|
85
|
+
"query": query,
|
|
86
|
+
"only_contexts": True
|
|
87
|
+
})}],
|
|
88
|
+
model=self.args.model,
|
|
89
|
+
max_tokens=self.args.rag_params_max_tokens,
|
|
90
|
+
)
|
|
91
|
+
result = response.choices[0].message.content
|
|
92
|
+
|
|
93
|
+
return [
|
|
94
|
+
types.TextContent(
|
|
95
|
+
type="text",
|
|
96
|
+
text=f"Search results for '{query}':\n\n{result}"
|
|
97
|
+
)
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
elif name == "rag-chat":
|
|
101
|
+
query = arguments.get("query")
|
|
102
|
+
if not query:
|
|
103
|
+
raise ValueError("Missing query parameter")
|
|
104
|
+
|
|
105
|
+
response = self.client.chat.completions.create(
|
|
106
|
+
messages=[{"role": "user", "content": query}],
|
|
107
|
+
model=self.args.model,
|
|
108
|
+
stream=True,
|
|
109
|
+
max_tokens=self.args.rag_params_max_tokens
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
full_response = ""
|
|
113
|
+
for chunk in response:
|
|
114
|
+
if chunk.choices[0].delta.content is not None:
|
|
115
|
+
full_response += chunk.choices[0].delta.content
|
|
116
|
+
|
|
117
|
+
return [
|
|
118
|
+
types.TextContent(
|
|
119
|
+
type="text",
|
|
120
|
+
text=f"Chat response for '{query}':\n\n{full_response}"
|
|
121
|
+
)
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
else:
|
|
125
|
+
raise ValueError(f"Unknown tool: {name}")
|
|
126
|
+
|
|
127
|
+
async def run(self):
|
|
128
|
+
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
|
|
129
|
+
await self.server.run(
|
|
130
|
+
read_stream,
|
|
131
|
+
write_stream,
|
|
132
|
+
InitializationOptions(
|
|
133
|
+
server_name="auto_coder_rag_client",
|
|
134
|
+
server_version="0.1.0",
|
|
135
|
+
capabilities=self.server.get_capabilities(
|
|
136
|
+
notification_options=NotificationOptions(),
|
|
137
|
+
experimental_capabilities={},
|
|
138
|
+
),
|
|
139
|
+
),
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def parse_args(input_args: Optional[List[str]] = None) -> AutoCoderArgs:
|
|
143
|
+
system_lang, _ = locale.getdefaultlocale()
|
|
144
|
+
lang = "zh" if system_lang and system_lang.startswith("zh") else "en"
|
|
145
|
+
desc = lang_desc[lang]
|
|
146
|
+
|
|
147
|
+
parser = argparse.ArgumentParser(description="Auto Coder RAG Client MCP Server")
|
|
148
|
+
parser.add_argument("--rag_url", required=True, help="RAG server URL")
|
|
149
|
+
parser.add_argument("--rag_token", required=True, help="RAG server token")
|
|
150
|
+
parser.add_argument("--model", default="deepseek_chat", help=desc["model"])
|
|
151
|
+
parser.add_argument("--rag_params_max_tokens", type=int, default=4096, help="Max tokens for RAG response")
|
|
152
|
+
|
|
153
|
+
args = parser.parse_args(input_args)
|
|
154
|
+
return AutoCoderArgs(**vars(args))
|
|
155
|
+
|
|
156
|
+
async def main():
|
|
157
|
+
# Parse command line arguments
|
|
158
|
+
args = parse_args()
|
|
159
|
+
|
|
160
|
+
# Initialize LLM
|
|
161
|
+
llm = ByzerLLM()
|
|
162
|
+
llm.setup_default_model_name(args.model)
|
|
163
|
+
|
|
164
|
+
# Initialize and run server
|
|
165
|
+
server = AutoCoderRAGClientMCP(llm=llm, args=args)
|
|
166
|
+
await server.setup_server()
|
|
167
|
+
await server.run()
|
|
168
|
+
|
|
169
|
+
if __name__ == "__main__":
|
|
170
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
from typing import Any, List, Dict, Generator, Optional
|
|
2
|
+
import asyncio
|
|
3
|
+
import httpx
|
|
4
|
+
import argparse
|
|
5
|
+
from mcp.server.models import InitializationOptions
|
|
6
|
+
import mcp.types as types
|
|
7
|
+
from mcp.server import NotificationOptions, Server
|
|
8
|
+
import mcp.server.stdio
|
|
9
|
+
from autocoder.rag.long_context_rag import LongContextRAG
|
|
10
|
+
from autocoder.common import AutoCoderArgs
|
|
11
|
+
from byzerllm import ByzerLLM
|
|
12
|
+
from autocoder.lang import lang_desc
|
|
13
|
+
import locale
|
|
14
|
+
import pkg_resources
|
|
15
|
+
|
|
16
|
+
class AutoCoderRAGMCP:
|
|
17
|
+
def __init__(self, llm: ByzerLLM, args: AutoCoderArgs):
|
|
18
|
+
self.llm = llm
|
|
19
|
+
self.args = args
|
|
20
|
+
self.rag = LongContextRAG(
|
|
21
|
+
llm=llm,
|
|
22
|
+
args=args,
|
|
23
|
+
path=args.source_dir,
|
|
24
|
+
tokenizer_path=args.tokenizer_path
|
|
25
|
+
)
|
|
26
|
+
self.server = Server("auto_coder_rag")
|
|
27
|
+
|
|
28
|
+
async def setup_server(self):
|
|
29
|
+
@self.server.list_tools()
|
|
30
|
+
async def handle_list_tools() -> List[types.Tool]:
|
|
31
|
+
return [
|
|
32
|
+
types.Tool(
|
|
33
|
+
name="rag-search",
|
|
34
|
+
description="Search documents using RAG",
|
|
35
|
+
inputSchema={
|
|
36
|
+
"type": "object",
|
|
37
|
+
"properties": {
|
|
38
|
+
"query": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"description": "Search query",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
"required": ["query"],
|
|
44
|
+
},
|
|
45
|
+
),
|
|
46
|
+
types.Tool(
|
|
47
|
+
name="rag-chat",
|
|
48
|
+
description="Chat with documents using RAG",
|
|
49
|
+
inputSchema={
|
|
50
|
+
"type": "object",
|
|
51
|
+
"properties": {
|
|
52
|
+
"query": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"description": "Chat query",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
"required": ["query"],
|
|
58
|
+
},
|
|
59
|
+
),
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
@self.server.call_tool()
|
|
63
|
+
async def handle_call_tool(
|
|
64
|
+
name: str, arguments: Dict[str, Any] | None
|
|
65
|
+
) -> List[types.TextContent | types.ImageContent | types.EmbeddedResource]:
|
|
66
|
+
if not arguments:
|
|
67
|
+
raise ValueError("Missing arguments")
|
|
68
|
+
|
|
69
|
+
if name == "rag-search":
|
|
70
|
+
query = arguments.get("query")
|
|
71
|
+
if not query:
|
|
72
|
+
raise ValueError("Missing query parameter")
|
|
73
|
+
|
|
74
|
+
results = self.rag.search(query)
|
|
75
|
+
return [
|
|
76
|
+
types.TextContent(
|
|
77
|
+
type="text",
|
|
78
|
+
text=f"Search results for '{query}':\n\n" +
|
|
79
|
+
"\n".join([f"- {result.module_name}: {result.source_code[:200]}..."
|
|
80
|
+
for result in results])
|
|
81
|
+
)
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
elif name == "rag-chat":
|
|
85
|
+
query = arguments.get("query")
|
|
86
|
+
if not query:
|
|
87
|
+
raise ValueError("Missing query parameter")
|
|
88
|
+
|
|
89
|
+
response, _ = self.rag.stream_chat_oai(
|
|
90
|
+
conversations=[{"role": "user", "content": query}]
|
|
91
|
+
)
|
|
92
|
+
full_response = "".join([chunk for chunk in response])
|
|
93
|
+
|
|
94
|
+
return [
|
|
95
|
+
types.TextContent(
|
|
96
|
+
type="text",
|
|
97
|
+
text=f"Chat response for '{query}':\n\n{full_response}"
|
|
98
|
+
)
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
else:
|
|
102
|
+
raise ValueError(f"Unknown tool: {name}")
|
|
103
|
+
|
|
104
|
+
async def run(self):
|
|
105
|
+
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
|
|
106
|
+
await self.server.run(
|
|
107
|
+
read_stream,
|
|
108
|
+
write_stream,
|
|
109
|
+
InitializationOptions(
|
|
110
|
+
server_name="auto_coder_rag",
|
|
111
|
+
server_version="0.1.0",
|
|
112
|
+
capabilities=self.server.get_capabilities(
|
|
113
|
+
notification_options=NotificationOptions(),
|
|
114
|
+
experimental_capabilities={},
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
def parse_args(input_args: Optional[List[str]] = None) -> AutoCoderArgs:
|
|
120
|
+
try:
|
|
121
|
+
tokenizer_path = pkg_resources.resource_filename(
|
|
122
|
+
"autocoder", "data/tokenizer.json"
|
|
123
|
+
)
|
|
124
|
+
except FileNotFoundError:
|
|
125
|
+
tokenizer_path = None
|
|
126
|
+
|
|
127
|
+
system_lang, _ = locale.getdefaultlocale()
|
|
128
|
+
lang = "zh" if system_lang and system_lang.startswith("zh") else "en"
|
|
129
|
+
desc = lang_desc[lang]
|
|
130
|
+
|
|
131
|
+
parser = argparse.ArgumentParser(description="Auto Coder RAG MCP Server")
|
|
132
|
+
parser.add_argument("--source_dir", default=".", help="Source directory path")
|
|
133
|
+
parser.add_argument("--tokenizer_path", default=tokenizer_path, help="Path to tokenizer file")
|
|
134
|
+
parser.add_argument("--model", default="deepseek_chat", help=desc["model"])
|
|
135
|
+
parser.add_argument("--index_model", default="", help=desc["index_model"])
|
|
136
|
+
parser.add_argument("--emb_model", default="", help=desc["emb_model"])
|
|
137
|
+
parser.add_argument("--ray_address", default="auto", help=desc["ray_address"])
|
|
138
|
+
parser.add_argument("--required_exts", default="", help=desc["doc_build_parse_required_exts"])
|
|
139
|
+
parser.add_argument("--rag_doc_filter_relevance", type=int, default=5, help="Relevance score threshold for document filtering")
|
|
140
|
+
parser.add_argument("--rag_context_window_limit", type=int, default=56000, help="Context window limit for RAG")
|
|
141
|
+
parser.add_argument("--full_text_ratio", type=float, default=0.7, help="Ratio of full text area in context window")
|
|
142
|
+
parser.add_argument("--segment_ratio", type=float, default=0.2, help="Ratio of segment area in context window")
|
|
143
|
+
parser.add_argument("--index_filter_workers", type=int, default=5, help="Number of workers for document filtering")
|
|
144
|
+
parser.add_argument("--index_filter_file_num", type=int, default=3, help="Maximum number of files to filter")
|
|
145
|
+
parser.add_argument("--host", default="", help="Server host address")
|
|
146
|
+
parser.add_argument("--port", type=int, default=8000, help="Server port")
|
|
147
|
+
parser.add_argument("--monitor_mode", action="store_true", help="Enable document monitoring mode")
|
|
148
|
+
parser.add_argument("--enable_hybrid_index", action="store_true", help="Enable hybrid index")
|
|
149
|
+
parser.add_argument("--disable_auto_window", action="store_true", help="Disable automatic window adaptation")
|
|
150
|
+
parser.add_argument("--disable_segment_reorder", action="store_true", help="Disable segment reordering")
|
|
151
|
+
parser.add_argument("--disable_inference_enhance", action="store_true", help="Disable inference enhancement")
|
|
152
|
+
parser.add_argument("--inference_deep_thought", action="store_true", help="Enable deep thought in inference")
|
|
153
|
+
parser.add_argument("--inference_slow_without_deep_thought", action="store_true", help="Enable slow inference without deep thought")
|
|
154
|
+
parser.add_argument("--inference_compute_precision", type=int, default=64, help="Inference compute precision")
|
|
155
|
+
parser.add_argument("--data_cells_max_num", type=int, default=2000, help="Maximum number of data cells to process")
|
|
156
|
+
parser.add_argument("--recall_model", default="", help="Model used for document recall")
|
|
157
|
+
parser.add_argument("--chunk_model", default="", help="Model used for document chunking")
|
|
158
|
+
parser.add_argument("--qa_model", default="", help="Model used for question answering")
|
|
159
|
+
|
|
160
|
+
args = parser.parse_args(input_args)
|
|
161
|
+
return AutoCoderArgs(**vars(args)),args
|
|
162
|
+
|
|
163
|
+
async def main():
|
|
164
|
+
# Parse command line arguments
|
|
165
|
+
args,raw_rags = parse_args()
|
|
166
|
+
|
|
167
|
+
# Initialize LLM
|
|
168
|
+
llm = ByzerLLM()
|
|
169
|
+
llm.setup_default_model_name(args.model)
|
|
170
|
+
|
|
171
|
+
# Setup sub models if specified
|
|
172
|
+
if raw_rags.recall_model:
|
|
173
|
+
recall_model = ByzerLLM()
|
|
174
|
+
recall_model.setup_default_model_name(args.recall_model)
|
|
175
|
+
llm.setup_sub_client("recall_model", recall_model)
|
|
176
|
+
|
|
177
|
+
if raw_rags.chunk_model:
|
|
178
|
+
chunk_model = ByzerLLM()
|
|
179
|
+
chunk_model.setup_default_model_name(args.chunk_model)
|
|
180
|
+
llm.setup_sub_client("chunk_model", chunk_model)
|
|
181
|
+
|
|
182
|
+
if raw_rags.qa_model:
|
|
183
|
+
qa_model = ByzerLLM()
|
|
184
|
+
qa_model.setup_default_model_name(args.qa_model)
|
|
185
|
+
llm.setup_sub_client("qa_model", qa_model)
|
|
186
|
+
|
|
187
|
+
# Initialize and run server
|
|
188
|
+
server = AutoCoderRAGMCP(llm=llm, args=args)
|
|
189
|
+
await server.setup_server()
|
|
190
|
+
await server.run()
|
|
191
|
+
|
|
192
|
+
if __name__ == "__main__":
|
|
193
|
+
asyncio.run(main())
|
autocoder/chat_auto_coder.py
CHANGED
|
@@ -48,6 +48,7 @@ from autocoder.agent.auto_guess_query import AutoGuessQuery
|
|
|
48
48
|
from autocoder.common.mcp_server import get_mcp_server, McpRequest, McpInstallRequest, McpRemoveRequest, McpListRequest, McpListRunningRequest, McpRefreshRequest
|
|
49
49
|
import byzerllm
|
|
50
50
|
from byzerllm.utils import format_str_jinja2
|
|
51
|
+
from autocoder.common.memory_manager import get_global_memory_file_paths
|
|
51
52
|
|
|
52
53
|
|
|
53
54
|
class SymbolItem(BaseModel):
|
|
@@ -1657,6 +1658,9 @@ def commit(query: str):
|
|
|
1657
1658
|
return_paths=True
|
|
1658
1659
|
)
|
|
1659
1660
|
|
|
1661
|
+
if conf.get("enable_global_memory", "true") in ["true", "True",True]:
|
|
1662
|
+
yaml_config["urls"] += get_global_memory_file_paths()
|
|
1663
|
+
|
|
1660
1664
|
# 临时保存yaml文件,然后读取yaml文件,转换为args
|
|
1661
1665
|
temp_yaml = os.path.join("actions", f"{uuid.uuid4()}.yml")
|
|
1662
1666
|
try:
|
|
@@ -1740,11 +1744,14 @@ def coding(query: str):
|
|
|
1740
1744
|
converted_value = convert_config_value(key, value)
|
|
1741
1745
|
if converted_value is not None:
|
|
1742
1746
|
yaml_config[key] = converted_value
|
|
1743
|
-
|
|
1747
|
+
|
|
1744
1748
|
yaml_config["urls"] = current_files + get_llm_friendly_package_docs(
|
|
1745
1749
|
return_paths=True
|
|
1746
1750
|
)
|
|
1747
1751
|
|
|
1752
|
+
if conf.get("enable_global_memory", "true") in ["true", "True",True]:
|
|
1753
|
+
yaml_config["urls"] += get_global_memory_file_paths()
|
|
1754
|
+
|
|
1748
1755
|
# handle image
|
|
1749
1756
|
v = Image.convert_image_paths_from(query)
|
|
1750
1757
|
yaml_config["query"] = v
|
|
@@ -1794,7 +1801,7 @@ def coding(query: str):
|
|
|
1794
1801
|
|
|
1795
1802
|
yaml_config[
|
|
1796
1803
|
"context"
|
|
1797
|
-
] += f"
|
|
1804
|
+
] += f"下面是我们的历史对话,参考我们的历史对话从而更好的理解需求和修改代码: \n\n<history>\n"
|
|
1798
1805
|
for conv in conversations:
|
|
1799
1806
|
if conv["role"] == "user":
|
|
1800
1807
|
yaml_config["context"] += f"用户: {conv['content']}\n"
|
|
@@ -1855,6 +1862,9 @@ def chat(query: str):
|
|
|
1855
1862
|
return_paths=True
|
|
1856
1863
|
)
|
|
1857
1864
|
|
|
1865
|
+
if conf.get("enable_global_memory", "true") in ["true", "True",True]:
|
|
1866
|
+
current_files += get_global_memory_file_paths()
|
|
1867
|
+
|
|
1858
1868
|
yaml_config["urls"] = current_files
|
|
1859
1869
|
|
|
1860
1870
|
if "emb_model" in conf:
|
|
@@ -1864,14 +1874,24 @@ def chat(query: str):
|
|
|
1864
1874
|
if is_new:
|
|
1865
1875
|
query = query.replace("/new", "", 1).strip()
|
|
1866
1876
|
|
|
1877
|
+
yaml_config["action"] = []
|
|
1878
|
+
|
|
1867
1879
|
if "/mcp " in query:
|
|
1868
|
-
yaml_config["action"]
|
|
1880
|
+
yaml_config["action"].append("mcp")
|
|
1869
1881
|
query = query.replace("/mcp ", "", 1).strip()
|
|
1870
1882
|
|
|
1871
1883
|
if "/rag " in query:
|
|
1872
|
-
yaml_config["action"]
|
|
1884
|
+
yaml_config["action"].append("rag")
|
|
1873
1885
|
query = query.replace("/rag ", "", 1).strip()
|
|
1874
1886
|
|
|
1887
|
+
if "/copy" in query:
|
|
1888
|
+
yaml_config["action"].append("copy")
|
|
1889
|
+
query = query.replace("/copy", "", 1).strip()
|
|
1890
|
+
|
|
1891
|
+
if "/save" in query:
|
|
1892
|
+
yaml_config["action"].append("save")
|
|
1893
|
+
query = query.replace("/save", "", 1).strip()
|
|
1894
|
+
|
|
1875
1895
|
is_review = query.strip().startswith("/review")
|
|
1876
1896
|
if is_review:
|
|
1877
1897
|
query = query.replace("/review", "", 1).strip()
|
autocoder/common/__init__.py
CHANGED
|
@@ -348,7 +348,8 @@ class AutoCoderArgs(pydantic.BaseModel):
|
|
|
348
348
|
data_cells_max_num: Optional[int] = 2000
|
|
349
349
|
generate_times_same_model: Optional[int] = 1
|
|
350
350
|
|
|
351
|
-
action:
|
|
351
|
+
action: List[str] = []
|
|
352
|
+
enable_global_memory: Optional[bool] = True
|
|
352
353
|
|
|
353
354
|
class Config:
|
|
354
355
|
protected_namespaces = ()
|
|
@@ -13,7 +13,7 @@ COMMANDS = {
|
|
|
13
13
|
"/sd": {},
|
|
14
14
|
},
|
|
15
15
|
"/coding": {"/apply": {}, "/next": {}},
|
|
16
|
-
"/chat": {"/new": {}, "/mcp": {}, "/rag": {}, "/review": {}, "/no_context": {}},
|
|
16
|
+
"/chat": {"/new": {}, "/save": {}, "/copy":{}, "/mcp": {}, "/rag": {}, "/review": {}, "/no_context": {}},
|
|
17
17
|
"/mcp": {
|
|
18
18
|
"/add": "",
|
|
19
19
|
"/remove": "",
|
autocoder/common/mcp_hub.py
CHANGED
|
@@ -192,7 +192,7 @@ class McpHub:
|
|
|
192
192
|
"PATH": os.environ.get("PATH", "")},
|
|
193
193
|
)
|
|
194
194
|
|
|
195
|
-
# Create transport using context manager
|
|
195
|
+
# Create transport using context manager
|
|
196
196
|
transport_manager = stdio_client(server_params)
|
|
197
197
|
transport = await transport_manager.__aenter__()
|
|
198
198
|
try:
|
|
@@ -204,9 +204,9 @@ class McpHub:
|
|
|
204
204
|
self.connections[name] = connection
|
|
205
205
|
|
|
206
206
|
# Update server status and fetch capabilities
|
|
207
|
-
server.status = "connected"
|
|
208
|
-
server.tools = await self._fetch_tools(name)
|
|
209
|
-
server.resources = await self._fetch_resources(name)
|
|
207
|
+
server.status = "connected"
|
|
208
|
+
server.tools = await self._fetch_tools(name)
|
|
209
|
+
server.resources = await self._fetch_resources(name)
|
|
210
210
|
server.resource_templates = await self._fetch_resource_templates(name)
|
|
211
211
|
|
|
212
212
|
except Exception as e:
|
autocoder/common/mcp_server.py
CHANGED
|
@@ -128,6 +128,35 @@ class McpServer:
|
|
|
128
128
|
self._task = self._loop.create_task(self._process_request())
|
|
129
129
|
self._loop.run_forever()
|
|
130
130
|
|
|
131
|
+
def _install_python_package(self, package_name: str) -> None:
|
|
132
|
+
"""Install a Python package using pip"""
|
|
133
|
+
try:
|
|
134
|
+
import importlib
|
|
135
|
+
importlib.import_module(package_name.replace("-", "_"))
|
|
136
|
+
except ImportError:
|
|
137
|
+
import subprocess
|
|
138
|
+
try:
|
|
139
|
+
subprocess.run([sys.executable, "-m", "pip", "install", package_name], check=True)
|
|
140
|
+
except subprocess.CalledProcessError:
|
|
141
|
+
print(f"\n\033[93mFailed to automatically install {package_name}. Please manually install it using:\n")
|
|
142
|
+
print(f" pip install {package_name}\n")
|
|
143
|
+
print(f"We have already updated the server configuration in ~/.autocoder/mcp/settings.json.\n")
|
|
144
|
+
print(f"After installation, you can restart the auto-coder.chat using the server.\033[0m\n")
|
|
145
|
+
|
|
146
|
+
def _install_node_package(self, package_name: str) -> None:
|
|
147
|
+
"""Install a Node.js package using npm"""
|
|
148
|
+
import subprocess
|
|
149
|
+
try:
|
|
150
|
+
subprocess.run(["npx", package_name, "--version"], check=True)
|
|
151
|
+
except:
|
|
152
|
+
try:
|
|
153
|
+
subprocess.run(["npm", "install", "-y", "-g", package_name], check=True)
|
|
154
|
+
except subprocess.CalledProcessError:
|
|
155
|
+
print(f"\n\033[93mFailed to automatically install {package_name}. Please manually install it using:\n")
|
|
156
|
+
print(f" npm install -g {package_name}\n")
|
|
157
|
+
print(f"We have already updated the server configuration in ~/.autocoder/mcp/settings.json.\n")
|
|
158
|
+
print(f"After installation, you can restart the auto-coder.chat using the server.\033[0m\n")
|
|
159
|
+
|
|
131
160
|
async def _install_server(self, request: McpInstallRequest, hub: McpHub) -> McpResponse:
|
|
132
161
|
"""Install an MCP server with module dependency check"""
|
|
133
162
|
name = ""
|
|
@@ -143,6 +172,12 @@ class McpServer:
|
|
|
143
172
|
# 取第一个server 配置
|
|
144
173
|
config = list(raw_config.values())[0]
|
|
145
174
|
name = list(raw_config.keys())[0]
|
|
175
|
+
if name.startswith("@") or config["command"] in ["npx","npm"]:
|
|
176
|
+
for item in config["args"]:
|
|
177
|
+
if name in item:
|
|
178
|
+
self._install_node_package(item)
|
|
179
|
+
else:
|
|
180
|
+
self._install_python_package(name)
|
|
146
181
|
except json.JSONDecodeError:
|
|
147
182
|
name = server_name_or_config.strip()
|
|
148
183
|
if name not in MCP_BUILD_IN_SERVERS:
|
|
@@ -151,26 +186,7 @@ class McpServer:
|
|
|
151
186
|
for s in external_servers:
|
|
152
187
|
if s.name == name:
|
|
153
188
|
if s.runtime == "python":
|
|
154
|
-
|
|
155
|
-
try:
|
|
156
|
-
import importlib
|
|
157
|
-
importlib.import_module(
|
|
158
|
-
name.replace("-", "_"))
|
|
159
|
-
except ImportError:
|
|
160
|
-
# Install missing module
|
|
161
|
-
import subprocess
|
|
162
|
-
try:
|
|
163
|
-
subprocess.run(
|
|
164
|
-
[sys.executable, "-m", "pip", "install", name], check=True)
|
|
165
|
-
except subprocess.CalledProcessError:
|
|
166
|
-
print(
|
|
167
|
-
f"\n\033[93mFailed to automatically install {name}. Please manually install it using:\n")
|
|
168
|
-
print(f" pip install {name}\n")
|
|
169
|
-
print(
|
|
170
|
-
f"We have already updated the server configuration in ~/.autocoder/mcp/settings.json.\n")
|
|
171
|
-
print(
|
|
172
|
-
f"After installation, you can restart the auto-coder.chat using the server.\033[0m\n")
|
|
173
|
-
|
|
189
|
+
self._install_python_package(name)
|
|
174
190
|
config = {
|
|
175
191
|
"command": "python",
|
|
176
192
|
"args": [
|
|
@@ -178,28 +194,12 @@ class McpServer:
|
|
|
178
194
|
],
|
|
179
195
|
}
|
|
180
196
|
elif s.runtime == "node":
|
|
181
|
-
|
|
182
|
-
try:
|
|
183
|
-
subprocess.run(
|
|
184
|
-
["npx", name, "--version"], check=True)
|
|
185
|
-
except:
|
|
186
|
-
# Install missing package
|
|
187
|
-
try:
|
|
188
|
-
subprocess.run(
|
|
189
|
-
["npm", "install", "-y", "-g", name], check=True)
|
|
190
|
-
except subprocess.CalledProcessError:
|
|
191
|
-
print(
|
|
192
|
-
f"\n\033[93mFailed to automatically install {name}. Please manually install it using:\n")
|
|
193
|
-
print(f" npm install -g {name}\n")
|
|
194
|
-
print(
|
|
195
|
-
f"We have already updated the server configuration in ~/.autocoder/mcp/settings.json.\n")
|
|
196
|
-
print(
|
|
197
|
-
f"After installation, you can restart the auto-coder.chat using the server.\033[0m\n")
|
|
198
|
-
|
|
197
|
+
self._install_node_package(name)
|
|
199
198
|
config = {
|
|
200
199
|
"command": "npx",
|
|
201
200
|
"args": [
|
|
202
201
|
"-y",
|
|
202
|
+
"-g",
|
|
203
203
|
name
|
|
204
204
|
]
|
|
205
205
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
import time
|
|
4
|
+
from typing import List, Dict, Optional, Any
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
|
|
8
|
+
class MemoryItem(BaseModel):
|
|
9
|
+
content: Any
|
|
10
|
+
role: str
|
|
11
|
+
|
|
12
|
+
class MemoryEntry(BaseModel):
|
|
13
|
+
timestamp: datetime
|
|
14
|
+
conversation: List[MemoryItem]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def save_to_memory_file(ask_conversation,query:str,response:str):
|
|
18
|
+
# Save to memory file
|
|
19
|
+
memory_dir = os.path.join(os.path.expanduser("~"), ".auto-coder", "memory")
|
|
20
|
+
os.makedirs(memory_dir, exist_ok=True)
|
|
21
|
+
memory_file = os.path.join(memory_dir, "memory.json")
|
|
22
|
+
|
|
23
|
+
# Read existing memory or create new
|
|
24
|
+
if os.path.exists(memory_file):
|
|
25
|
+
with open(memory_file, 'r') as f:
|
|
26
|
+
try:
|
|
27
|
+
memory_data = json.load(f)
|
|
28
|
+
except json.JSONDecodeError:
|
|
29
|
+
memory_data = {}
|
|
30
|
+
else:
|
|
31
|
+
memory_data = {}
|
|
32
|
+
|
|
33
|
+
# Add new conversation
|
|
34
|
+
current_time = str(int(time.time()))
|
|
35
|
+
memory_data[current_time] = [
|
|
36
|
+
{"content": ask_conversation, "role": "background"},
|
|
37
|
+
{"content": query, "role": "user"},
|
|
38
|
+
{"content": response, "role": "assistant"}
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
# Save memory
|
|
42
|
+
with open(memory_file, 'w') as f:
|
|
43
|
+
json.dump(memory_data, f, ensure_ascii=False, indent=2)
|
|
44
|
+
|
|
45
|
+
def load_from_memory_file() -> List[MemoryEntry]:
|
|
46
|
+
"""Load memory data from file and return as list of MemoryEntry objects"""
|
|
47
|
+
memory_dir = os.path.join(os.path.expanduser("~"), ".auto-coder", "memory")
|
|
48
|
+
memory_file = os.path.join(memory_dir, "memory.json")
|
|
49
|
+
|
|
50
|
+
if not os.path.exists(memory_file):
|
|
51
|
+
return []
|
|
52
|
+
|
|
53
|
+
with open(memory_file, 'r') as f:
|
|
54
|
+
try:
|
|
55
|
+
memory_data = json.load(f)
|
|
56
|
+
except json.JSONDecodeError:
|
|
57
|
+
return []
|
|
58
|
+
|
|
59
|
+
entries = []
|
|
60
|
+
for timestamp_str, conversation in memory_data.items():
|
|
61
|
+
try:
|
|
62
|
+
timestamp = datetime.fromtimestamp(int(timestamp_str))
|
|
63
|
+
memory_items = [MemoryItem(**item) for item in conversation]
|
|
64
|
+
entries.append(MemoryEntry(
|
|
65
|
+
timestamp=timestamp,
|
|
66
|
+
conversation=memory_items
|
|
67
|
+
))
|
|
68
|
+
except (ValueError, TypeError):
|
|
69
|
+
continue
|
|
70
|
+
|
|
71
|
+
# Sort entries by timestamp (oldest first)
|
|
72
|
+
entries.sort(key=lambda x: x.timestamp)
|
|
73
|
+
|
|
74
|
+
return entries
|
|
75
|
+
|
|
76
|
+
def get_global_memory_file_paths() -> List[str]:
|
|
77
|
+
"""Get global memory and generate temporary files in ~/.auto-coder/memory/.tmp
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
List[str]: List of file paths for the generated temporary files
|
|
81
|
+
"""
|
|
82
|
+
entries = load_from_memory_file()
|
|
83
|
+
memory_dir = os.path.join(os.path.expanduser("~"), ".auto-coder", "memory")
|
|
84
|
+
tmp_dir = os.path.join(memory_dir, ".tmp")
|
|
85
|
+
os.makedirs(tmp_dir, exist_ok=True)
|
|
86
|
+
|
|
87
|
+
file_paths = []
|
|
88
|
+
|
|
89
|
+
for entry in entries:
|
|
90
|
+
# Find assistant responses
|
|
91
|
+
assistant_contents = [
|
|
92
|
+
item.content for item in entry.conversation
|
|
93
|
+
if item.role == "assistant"
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
if assistant_contents:
|
|
97
|
+
timestamp_str = str(int(entry.timestamp.timestamp()))
|
|
98
|
+
content = "\n".join(assistant_contents)
|
|
99
|
+
file_path = os.path.join(tmp_dir, os.path.join("memory",f"{timestamp_str}.txt"))
|
|
100
|
+
|
|
101
|
+
# Create parent directory if it doesn't exist
|
|
102
|
+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
|
103
|
+
|
|
104
|
+
# Only write file if it doesn't exist
|
|
105
|
+
if not os.path.exists(file_path):
|
|
106
|
+
with open(file_path, "w", encoding="utf-8") as f:
|
|
107
|
+
f.write(content)
|
|
108
|
+
|
|
109
|
+
file_paths.append(file_path)
|
|
110
|
+
|
|
111
|
+
return file_paths
|
|
112
|
+
|
autocoder/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.1.
|
|
1
|
+
__version__ = "0.1.224"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|