adam-community 1.0.12__tar.gz → 1.0.14__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.
Files changed (34) hide show
  1. {adam_community-1.0.12 → adam_community-1.0.14}/PKG-INFO +1 -1
  2. adam_community-1.0.14/adam_community/__version__.py +1 -0
  3. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/build.py +2 -2
  4. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/cli.py +1 -0
  5. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/init.py +62 -16
  6. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/initial_assistant_message.md.j2 +4 -4
  7. adam_community-1.0.14/adam_community/cli/templates/rag_python.py.j2 +76 -0
  8. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community.egg-info/PKG-INFO +1 -1
  9. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community.egg-info/SOURCES.txt +3 -2
  10. adam_community-1.0.12/adam_community/__version__.py +0 -1
  11. {adam_community-1.0.12 → adam_community-1.0.14}/README.md +0 -0
  12. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/__init__.py +0 -0
  13. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/__init__.py +0 -0
  14. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/parser.py +0 -0
  15. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/Makefile.j2 +0 -0
  16. /adam_community-1.0.12/adam_community/cli/templates/README_toolbox.md.j2 → /adam_community-1.0.14/adam_community/cli/templates/README_agent.md.j2 +0 -0
  17. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/README_kit.md.j2 +0 -0
  18. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/__init__.py +0 -0
  19. /adam_community-1.0.12/adam_community/cli/templates/toolbox_python.py.j2 → /adam_community-1.0.14/adam_community/cli/templates/agent_python.py.j2 +0 -0
  20. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/configure.json.j2 +0 -0
  21. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/initial_system_prompt.md.j2 +0 -0
  22. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/input.json.j2 +0 -0
  23. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/kit_python.py.j2 +0 -0
  24. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/templates/long_description.md.j2 +0 -0
  25. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/cli/updater.py +0 -0
  26. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/tool.py +0 -0
  27. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community/util.py +0 -0
  28. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community.egg-info/dependency_links.txt +0 -0
  29. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community.egg-info/entry_points.txt +0 -0
  30. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community.egg-info/requires.txt +0 -0
  31. {adam_community-1.0.12 → adam_community-1.0.14}/adam_community.egg-info/top_level.txt +0 -0
  32. {adam_community-1.0.12 → adam_community-1.0.14}/setup.cfg +0 -0
  33. {adam_community-1.0.12 → adam_community-1.0.14}/setup.py +0 -0
  34. {adam_community-1.0.12 → adam_community-1.0.14}/test/test_util_tool.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: adam_community
3
- Version: 1.0.12
3
+ Version: 1.0.14
4
4
  Summary: Adam Community Tools and Utilities
5
5
  Home-page: https://github.com/yourusername/adam-community
6
6
  Author: Adam Community
@@ -0,0 +1 @@
1
+ __version__ = "1.0.14"
@@ -54,9 +54,9 @@ def check_python_files(directory: Path) -> Tuple[bool, List[str]]:
54
54
  # 检查参数类型是否都是有效的JSON Schema类型
55
55
  param_errors = []
56
56
  for param_name, param_info in func_info["parameters"]["properties"].items():
57
- if "type" not in param_info:
57
+ if "type" not in param_info and "oneOf" not in param_info:
58
58
  param_errors.append(f"参数 '{param_name}' 缺少类型定义")
59
- elif param_info["type"] not in ["string", "integer", "number", "boolean", "array", "object", "null"]:
59
+ elif "type" in param_info and param_info["type"] not in ["string", "integer", "number", "boolean", "array", "object", "null"]:
60
60
  param_errors.append(f"参数 '{param_name}' 类型 '{param_info['type']}' 不是有效的JSON Schema类型")
61
61
 
62
62
  if param_errors:
@@ -72,6 +72,7 @@ def config(disable_update_check, enable_update_check):
72
72
  else:
73
73
  click.echo("请使用 --disable-update-check 或 --enable-update-check 选项")
74
74
 
75
+
75
76
  # 添加 init 命令
76
77
  cli.add_command(init)
77
78
 
@@ -4,6 +4,7 @@ from pathlib import Path
4
4
  from jinja2 import Environment, FileSystemLoader
5
5
  from typing import Dict, Any
6
6
 
7
+
7
8
  @click.command()
8
9
  @click.option('--name', prompt='项目名称(仅支持字母、数字、连字符,不能有空格)', help='项目的英文名称(用于文件夹和配置)')
9
10
  @click.option('--display-name', prompt='显示名称', help='项目的中文显示名称')
