adam-community 1.0.24__tar.gz → 1.0.25__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 (38) hide show
  1. {adam_community-1.0.24 → adam_community-1.0.25}/PKG-INFO +1 -1
  2. adam_community-1.0.25/adam_community/__version__.py +1 -0
  3. adam_community-1.0.25/adam_community/cli/templates/agent_python.py.j2 +334 -0
  4. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community.egg-info/PKG-INFO +1 -1
  5. adam_community-1.0.24/adam_community/__version__.py +0 -1
  6. adam_community-1.0.24/adam_community/cli/templates/agent_python.py.j2 +0 -139
  7. {adam_community-1.0.24 → adam_community-1.0.25}/README.md +0 -0
  8. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/__init__.py +0 -0
  9. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/__init__.py +0 -0
  10. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/build.py +0 -0
  11. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/cli.py +0 -0
  12. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/init.py +0 -0
  13. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/parser.py +0 -0
  14. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/Makefile.j2 +0 -0
  15. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/README_agent.md.j2 +0 -0
  16. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/README_kit.md.j2 +0 -0
  17. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/__init__.py +0 -0
  18. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/configure.json.j2 +0 -0
  19. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/initial_assistant_message.md.j2 +0 -0
  20. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/initial_assistant_message_en.md.j2 +0 -0
  21. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/initial_system_prompt.md.j2 +0 -0
  22. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/initial_system_prompt_en.md.j2 +0 -0
  23. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/input.json.j2 +0 -0
  24. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/kit_python.py.j2 +0 -0
  25. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/long_description.md.j2 +0 -0
  26. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/long_description_en.md.j2 +0 -0
  27. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/templates/rag_python.py.j2 +0 -0
  28. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/cli/updater.py +0 -0
  29. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/tool.py +0 -0
  30. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community/util.py +0 -0
  31. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community.egg-info/SOURCES.txt +0 -0
  32. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community.egg-info/dependency_links.txt +0 -0
  33. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community.egg-info/entry_points.txt +0 -0
  34. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community.egg-info/requires.txt +0 -0
  35. {adam_community-1.0.24 → adam_community-1.0.25}/adam_community.egg-info/top_level.txt +0 -0
  36. {adam_community-1.0.24 → adam_community-1.0.25}/setup.cfg +0 -0
  37. {adam_community-1.0.24 → adam_community-1.0.25}/setup.py +0 -0
  38. {adam_community-1.0.24 → adam_community-1.0.25}/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.24
