scmcp-shared 0.6.0__py3-none-any.whl → 0.6.2__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.
- scmcp_shared/__init__.py +1 -1
- scmcp_shared/agent.py +5 -2
- scmcp_shared/kb.py +29 -59
- scmcp_shared/server/rag.py +1 -1
- {scmcp_shared-0.6.0.dist-info → scmcp_shared-0.6.2.dist-info}/METADATA +1 -1
- {scmcp_shared-0.6.0.dist-info → scmcp_shared-0.6.2.dist-info}/RECORD +8 -8
- {scmcp_shared-0.6.0.dist-info → scmcp_shared-0.6.2.dist-info}/WHEEL +0 -0
- {scmcp_shared-0.6.0.dist-info → scmcp_shared-0.6.2.dist-info}/licenses/LICENSE +0 -0
scmcp_shared/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.6.
|
1
|
+
__version__ = "0.6.2"
|
scmcp_shared/agent.py
CHANGED
@@ -4,7 +4,7 @@ import os
|
|
4
4
|
|
5
5
|
from agno.agent import Agent
|
6
6
|
from agno.models.openai import OpenAILike
|
7
|
-
from
|
7
|
+
from .kb import load_kb
|
8
8
|
|
9
9
|
model = OpenAILike(
|
10
10
|
id=os.getenv("MODEL"),
|
@@ -13,13 +13,16 @@ model = OpenAILike(
|
|
13
13
|
)
|
14
14
|
|
15
15
|
|
16
|
-
def rag_agent(task, software=
|
16
|
+
def rag_agent(task, software="scmcp"):
|
17
17
|
knowledge_base = load_kb(software=software)
|
18
18
|
agent = Agent(
|
19
19
|
model=model,
|
20
20
|
knowledge=knowledge_base,
|
21
21
|
show_tool_calls=True,
|
22
22
|
search_knowledge=True,
|
23
|
+
instructions="""
|
24
|
+
MUST query the knowledge base, and return the code example that can be used to solve the task.
|
25
|
+
""",
|
23
26
|
)
|
24
27
|
query = f"""
|
25
28
|
<task>
|
scmcp_shared/kb.py
CHANGED
@@ -3,12 +3,9 @@ from agno.embedder.openai import OpenAIEmbedder
|
|
3
3
|
from agno.models.deepseek import DeepSeek
|
4
4
|
from agno.vectordb.lancedb import LanceDb
|
5
5
|
from agno.knowledge.agent import AgentKnowledge
|
6
|
-
import importlib.resources
|
7
6
|
import os
|
8
7
|
import requests
|
9
8
|
import zipfile
|
10
|
-
import tempfile
|
11
|
-
import shutil
|
12
9
|
from pathlib import Path
|
13
10
|
import logging
|
14
11
|
|
@@ -21,12 +18,6 @@ model_id = os.getenv("MODEL")
|
|
21
18
|
model_api_key = os.getenv("API_KEY")
|
22
19
|
model_base_url = os.getenv("BASE_URL")
|
23
20
|
|
24
|
-
# 配置信息
|
25
|
-
config = {
|
26
|
-
"local_dir": "vector_db",
|
27
|
-
"huggingface_url": "https://huggingface.co/datasets/huangshing/scmcp_vector_db/resolve/main/vector_db.zip",
|
28
|
-
}
|
29
|
-
|
30
21
|
|
31
22
|
def download_vector_db(source="huggingface"):
|
32
23
|
"""
|
@@ -36,9 +27,7 @@ def download_vector_db(source="huggingface"):
|
|
36
27
|
source: 下载源 ("huggingface" 或 "github")
|
37
28
|
"""
|
38
29
|
|
39
|
-
|
40
|
-
package_path = importlib.resources.path("scmcp_shared", "")
|
41
|
-
local_dir = Path(package_path) / config["local_dir"]
|
30
|
+
local_dir = Path(__file__).parent
|
42
31
|
local_dir.mkdir(exist_ok=True)
|
43
32
|
|
44
33
|
# 检查是否已存在
|
@@ -48,51 +37,32 @@ def download_vector_db(source="huggingface"):
|
|
48
37
|
|
49
38
|
logger.info(f"Downloading vector database from {source}...")
|
50
39
|
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
try:
|
57
|
-
# 下载文件
|
58
|
-
if source == "huggingface":
|
59
|
-
url = config["huggingface_url"]
|
60
|
-
else:
|
61
|
-
raise ValueError(f"Unsupported source: {source}")
|
62
|
-
|
63
|
-
logger.info(f"Downloading from: {url}")
|
64
|
-
response = requests.get(url, stream=True)
|
65
|
-
response.raise_for_status()
|
40
|
+
# 下载文件
|
41
|
+
if source == "huggingface":
|
42
|
+
url = "https://huggingface.co/datasets/huangshing/scmcp_vector_db/resolve/main/vector_db.zip"
|
43
|
+
else:
|
44
|
+
raise ValueError(f"Unsupported source: {source}")
|
66
45
|
|
67
|
-
|
68
|
-
|
69
|
-
|
46
|
+
logger.info(f"Downloading from: {url}")
|
47
|
+
response = requests.get(url, stream=True)
|
48
|
+
response.raise_for_status()
|
70
49
|
|
71
|
-
|
72
|
-
|
73
|
-
|
50
|
+
# 下载到目标目录
|
51
|
+
zip_path = local_dir / "vector_db.zip"
|
52
|
+
with open(zip_path, "wb") as f:
|
53
|
+
for chunk in response.iter_content(chunk_size=8192):
|
54
|
+
f.write(chunk)
|
74
55
|
|
75
|
-
|
76
|
-
|
56
|
+
# 解压文件
|
57
|
+
logger.info("Extracting downloaded archive...")
|
58
|
+
with zipfile.ZipFile(zip_path, "r") as zip_ref:
|
59
|
+
zip_ref.extractall(local_dir)
|
77
60
|
|
78
|
-
|
79
|
-
|
80
|
-
except Exception as e:
|
81
|
-
raise RuntimeError(f"Failed to process vector database: {e}")
|
61
|
+
# 删除zip文件
|
62
|
+
zip_path.unlink()
|
82
63
|
|
83
|
-
|
84
|
-
|
85
|
-
"""解压归档文件"""
|
86
|
-
with zipfile.ZipFile(archive_path, "r") as zip_ref:
|
87
|
-
zip_ref.extractall(extract_dir)
|
88
|
-
|
89
|
-
# 如果解压后只有一个子目录,移动内容到目标目录
|
90
|
-
extracted_items = list(Path(extract_dir).iterdir())
|
91
|
-
if len(extracted_items) == 1 and extracted_items[0].is_dir():
|
92
|
-
subdir = extracted_items[0]
|
93
|
-
for item in subdir.iterdir():
|
94
|
-
shutil.move(str(item), str(extract_dir / item.name))
|
95
|
-
subdir.rmdir()
|
64
|
+
logger.info(f"Vector database downloaded and extracted to: {local_dir}")
|
65
|
+
return str(local_dir)
|
96
66
|
|
97
67
|
|
98
68
|
def load_kb(software=None, auto_download=True, download_source="huggingface"):
|
@@ -105,16 +75,16 @@ def load_kb(software=None, auto_download=True, download_source="huggingface"):
|
|
105
75
|
download_source: 下载源 ("huggingface" 或 "github")
|
106
76
|
"""
|
107
77
|
# 获取向量数据库路径
|
108
|
-
|
109
|
-
|
110
|
-
|
78
|
+
vector_db_path = Path(__file__).parent / "vector_db"
|
79
|
+
|
80
|
+
# 如果不存在且允许自动下载,则下载
|
81
|
+
if not (vector_db_path / "scmcp.lance").exists():
|
111
82
|
if auto_download:
|
112
|
-
logger.info("Vector database not found
|
113
|
-
|
83
|
+
logger.info("Vector database not found, downloading...")
|
84
|
+
download_vector_db(download_source)
|
114
85
|
else:
|
115
86
|
raise FileNotFoundError(
|
116
|
-
"Vector database not found. Set auto_download=True to download automatically
|
117
|
-
"or manually place the vector database in the scmcp_shared package."
|
87
|
+
"Vector database not found. Set auto_download=True to download automatically."
|
118
88
|
)
|
119
89
|
|
120
90
|
vector_db = LanceDb(
|
scmcp_shared/server/rag.py
CHANGED
@@ -9,5 +9,5 @@ rag_mcp = FastMCP("RAG-Server")
|
|
9
9
|
def retrieve_knowledge(
|
10
10
|
task: str = Field(description="The tasks or questions that needs to be solved"),
|
11
11
|
):
|
12
|
-
"""search
|
12
|
+
"""search guide or code example that can be used to solve the user's tasks or questions"""
|
13
13
|
return rag_agent(task, software="scmcp")
|
@@ -1,8 +1,8 @@
|
|
1
|
-
scmcp_shared/__init__.py,sha256=
|
2
|
-
scmcp_shared/agent.py,sha256=
|
1
|
+
scmcp_shared/__init__.py,sha256=jFlbxEJFS0G44LE-yXXVSwXACA1J_NyYDk5E20_2zpc,22
|
2
|
+
scmcp_shared/agent.py,sha256=IRzsyxdf0bwAyhH_wHW7gVKqza_E8ldOQSCMvTcOTuE,1274
|
3
3
|
scmcp_shared/backend.py,sha256=PyxHhg7ThHE5u6XtWwleAiJ3aqdLHbXoXuyw5QeF4Qw,1695
|
4
4
|
scmcp_shared/cli.py,sha256=zYz_E3SlZ_mtYOrSdDJhDmHsppkwzEi2rZ6D3a_ga1c,5603
|
5
|
-
scmcp_shared/kb.py,sha256=
|
5
|
+
scmcp_shared/kb.py,sha256=mRT3EzSOzXZ1_h1RV4Z7Maqzk2wSwmkpb4DrpBOOJtk,3218
|
6
6
|
scmcp_shared/logging_config.py,sha256=Z5jLgOCfir4UGxM-ZQvYv7Iyl_zF78qqPNQ_aSE77f0,838
|
7
7
|
scmcp_shared/mcp_base.py,sha256=v8sBqObTVzLEvoeQe3la2cfnDWZE7DkY07SqEb_1srA,7277
|
8
8
|
scmcp_shared/util.py,sha256=LNrpoHBdA4x-Tt16uT_9A72_QZ41SrqZ0zy3Ozwa858,11163
|
@@ -22,14 +22,14 @@ scmcp_shared/schema/preset/util.py,sha256=1twQ9kiaKI6XubJIuYywG7vr-T2cCCblehhYXJ
|
|
22
22
|
scmcp_shared/server/__init__.py,sha256=qwJEKZnBjcTi7wXcPpeQ-EP4YY9jJo9BYXkfCyn662c,198
|
23
23
|
scmcp_shared/server/auto.py,sha256=FQKbUDuWlgfkcakLGm28lzrJTBm2vynwskHDdVLV2Dk,1966
|
24
24
|
scmcp_shared/server/code.py,sha256=_uNIZ7sVfpBAhX1qPJ8f3zquSEgZXA3jWkPaRx3ph9k,56
|
25
|
-
scmcp_shared/server/rag.py,sha256=
|
25
|
+
scmcp_shared/server/rag.py,sha256=2b7ILYaFjVXfIjX4_J3EpARwrB1dds_7MEdea8oU7vQ,400
|
26
26
|
scmcp_shared/server/preset/__init__.py,sha256=2DdRR0MaipsxREZ4dWvnGfNRAaHQY7BGGVNgGQEyfbo,318
|
27
27
|
scmcp_shared/server/preset/io.py,sha256=2QigfUHR8HJtVdI4nIfRh0tm8WhVu8Hge1AAos6afZM,4059
|
28
28
|
scmcp_shared/server/preset/pl.py,sha256=pQx7yD1-vRSnNky_8tapI6vU1lqcZ5S4zs5y1aamtcc,16774
|
29
29
|
scmcp_shared/server/preset/pp.py,sha256=9WtTQ8aHnN_G_7Rm9hZsa7GU3A7xHBoNf8tE-gsDDHY,17114
|
30
30
|
scmcp_shared/server/preset/tl.py,sha256=LtrGMNkeTlTqe2Cyw1OwZXpeTbyGqgENYYC76BKXgpg,19716
|
31
31
|
scmcp_shared/server/preset/util.py,sha256=vek2SOEfiyAyCUEjwsFf1uqwT9YuzDHVQJ-dprIDWME,13519
|
32
|
-
scmcp_shared-0.6.
|
33
|
-
scmcp_shared-0.6.
|
34
|
-
scmcp_shared-0.6.
|
35
|
-
scmcp_shared-0.6.
|
32
|
+
scmcp_shared-0.6.2.dist-info/METADATA,sha256=G9fDdQvtdg4DHARkVp9_LyE_lhlRkwbtjedqSUWnb6Y,2514
|
33
|
+
scmcp_shared-0.6.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
34
|
+
scmcp_shared-0.6.2.dist-info/licenses/LICENSE,sha256=YNr1hpea195yq-wGtB8j-2dGtt7A5G00WENmxa7JGco,1495
|
35
|
+
scmcp_shared-0.6.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|