pycoze 0.1.342__py3-none-any.whl → 0.1.344__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.
- pycoze/bot/chat_base.py +0 -1
- pycoze/bot/tools.py +39 -19
- {pycoze-0.1.342.dist-info → pycoze-0.1.344.dist-info}/METADATA +1 -1
- {pycoze-0.1.342.dist-info → pycoze-0.1.344.dist-info}/RECORD +7 -7
- {pycoze-0.1.342.dist-info → pycoze-0.1.344.dist-info}/LICENSE +0 -0
- {pycoze-0.1.342.dist-info → pycoze-0.1.344.dist-info}/WHEEL +0 -0
- {pycoze-0.1.342.dist-info → pycoze-0.1.344.dist-info}/top_level.txt +0 -0
pycoze/bot/chat_base.py
CHANGED
pycoze/bot/tools.py
CHANGED
@@ -53,7 +53,7 @@ class ExecuteCommandTool(Tool):
|
|
53
53
|
shell=True,
|
54
54
|
capture_output=True,
|
55
55
|
text=True,
|
56
|
-
cwd=self.cwd
|
56
|
+
cwd=self.cwd,
|
57
57
|
)
|
58
58
|
if result.returncode != 0:
|
59
59
|
raise subprocess.CalledProcessError(
|
@@ -73,7 +73,9 @@ class ReadFileTool(Tool):
|
|
73
73
|
"""读取文件工具"""
|
74
74
|
|
75
75
|
def validate(self) -> bool:
|
76
|
-
return "path" in self.params and os.path.exists(
|
76
|
+
return "path" in self.params and os.path.exists(
|
77
|
+
resolve_relative_path(self.cwd, self.params["path"])
|
78
|
+
)
|
77
79
|
|
78
80
|
def execute(self) -> str:
|
79
81
|
path = resolve_relative_path(self.cwd, self.params["path"])
|
@@ -196,13 +198,15 @@ class WebAccessTool(Tool):
|
|
196
198
|
try:
|
197
199
|
content = web.get_simplified_webpage(url)[: 32 * 1024]
|
198
200
|
result = ai.chat(
|
199
|
-
[
|
200
|
-
|
201
|
-
|
201
|
+
[
|
202
|
+
{
|
203
|
+
"role": "user",
|
204
|
+
"content": f"""Please answer user question based on web page content. The user's question is:
|
202
205
|
{question}
|
203
206
|
Web page content is:
|
204
|
-
{content}"""
|
205
|
-
|
207
|
+
{content}""",
|
208
|
+
}
|
209
|
+
],
|
206
210
|
)
|
207
211
|
return f"Web page access completed, result is: {result}"
|
208
212
|
except Exception as e:
|
@@ -214,10 +218,10 @@ class AskFollowUpQuestionTool(Tool):
|
|
214
218
|
"""询问后续问题工具"""
|
215
219
|
|
216
220
|
def validate(self) -> bool:
|
217
|
-
return
|
221
|
+
return "question" in self.params
|
218
222
|
|
219
223
|
def execute(self) -> str:
|
220
|
-
info("assistant", self.params[
|
224
|
+
info("assistant", self.params["question"])
|
221
225
|
return f"Asked user: {self.params['question']}, Waiting for user replied.\n\n"
|
222
226
|
|
223
227
|
|
@@ -225,13 +229,25 @@ class AttemptTaskCompletionTool(Tool):
|
|
225
229
|
"""完成所有任务工具"""
|
226
230
|
|
227
231
|
def validate(self) -> bool:
|
228
|
-
return
|
232
|
+
return "result" in self.params
|
229
233
|
|
230
234
|
def execute(self) -> str:
|
231
|
-
result = self.params[
|
232
|
-
info("assistant",
|
233
|
-
if
|
234
|
-
|
235
|
+
result = self.params["result"]
|
236
|
+
info("assistant", "Completed:" + result + "\n")
|
237
|
+
if (
|
238
|
+
"command" in self.params
|
239
|
+
and self.params["command"] is not None
|
240
|
+
and type(self.params["command"]) == str
|
241
|
+
and len(type(self.params["command"])) > 0
|
242
|
+
):
|
243
|
+
print("run command")
|
244
|
+
result = subprocess.run(
|
245
|
+
self.params["command"],
|
246
|
+
shell=True,
|
247
|
+
capture_output=True,
|
248
|
+
text=True,
|
249
|
+
cwd=self.cwd,
|
250
|
+
)
|
235
251
|
return f"Task completed: {result}, executed command: {self.params['command']}, execution result: {result.stdout + result.stderr}"
|
236
252
|
else:
|
237
253
|
return f"Task completed: {result}"
|
@@ -249,12 +265,12 @@ class ToolExecutor:
|
|
249
265
|
"search_files": SearchFilesTool,
|
250
266
|
"list_files": ListFilesTool,
|
251
267
|
"access_webpage": WebAccessTool,
|
252
|
-
|
253
|
-
|
268
|
+
"ask_follow_up_question": AskFollowUpQuestionTool,
|
269
|
+
"complete_all_tasks": AttemptTaskCompletionTool,
|
254
270
|
}
|
255
271
|
|
256
272
|
@classmethod
|
257
|
-
def execute_tool(cls, cwd:str, tool_request, abilities) -> Tuple[bool, bool, any]:
|
273
|
+
def execute_tool(cls, cwd: str, tool_request, abilities) -> Tuple[bool, bool, any]:
|
258
274
|
"""执行工具"""
|
259
275
|
try:
|
260
276
|
tool_name = list(tool_request.keys())[0]
|
@@ -274,9 +290,13 @@ class ToolExecutor:
|
|
274
290
|
result = json.dumps(result, indent=4, ensure_ascii=False)
|
275
291
|
except:
|
276
292
|
return True, False, str(result)
|
277
|
-
return True, True,str(result)
|
293
|
+
return True, True, str(result)
|
278
294
|
else:
|
279
|
-
return
|
295
|
+
return (
|
296
|
+
False,
|
297
|
+
False,
|
298
|
+
f"Unknown tool: {tool_name}, the first key of output json ({tool_name}) will be recognized as a tool, so do not output other json except for executing tools.",
|
299
|
+
)
|
280
300
|
tool = tool_class(params, cwd)
|
281
301
|
if not tool.validate():
|
282
302
|
return False, False, "Tool parameter validation failed."
|
@@ -13,11 +13,11 @@ pycoze/api/lib/web.py,sha256=GWgtiTJOolKOX2drXcwuyqTcbo5FQVxa1NuBGcNyjyc,223
|
|
13
13
|
pycoze/api/lib/window.py,sha256=bTkQCzQZ7i3pYXB70bUSTBNJ9C4TW_X3yMae1VkquGk,1944
|
14
14
|
pycoze/bot/__init__.py,sha256=rL3Q-ycczRpSFfKn84fg3QBl5k22WpyeIU5qOEjEby8,79
|
15
15
|
pycoze/bot/chat.py,sha256=DB0fUb4B0EVRWWEavCzIa-cSXOpiZrxIusJnQYGPKG8,3765
|
16
|
-
pycoze/bot/chat_base.py,sha256=
|
16
|
+
pycoze/bot/chat_base.py,sha256=ll9ulBPfKtsrJYLqBsrgaFKU7WjIPRDa-LjwCS6xM_M,9666
|
17
17
|
pycoze/bot/lib.py,sha256=smigeWuhl8esHE-Y5l_9bpjJkEJ5OqrxTyPcO8JIubM,7224
|
18
18
|
pycoze/bot/message.py,sha256=Zq-_k8HztBMOUIs3hbOvWvwHBNopn4UJJBliCROIGcc,718
|
19
19
|
pycoze/bot/prompt.md,sha256=OBxwUY6yiwEmusnUHhwixWYByrWX3BpwfxG_Gfas8UM,15783
|
20
|
-
pycoze/bot/tools.py,sha256=
|
20
|
+
pycoze/bot/tools.py,sha256=twKBmaWiVB8kwEpSn50YsUN8ghwhi7pWrlPQZYPy_14,10419
|
21
21
|
pycoze/reference/__init__.py,sha256=zgqGqvmA9HaqytEM33B6vi0kQVk8IiCwJaXa22xsFz8,114
|
22
22
|
pycoze/reference/bot.py,sha256=pxHVYo0G3P3YZ--vBYbMEiEyBoxxPwaO5dMTf9WFMSc,2014
|
23
23
|
pycoze/reference/lib.py,sha256=T-oBOKxkus5dTouc0oDgfRzUyi6aTyY-FF4yX7SzF5M,3755
|
@@ -33,8 +33,8 @@ pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
|
|
33
33
|
pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
|
34
34
|
pycoze/utils/socket.py,sha256=bZbFFRH4mfThzRqt55BAAGQ6eICx_ja4x8UGGrUdAm8,2428
|
35
35
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
36
|
-
pycoze-0.1.
|
37
|
-
pycoze-0.1.
|
38
|
-
pycoze-0.1.
|
39
|
-
pycoze-0.1.
|
40
|
-
pycoze-0.1.
|
36
|
+
pycoze-0.1.344.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
37
|
+
pycoze-0.1.344.dist-info/METADATA,sha256=8QzoWSDoddsmCYZZrABnfy2I8Axhj5QxHe6po9J7Q40,755
|
38
|
+
pycoze-0.1.344.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
|
39
|
+
pycoze-0.1.344.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
40
|
+
pycoze-0.1.344.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|