3
+ Version: 1.0.25
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.25"
@@ -0,0 +1,334 @@
1
+ from adam_community.tool import Tool
2
+ from adam_community.util import runCmd
3
+ import json
4
+ import datetime
5
+
6
+
7
+ # 输出处理常量
8
+ MAX_OUTPUT_LENGTH = 10000
9
+ TRUNCATE_PREFIX_LENGTH = 5000
10
+ TRUNCATE_SUFFIX_LENGTH = 5000
11
+ SUMMARY_STDOUT_LENGTH = 300
12
+ SUMMARY_STDERR_LENGTH = 200
13
+
14
+
15
+ def truncate_output(text):
16
+ """截断过长的输出文本。
17
+
18
+ Args:
19
+ text (str): 需要截断的文本
20
+
21
+ Returns:
22
+ str: 截断后的文本
23
+ """
24
+ if len(text) <= MAX_OUTPUT_LENGTH:
25
+ return text
26
+ return (text[:TRUNCATE_PREFIX_LENGTH] +
27
+ "\n...输出太长已省略...\n" +
28
+ text[-TRUNCATE_SUFFIX_LENGTH:])
29
+
30
+
31
+ def get_status_info(exit_code):
32
+ """获取执行状态信息。
33
+
34
+ Args:
35
+ exit_code (int): 退出码
36
+
37
+ Returns:
38
+ tuple: (状态图标, 状态文本) 元组
39
+ """
40
+ if exit_code == 0:
41
+ return "✅", "成功"
42
+ return "❌", "失败"
43
+
44
+
45
+ def format_output_display(stdout, stderr, exit_code, tool_display_name):
46
+ """格式化输出显示文本。
47
+
48
+ Args:
49
+ stdout (str): 标准输出
50
+ stderr (str): 错误输出
51
+ exit_code (int): 退出码
52
+ tool_display_name (str): 工具显示名称
53
+
54
+ Returns:
55
+ str: 格式化的Markdown文本
56
+ """
57
+ status_icon, status_text = get_status_info(exit_code)
58
+
59
+ display_parts = [
60
+ f"## {status_icon} {tool_display_name}处理{status_text}",
61
+ "",
62
+ "### 📋 处理结果",
63
+ f"- 退出码: {exit_code}",
64
+ "- 标准输出:",
65
+ "```",
66
+ stdout,
67
+ "```"
68
+ ]
69
+
70
+ if stderr:
71
+ display_parts.extend([
72
+ "",
73
+ "### ⚠️ 错误/警告信息",
74
+ "```",
75
+ stderr,
76
+ "```"
77
+ ])
78
+
79
+ return "\n".join(display_parts)
80
+
81
+
82
+ def generate_summary(stdout, stderr, exit_code, tool_name):
83
+ """生成执行结果摘要。
84
+
85
+ Args:
86
+ stdout (str): 标准输出
87
+ stderr (str): 错误输出
88
+ exit_code (int): 退出码
89
+ tool_name (str): 工具名称
90
+
91
+ Returns:
92
+ str: 执行摘要文本
93
+ """
94
+ if exit_code != 0:
95
+ summary = f"{tool_name}执行失败(退出码: {exit_code})。"
96
+ if stderr:
97
+ summary += f" 错误信息: {stderr[:SUMMARY_STDERR_LENGTH]}"
98
+ return summary
99
+
100
+ if stderr:
101
+ summary = f"{tool_name}执行完成但有警告。"
102
+ summary += f" 输出: {stdout[:SUMMARY_STDERR_LENGTH]}"
103
+ summary += f" 警告: {stderr[:SUMMARY_STDERR_LENGTH]}"
104
+ return summary
105
+
106
+ summary = f"{tool_name}执行成功。"
107
+ summary += f" 输出摘要: {stdout[:SUMMARY_STDOUT_LENGTH]}"
108
+ return summary
109
+
110
+
111
+ class {{ name.replace("-", "_") }}_tool(Tool):
112
+ """
113
+ {{ description }}
114
+
115
+ Args:
116
+ input_text (str): 输入的文本内容
117
+ mode (str, optional): 处理模式,可选值:basic、advanced
118
+ """
119
+ DISPLAY_NAME = "{{ display_name }}工具"
120
+ NETWORK = False
121
+ CPU = 1
122
+ GPU = 0
123
+ SIF = "adam-base:1.0.0"
124
+
125
+ # 输出文件配置
126
+ OUTPUT_FILE = "output.txt"
127
+
128
+ def inputShow(self, **kwargs):
129
+ """AI决定使用该工具时调用,用于向用户展示当前调用的工具信息。
130
+
131
+ Args:
132
+ kwargs (dict): 包含args、message、files、user、task_id等参数的字典。
133
+
134
+ Returns:
135
+ str: 给用户显示的字符串(可使用markdown渲染)。
136
+ """
137
+ args = kwargs['args']
138
+ input_text = args['input_text']
139
+ mode = args.get('mode', 'basic')
140
+
141
+ show_text = f"正在使用 {{ display_name }} 工具处理文本内容"
142
+ if mode == 'advanced':
143
+ show_text += "(高级模式)"
144
+
145
+ return Tool.markdown_terminal(
146
+ show_text,
147
+ workdir=kwargs.get("task_id", ""),
148
+ user=kwargs.get("user", "Adam"),
149
+ conda_env=getattr(self, "CONDA_ENV", "base")
150
+ )
151
+
152
+ def call(self, kwargs):
153
+ """Tool 逻辑实现函数"""
154
+ args = kwargs['args']
155
+ input_text = args['input_text']
156
+ mode = args.get('mode', 'basic')
157
+
158
+ # TODO: 在这里实现你的主要逻辑
159
+ if mode == 'advanced':
160
+ result = f"高级模式处理: {input_text}"
161
+ else:
162
+ result = f"基础模式处理: {input_text}"
163
+
164
+ # 生成bash命令
165
+ bash_script = f'''# {{ display_name }} 处理脚本
166
+ echo "开始处理: {input_text}"
167
+ echo "处理模式: {mode}"
168
+
169
+ # TODO: 在这里添加实际的处理命令
170
+ echo "{result}"
171
+
172
+ # 生成输出文件
173
+ echo "处理完成" > {self.OUTPUT_FILE}
174
+ echo "结果: {result}" >> {self.OUTPUT_FILE}
175
+
176
+ echo "处理完成,结果已保存到 {self.OUTPUT_FILE}"
177
+ '''
178
+
179
+ return runCmd(bash_script)
180
+
181
+ def outputShow(self, kwargs):
182
+ """任务结束时调用,用于向用户展示工具执行结果。
183
+
184
+ Args:
185
+ kwargs (dict): 包含stdout、stderr、exit_code等执行结果的字典。
186
+
187
+ Returns:
188
+ tuple: (用户显示字符串, 文件列表) 元组。
189
+ - 用户显示字符串 (str): 格式化的显示文本
190
+ - 文件列表 (list): 生成的文件列表,会在前端提供下载
191
+ """
192
+ stdout = truncate_output(kwargs.get('stdout', ''))
193
+ stderr = truncate_output(kwargs.get('stderr', ''))
194
+ exit_code = kwargs.get('exit_code', 0)
195
+
196
+ display_text = format_output_display(
197
+ stdout, stderr, exit_code, "{{ display_name }} "
198
+ )
199
+
200
+ # 根据执行结果判断生成的文件
201
+ file_list = []
202
+ if exit_code == 0 or self.OUTPUT_FILE in kwargs.get('stdout', ''):
203
+ file_list.append(self.OUTPUT_FILE)
204
+
205
+ return display_text, file_list
206
+
207
+ def summary(self, kwargs):
208
+ """任务结束时调用,用于向AI提供执行结果摘要。
209
+
210
+ Args:
211
+ kwargs (dict): 包含stdout、stderr、exit_code等执行结果的字典。
212
+
213
+ Returns:
214
+ str: 给AI的文本摘要,应简洁明了,避免上下文过长。
215
+ """
216
+ stdout = truncate_output(kwargs.get('stdout', ''))
217
+ stderr = truncate_output(kwargs.get('stderr', ''))
218
+ exit_code = kwargs.get('exit_code', 0)
219
+
220
+ return generate_summary(
221
+ stdout, stderr, exit_code, "{{ display_name }}工具"
222
+ )
223
+
224
+
225
+ class {{ name.replace("-", "_") }}_advanced_tool(Tool, calltype="python"):
226
+ """{{ description }} - 高级功能
227
+
228
+ Args:
229
+ input_file (str): 输入文件路径
230
+ output_format (str): 输出格式,可选值:json、csv、txt
231
+ """
232
+ DISPLAY_NAME = "{{ display_name }}高级工具"
233
+ NETWORK = False
234
+ CPU = 1
235
+ GPU = 0
236
+ SIF = "adam-base:1.0.0"
237
+ CONDA_ENV = "base"
238
+
239
+ # 输出文件配置
240
+ OUTPUT_FILE = "result.json"
241
+ DEFAULT_OUTPUT_FORMAT = "json"
242
+
243
+ def inputShow(self, **kwargs):
244
+ """AI决定使用该工具时调用,用于向用户展示当前调用的工具信息。
245
+
246
+ Args:
247
+ kwargs (dict): 包含args、message、files、user、task_id等参数的字典。
248
+
249
+ Returns:
250
+ str: 给用户显示的字符串(可使用markdown渲染)。
251
+ """
252
+ args = kwargs['args']
253
+ input_file = args['input_file']
254
+ output_format = args.get('output_format', self.DEFAULT_OUTPUT_FORMAT)
255
+
256
+ show_text = (f"正在使用 {{ display_name }} 高级工具处理文件: {input_file}"
257
+ f"(输出格式: {output_format})")
258
+
259
+ return Tool.markdown_terminal(
260
+ show_text,
261
+ workdir=kwargs.get("task_id", ""),
262
+ user=kwargs.get("user", "Adam"),
263
+ conda_env=self.CONDA_ENV
264
+ )
265
+
266
+ def call(self, kwargs):
267
+ """Tool 逻辑实现函数"""
268
+ args = kwargs['args']
269
+ input_file = args['input_file']
270
+ output_format = args.get('output_format', self.DEFAULT_OUTPUT_FORMAT)
271
+
272
+ # TODO: 在这里实现你的Python逻辑
273
+ result = {
274
+ 'input_file': input_file,
275
+ 'output_format': output_format,
276
+ 'processed_at': datetime.datetime.now().isoformat(),
277
+ 'result': 'Python工具处理完成'
278
+ }
279
+
280
+ # 对于Python工具,必须使用print输出结果
281
+ print(f"Python工具处理完成,输入文件: {input_file}")
282
+ print(f"输出格式: {output_format}")
283
+ print(f"处理结果: {result}")
284
+
285
+ # 生成输出文件
286
+ if output_format == 'json':
287
+ with open(self.OUTPUT_FILE, 'w', encoding='utf-8') as f:
288
+ json.dump(result, f, indent=2, ensure_ascii=False)
289
+ print(f"结果已保存到 {self.OUTPUT_FILE}")
290
+
291
+ def outputShow(self, kwargs):
292
+ """任务结束时调用,用于向用户展示工具执行结果。
293
+
294
+ Args:
295
+ kwargs (dict): 包含stdout、stderr、exit_code等执行结果的字典。
296
+
297
+ Returns:
298
+ tuple: (用户显示字符串, 文件列表) 元组。
299
+ - 用户显示字符串 (str): 格式化的显示文本
300
+ - 文件列表 (list): 生成的文件列表,会在前端提供下载
301
+ """
302
+ stdout = truncate_output(kwargs.get('stdout', ''))
303
+ stderr = truncate_output(kwargs.get('stderr', ''))
304
+ exit_code = kwargs.get('exit_code', 0)
305
+
306
+ display_text = format_output_display(
307
+ stdout, stderr, exit_code, "{{ display_name }} 高级工具"
308
+ )
309
+
310
+ # 根据输出格式判断生成的文件
311
+ file_list = []
312
+ args = kwargs.get('args', {})
313
+ output_format = args.get('output_format', self.DEFAULT_OUTPUT_FORMAT)
314
+ if output_format == 'json' and exit_code == 0:
315
+ file_list.append(self.OUTPUT_FILE)
316
+
317
+ return display_text, file_list
318
+
319
+ def summary(self, kwargs):
320
+ """任务结束时调用,用于向AI提供执行结果摘要。
321
+
322
+ Args:
323
+ kwargs (dict): 包含stdout、stderr、exit_code等执行结果的字典。
324
+
325
+ Returns:
326
+ str: 给AI的文本摘要,应简洁明了,避免上下文过长。
327
+ """
328
+ stdout = truncate_output(kwargs.get('stdout', ''))
329
+ stderr = truncate_output(kwargs.get('stderr', ''))
330
+ exit_code = kwargs.get('exit_code', 0)
331
+
332
+ return generate_summary(
333
+ stdout, stderr, exit_code, "{{ display_name }}高级工具"
334
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: adam_community
3
- Version: 1.0.24
3
+ Version: 1.0.25
4
4
  Summary: Adam Community Tools and Utilities
5
5
  Home-page: https://github.com/yourusername/adam-community
6
6
  Author: Adam Community
@@ -1 +0,0 @@
1
- __version__ = "1.0.24"
@@ -1,139 +0,0 @@
1
- from adam_community.tool import Tool
2
- from adam_community.util import runCmd
3
-
4
- class {{ name.replace("-", "_") }}_tool(Tool):
5
- """
6
- {{ description }}
7
-
8
- :param str input_text: 输入的文本内容
9
- :param str? mode: 处理模式,可选值:basic、advanced
10
- """
11
-
12
- DISPLAY_NAME = "{{ display_name }}工具"
13
- NETWORK = False # 根据需要设置是否需要网络访问
14
- CPU = 1 # 需要的CPU数量
15
- GPU = 0 # 需要的GPU数量
16
- SIF = "adam-base:1.0.0" # 指定容器镜像(必填)
17
-
18
- def call(self, kwargs):
19
- """
20
- 工具的主要实现函数
21
-
22
- Args:
23
- kwargs: 包含args、message、files、user、task_id等参数的字典
24
-
25
- Returns:
26
- 执行结果字符串(bash命令)或直接执行结果
27
- """
28
- # 获取用户输入的参数
29
- input_text = kwargs['args']['input_text']
30
- mode = kwargs['args'].get('mode', 'basic')
31
-
32
- # TODO: 在这里实现你的主要逻辑
33
- if mode == 'advanced':
34
- result = f"高级模式处理: {input_text}"
35
- else:
36
- result = f"基础模式处理: {input_text}"
37
-
38
- # 生成bash命令
39
- bash_script = f'''
40
- # {{ display_name }} 处理脚本
41
- echo "开始处理: {input_text}"
42
- echo "处理模式: {mode}"
43
-
44
- # TODO: 在这里添加实际的处理命令
45
- echo "{result}"
46
-
47
- # 生成输出文件
48
- echo "处理完成" > output.txt
49
- echo "结果: {result}" >> output.txt
50
-
51
- echo "处理完成,结果已保存到 output.txt"
52
- '''
53
-
54
- return runCmd(bash_script)
55
-
56
- def outputShow(self, kwargs):
57
- """
58
- 自定义输出显示格式(可选)
59
- """
60
- stdout = kwargs.get('stdout', '')
61
- stderr = kwargs.get('stderr', '')
62
-
63
- display_text = f"""## 🎉 {{ display_name }} 处理完成
64
-
65
- ### 📋 处理结果
66
- ```
67
- {stdout}
68
- ```
69
- """
70
-
71
- if stderr:
72
- display_text += f"""
73
- ### ⚠️ 警告信息
74
- ```
75
- {stderr}
76
- ```
77
- """
78
-
79
- # 返回可能生成的文件
80
- file_list = ['output.txt'] if 'output.txt' in stdout else []
81
-
82
- return display_text, file_list
83
-
84
- def summary(self, kwargs):
85
- """
86
- 为AI生成简短的执行摘要
87
- """
88
- stdout = kwargs.get('stdout', '')
89
- stderr = kwargs.get('stderr', '')
90
-
91
- if stderr:
92
- return f"{{ display_name }}工具执行完成但有警告: {stdout[:200]}...。警告: {stderr[:100]}"
93
- else:
94
- return f"{{ display_name }}工具执行成功: {stdout[:200]}..."
95
-
96
-
97
- class {{ name.replace("-", "_") }}_advanced_tool(Tool, calltype="python"):
98
- """
99
- {{ description }} - 高级功能
100
-
101
- :param str input_file: 输入文件路径
102
- :param str output_format: 输出格式,可选值:json、csv、txt
103
- """
104
-
105
- DISPLAY_NAME = "{{ display_name }}高级工具"
106
- NETWORK = False # 根据需要设置是否需要网络访问
107
- CPU = 1 # 需要的CPU数量
108
- GPU = 0 # 需要的GPU数量
109
- SIF = "adam-base:1.0.0" # 指定容器镜像(必填)
110
- CONDA_ENV = "base" # 指定conda环境
111
-
112
- def call(self, kwargs):
113
- """
114
- Python类型工具的实现
115
- """
116
- import json
117
- import datetime
118
-
119
- input_file = kwargs['args']['input_file']
120
- output_format = kwargs['args'].get('output_format', 'json')
121
-
122
- # TODO: 在这里实现你的Python逻辑
123
- result = {
124
- 'input_file': input_file,
125
- 'output_format': output_format,
126
- 'processed_at': datetime.datetime.now().isoformat(),
127
- 'result': 'Python工具处理完成'
128
- }
129
-
130
- # 对于Python工具,必须使用print输出结果
131
- print(f"Python工具处理完成,输入文件: {input_file}")
132
- print(f"输出格式: {output_format}")
133
- print(f"处理结果: {result}")
134
-
135
- # 生成输出文件
136
- if output_format == 'json':
137
- with open('result.json', 'w', encoding='utf-8') as f:
138
- json.dump(result, f, indent=2, ensure_ascii=False)
139
- print("结果已保存到 result.json")