@@ -11,11 +12,11 @@ from typing import Dict, Any
11
12
  @click.option('--version', default='1.0.0', prompt='版本号', help='项目版本号')
12
13
  @click.option('--author', prompt='作者', help='项目作者')
13
14
  @click.option('--type',
14
- type=click.Choice(['kit', 'toolbox']),
15
- prompt='项目类型',
16
- help='选择项目类型: kit(表单工具) 或 toolbox(智能体工具)')
15
+ type=click.Choice(['kit', 'agent'], case_sensitive=False),
16
+ help='选择项目类型: kit(表单工具) 或 agent(智能体工具)')
17
+ @click.option('--collection', help='知识库名称(仅当启用 RAG 功能时使用)')
17
18
  @click.argument('directory', type=click.Path(exists=True, file_okay=False, dir_okay=True), default='.')
18
- def init(name: str, display_name: str, description: str, version: str, author: str, type: str, directory: str):
19
+ def init(name: str, display_name: str, description: str, version: str, author: str, type: str, collection: str, directory: str):
19
20
  """初始化一个新的 Adam 工具项目"""
20
21
 
21
22
  # 验证项目名称格式
@@ -25,6 +26,17 @@ def init(name: str, display_name: str, description: str, version: str, author: s
25
26
  click.echo("示例: my-tool, data-processor, image-analyzer")
26
27
  return
27
28
 
29
+ # 如果没有提供项目类型,显示选择菜单
30
+ if not type:
31
+ type = select_project_type()
32
+
33
+ # 如果是 agent 类型,询问是否需要 RAG 功能
34
+ enable_rag = False
35
+ if type == 'agent':
36
+ enable_rag = click.confirm('是否需要启用 RAG 知识库搜索功能?', default=False)
37
+ if enable_rag and not collection:
38
+ collection = click.prompt('知识库名称')
39
+
28
40
  directory_path = Path(directory)
29
41
  project_path = directory_path / name
30
42
 
@@ -52,7 +64,11 @@ def init(name: str, display_name: str, description: str, version: str, author: s
52
64
  'description': description,
53
65
  'version': version,
54
66
  'author': author,
55
- 'project_type': type
67
+ 'project_type': type,
68
+ 'enable_rag': enable_rag,
69
+ 'collection_name': collection if enable_rag else '',
70
+ 'class_name': name.replace('-', '_').title(),
71
+ 'rag_class_name': name.replace('-', '_').replace('_', '').title() + 'RAG' if enable_rag else ''
56
72
  }
57
73
 
58
74
  # 生成配置文件
@@ -65,8 +81,11 @@ def init(name: str, display_name: str, description: str, version: str, author: s
65
81
 
66
82
  if type == 'kit':
67
83
  generate_kit_files(env, project_path, config_path, template_vars)
68
- else:
69
- generate_toolbox_files(env, project_path, config_path, template_vars)
84
+ else: # agent
85
+ generate_agent_files(env, project_path, config_path, template_vars)
86
+ # 如果启用了 RAG 功能,额外生成 RAG 文件
87
+ if enable_rag:
88
+ generate_rag_files(env, project_path, config_path, template_vars)
70
89
 
71
90
  # 生成 Makefile
72
91
  render_and_save(env, 'Makefile.j2', project_path / "Makefile", template_vars)
@@ -75,8 +94,8 @@ def init(name: str, display_name: str, description: str, version: str, author: s
75
94
  # 生成 README 文件
76
95
  if type == 'kit':
77
96
  render_and_save(env, 'README_kit.md.j2', project_path / "README.md", template_vars)
78
- else:
79
- render_and_save(env, 'README_toolbox.md.j2', project_path / "README.md", template_vars)
97
+ else: # agent
98
+ render_and_save(env, 'README_agent.md.j2', project_path / "README.md", template_vars)
80
99
  click.echo(f"生成项目文档: README.md")
81
100
 
82
101
  click.echo(f"\n✅ 项目 '{name}' 初始化完成!")
@@ -88,10 +107,12 @@ def init(name: str, display_name: str, description: str, version: str, author: s
88
107
  click.echo("3. 📝 自定义 config/input.json 表单配置")
89
108
  else:
90
109
  click.echo("3. 🤖 自定义 config/initial_system_prompt.md 和 config/initial_assistant_message.md")
91
- click.echo("4. 📄 完善 config/long_description.md 描述文档")
92
- click.echo("5. ⚙️ 运行 'make parse' 生成 functions.json")
93
- click.echo("6. 📦 运行 'make build' 打包项目")
94
- click.echo(f"\n💡 详细的开发指南请查看: {project_path}/README.md")
110
+ if enable_rag:
111
+ click.echo("4. 🔍 根据需要修改 RAG 知识库搜索功能")
112
+ click.echo(f"{4 if type == 'kit' else 5}. 📄 完善 config/long_description.md 描述文档")
113
+ click.echo(f"{5 if type == 'kit' else 6}. ⚙️ 运行 'make parse' 生成 functions.json")
114
+ click.echo(f"{6 if type == 'kit' else 7}. 📦 运行 'make build' 打包项目")
115
+ click.echo(f"\n💡 详细的开发指南请查看: https://sidereus-ai.feishu.cn/wiki/FVMowiyGCi4qYGkr131cPNzVnQd")
95
116
 
96
117
 
97
118
  def render_and_save(env: Environment, template_name: str, output_path: Path, template_vars: Dict[str, Any]):
@@ -115,8 +136,8 @@ def generate_kit_files(env: Environment, project_path: Path, config_path: Path,
115
136
  click.echo(f"生成主要实现文件: {python_filename}")
116
137
 
117
138
 
118
- def generate_toolbox_files(env: Environment, project_path: Path, config_path: Path, template_vars: Dict[str, Any]):
119
- """生成 toolbox 项目的特定文件"""
139
+ def generate_agent_files(env: Environment, project_path: Path, config_path: Path, template_vars: Dict[str, Any]):
140
+ """生成 agent 项目的特定文件"""
120
141
 
121
142
  # 生成 initial_system_prompt.md
122
143
  render_and_save(env, 'initial_system_prompt.md.j2', config_path / "initial_system_prompt.md", template_vars)
@@ -128,10 +149,35 @@ def generate_toolbox_files(env: Environment, project_path: Path, config_path: Pa
128
149
 
129
150
  # 生成主要的Python实现文件
130
151
  python_filename = f"{template_vars['name'].replace('-', '_')}.py"
131
- render_and_save(env, 'toolbox_python.py.j2', project_path / python_filename, template_vars)
152
+ render_and_save(env, 'agent_python.py.j2', project_path / python_filename, template_vars)
132
153
  click.echo(f"生成主要实现文件: {python_filename}")
133
154
 
134
155
 
156
+ def generate_rag_files(env: Environment, project_path: Path, config_path: Path, template_vars: Dict[str, Any]):
157
+ """生成 RAG 功能的额外文件"""
158
+
159
+ # 生成 RAG 功能的 Python 实现文件
160
+ rag_filename = f"{template_vars['name'].replace('-', '_')}_rag.py"
161
+ render_and_save(env, 'rag_python.py.j2', project_path / rag_filename, template_vars)
162
+ click.echo(f"生成 RAG 功能文件: {rag_filename}")
163
+
164
+
165
+ def select_project_type() -> str:
166
+ """显示项目类型选择菜单"""
167
+ click.echo("\n请选择项目类型:")
168
+ click.echo("1. kit (表单工具)")
169
+ click.echo("2. agent (智能体工具)")
170
+
171
+ while True:
172
+ choice = click.prompt("请输入选项编号 (1 或 2)", type=str)
173
+ if choice == '1':
174
+ return 'kit'
175
+ elif choice == '2':
176
+ return 'agent'
177
+ else:
178
+ click.echo("❌ 无效选择,请输入 1 或 2")
179
+
180
+
135
181
  def validate_project_name(name: str) -> bool:
136
182
  """验证项目名称格式"""
137
183
  # 项目名称只能包含字母、数字和连字符,不能有空格
@@ -1,19 +1,19 @@
1
- # 欢迎使用{{ display_name }}工具!
1
+ ## 欢迎使用{{ display_name }}工具!
2
2
 
3
3
  我是您的专业{{ display_name }}助手,可以帮助您完成以下任务:
4
4
 
5
- ## 🔧 主要功能
5
+ ### 🔧 主要功能
6
6
  - 功能1: 基础处理功能
7
7
  - 功能2: 高级分析功能
8
8
  - 功能3: 结果导出功能
9
9
 
10
- ## 🚀 快速开始
10
+ ### 🚀 快速开始
11
11
  1. 描述您的需求
12
12
  2. 提供必要的输入数据
13
13
  3. 我将为您执行相应操作
14
14
  4. 获取详细的分析结果
15
15
 
16
- ## 💡 使用建议
16
+ ### 💡 使用建议
17
17
  - 请详细描述您的需求
18
18
  - 如有文件需要处理,请上传相关文件
19
19
  - 我会为您提供详细的操作步骤和结果分析
@@ -0,0 +1,76 @@
1
+ from adam_community.tool import Tool
2
+ from adam_community.util import knowledgeSearch
3
+ import json
4
+
5
+ class {{ class_name }}(Tool, calltype="python"):
6
+ """
7
+ {{ description }}
8
+
9
+ :param str query: 搜索的关键词
10
+ """
11
+
12
+ DISPLAY_NAME = "{{ display_name }}"
13
+ NETWORK = True
14
+ CONDA_ENV = "knowledgebase"
15
+ SIF = "akb:1.0.0"
16
+ COLLECTION_NAME = "{{ collection_name }}"
17
+ PROJECT_NAME = "default"
18
+
19
+ # 基础提示词模板
20
+ BASIC_PROMPT = """
21
+ # 参考资料
22
+ <context>
23
+ {}
24
+ </context>
25
+ """
26
+
27
+ def call(self, kwargs):
28
+ """
29
+ 执行知识库搜索并生成提示词
30
+
31
+ Args:
32
+ kwargs: 包含查询参数的字典
33
+ """
34
+ query = kwargs.get('args', {}).get('query')
35
+ if not query:
36
+ self.logger.error("查询参数为空")
37
+ return
38
+
39
+ self.logger.debug(f"搜索知识库 {self.COLLECTION_NAME}: {query}")
40
+
41
+ try:
42
+ # 调用知识库搜索(messages_prev 参数在本地实现中未使用,传 None 即可)
43
+ response_text = knowledgeSearch(query, None, self.PROJECT_NAME, self.COLLECTION_NAME)
44
+
45
+ # 解析响应并提取内容
46
+ response = json.loads(response_text)
47
+ if response.get("code") != 0:
48
+ self.logger.warning(f"知识库搜索返回错误: {response.get('message', '未知错误')}")
49
+ return
50
+
51
+ # 提取知识库内容
52
+ result_list = response.get("data", {}).get("result_list", [])
53
+ context_content = ""
54
+
55
+ for point in result_list:
56
+ content = point.get("content", "")
57
+ if content:
58
+ context_content += f"{content}\n---\n"
59
+
60
+ # 生成最终提示词
61
+ prompt = self.BASIC_PROMPT.format(context_content)
62
+ print(prompt)
63
+
64
+ except Exception as e:
65
+ self.logger.error(f"知识库搜索失败: {e}")
66
+
67
+ def inputShow(self, **kwargs):
68
+ """显示输入信息"""
69
+ query = kwargs.get('args', {}).get('query', '')
70
+ return f"Searching knowledge base {self.COLLECTION_NAME}: {query}"
71
+
72
+ def outputShow(self, kwargs):
73
+ """显示输出信息"""
74
+ query = kwargs.get('args', {}).get('query', '')
75
+ stderr = kwargs.get('stderr', '')
76
+ return f"Done searching knowledge base {self.COLLECTION_NAME}: {query}", stderr
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: adam_community
3
- Version: 1.0.12
3
+ Version: 1.0.14
4
4
  Summary: Adam Community Tools and Utilities
5
5
  Home-page: https://github.com/yourusername/adam-community
6
6
  Author: Adam Community
@@ -17,14 +17,15 @@ adam_community/cli/init.py
17
17
  adam_community/cli/parser.py
18
18
  adam_community/cli/updater.py
19
19
  adam_community/cli/templates/Makefile.j2
20
+ adam_community/cli/templates/README_agent.md.j2
20
21
  adam_community/cli/templates/README_kit.md.j2
21
- adam_community/cli/templates/README_toolbox.md.j2
22
22
  adam_community/cli/templates/__init__.py
23
+ adam_community/cli/templates/agent_python.py.j2
23
24
  adam_community/cli/templates/configure.json.j2
24
25
  adam_community/cli/templates/initial_assistant_message.md.j2
25
26
  adam_community/cli/templates/initial_system_prompt.md.j2
26
27
  adam_community/cli/templates/input.json.j2
27
28
  adam_community/cli/templates/kit_python.py.j2
28
29
  adam_community/cli/templates/long_description.md.j2
29
- adam_community/cli/templates/toolbox_python.py.j2
30
+ adam_community/cli/templates/rag_python.py.j2
30
31
  test/test_util_tool.py
@@ -1 +0,0 @@
1
- __version__ = "1.0.12"