pycoze 0.1.283__py3-none-any.whl → 0.1.285__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/api/lib/window_cls.py +59 -46
- pycoze/bot/agent/chat.py +2 -2
- pycoze/reference/bot.py +61 -64
- {pycoze-0.1.283.dist-info → pycoze-0.1.285.dist-info}/METADATA +1 -1
- {pycoze-0.1.283.dist-info → pycoze-0.1.285.dist-info}/RECORD +8 -8
- {pycoze-0.1.283.dist-info → pycoze-0.1.285.dist-info}/LICENSE +0 -0
- {pycoze-0.1.283.dist-info → pycoze-0.1.285.dist-info}/WHEEL +0 -0
- {pycoze-0.1.283.dist-info → pycoze-0.1.285.dist-info}/top_level.txt +0 -0
pycoze/api/lib/window_cls.py
CHANGED
@@ -1,46 +1,59 @@
|
|
1
|
-
import sys
|
2
|
-
import subprocess
|
3
|
-
import os
|
4
|
-
from pycoze import utils
|
5
|
-
|
6
|
-
|
7
|
-
socket = utils.socket
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
socket.post("
|
22
|
-
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
1
|
+
import sys
|
2
|
+
import subprocess
|
3
|
+
import os
|
4
|
+
from pycoze import utils
|
5
|
+
|
6
|
+
|
7
|
+
socket = utils.socket
|
8
|
+
|
9
|
+
|
10
|
+
class WindowCls:
|
11
|
+
|
12
|
+
def message(self, message: str, type: str = "info"):
|
13
|
+
assert type in [
|
14
|
+
"info",
|
15
|
+
"warning",
|
16
|
+
"success",
|
17
|
+
"error",
|
18
|
+
], "type must be info, warning, success or error"
|
19
|
+
if not isinstance(message, str):
|
20
|
+
message = repr(message)
|
21
|
+
socket.post("append-msg", {"message": message, "type": type})
|
22
|
+
|
23
|
+
def confirm(self, title: str, message: str) -> bool:
|
24
|
+
return socket.post_and_recv_result(
|
25
|
+
"confirm", {"title": title, "message": message}
|
26
|
+
)
|
27
|
+
|
28
|
+
def input(self, title: str, message: str) -> str:
|
29
|
+
return socket.post_and_recv_result(
|
30
|
+
"input", {"title": title, "message": message}
|
31
|
+
)
|
32
|
+
|
33
|
+
def maximize(self):
|
34
|
+
socket.post("maximize", {})
|
35
|
+
|
36
|
+
def get_slected_text(self) -> str:
|
37
|
+
result = socket.post_and_recv_result("get-selected-text", {})
|
38
|
+
return result
|
39
|
+
|
40
|
+
def open_file_with_system(self, file_path, wait: bool):
|
41
|
+
process_fn = subprocess.run if wait else subprocess.Popen
|
42
|
+
if sys.platform.startswith("linux"):
|
43
|
+
process_fn(["xdg-open", file_path])
|
44
|
+
elif sys.platform.startswith("darwin"):
|
45
|
+
process_fn(["open", file_path])
|
46
|
+
elif sys.platform.startswith("win32") or sys.platform.startswith("cygwin"):
|
47
|
+
os.startfile(file_path)
|
48
|
+
else:
|
49
|
+
raise OSError("Unsupported operating system")
|
50
|
+
|
51
|
+
def open_program(self, program_path, wait: bool):
|
52
|
+
process_fn = subprocess.run if wait else subprocess.Popen
|
53
|
+
process_fn([program_path])
|
54
|
+
|
55
|
+
def execute_javaScript(self, js_code: str):
|
56
|
+
result = socket.post_and_recv_result("executeJavaScript", {"code": js_code})
|
57
|
+
if not result["ok"]:
|
58
|
+
raise Exception(result["value"])
|
59
|
+
return result["value"] if "value" in result else None
|
pycoze/bot/agent/chat.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import json
|
2
|
-
from langchain_core.messages import AIMessage
|
3
2
|
|
4
3
|
|
5
4
|
INPUT_MESSAGE = "INPUT_MESSAGE=>"
|
@@ -9,7 +8,7 @@ _INFOMATION_MESSAGE = "INFOMATION_MESSAGE=>"
|
|
9
8
|
_LOG = "LOG=>"
|
10
9
|
|
11
10
|
|
12
|
-
CHAT_DATA = {"output":"", "info": ""}
|
11
|
+
CHAT_DATA = {"output": "", "info": ""}
|
13
12
|
|
14
13
|
|
15
14
|
def log(content, *args, end="\n", **kwargs):
|
@@ -27,6 +26,7 @@ def output(role, content):
|
|
27
26
|
CHAT_DATA["output"] = content
|
28
27
|
print(_OUTPUT_MESSAGE + json.dumps({"role": role, "content": content}))
|
29
28
|
|
29
|
+
|
30
30
|
def info(role, content):
|
31
31
|
CHAT_DATA["info"] += content
|
32
32
|
print(_INFOMATION_MESSAGE + json.dumps({"role": role, "content": content}))
|
pycoze/reference/bot.py
CHANGED
@@ -1,64 +1,61 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
|
5
|
-
import
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
tool
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
except Exception as e:
|
63
|
-
print(f"Error loading bot {bot_id}: {e}")
|
64
|
-
return None
|
1
|
+
import os
|
2
|
+
from langchain.agents import tool as to_agent_tool
|
3
|
+
from .lib import ModuleManager, wrapped_func
|
4
|
+
import json
|
5
|
+
from pycoze import utils
|
6
|
+
|
7
|
+
bot_index = 0
|
8
|
+
|
9
|
+
params = utils.params
|
10
|
+
|
11
|
+
|
12
|
+
def ref_bot(bot_id, as_agent_tool=False, workspace_path=None):
|
13
|
+
global bot_index
|
14
|
+
if workspace_path is None:
|
15
|
+
workspace_path = params["workspacePath"]
|
16
|
+
tool_base_path = os.path.join(workspace_path, "User/Local/bot")
|
17
|
+
module_path = os.path.join(tool_base_path, bot_id)
|
18
|
+
module_path = os.path.normpath(os.path.abspath(module_path))
|
19
|
+
|
20
|
+
if not os.path.exists(module_path):
|
21
|
+
print(f"Bot {bot_id} not found in:" + module_path)
|
22
|
+
return None
|
23
|
+
|
24
|
+
try:
|
25
|
+
with ModuleManager(module_path) as manager:
|
26
|
+
info = module_path + "/info.json"
|
27
|
+
with open(info, "r", encoding="utf-8") as f:
|
28
|
+
info = json.load(f)
|
29
|
+
name = info["name"]
|
30
|
+
random_name = "bot_" + str(bot_index)
|
31
|
+
bot_index += 1
|
32
|
+
function_code = f"""
|
33
|
+
def {random_name}(command:str) -> str:
|
34
|
+
\"\"\"接收任意指令字符串,并返回AI角色({name}专家)深入思考和执行指令后的字符串结果。
|
35
|
+
AI角色({name}专家)擅长使用各种工具,并会给出专业且更为准确的结果。
|
36
|
+
|
37
|
+
Args:
|
38
|
+
command (str): AI角色({name}专家)需要执行的指令字符串。
|
39
|
+
|
40
|
+
Returns:
|
41
|
+
str: AI角色({name}专家)执行指令后的结果。
|
42
|
+
\"\"\"
|
43
|
+
from pycoze import bot
|
44
|
+
from pycoze import utils
|
45
|
+
import tempfile
|
46
|
+
|
47
|
+
with tempfile.NamedTemporaryFile(delete=True, mode='w+t') as temp_file:
|
48
|
+
sys.stdout = temp_file # 将输出重定向到临时文件,防止影响AI结果
|
49
|
+
result = bot.get_chat_response("botSetting.json", command)
|
50
|
+
sys.stdout = sys.__stdout__ # 恢复标准输出
|
51
|
+
return result
|
52
|
+
"""
|
53
|
+
exec(function_code)
|
54
|
+
tool = to_agent_tool(eval(random_name))
|
55
|
+
tool.func = wrapped_func(tool, module_path)
|
56
|
+
if tool.description is None:
|
57
|
+
tool.description = "This tool is used to " + tool.name + "."
|
58
|
+
return tool if as_agent_tool else tool.func
|
59
|
+
except Exception as e:
|
60
|
+
print(f"Error loading bot {bot_id}: {e}")
|
61
|
+
return None
|
@@ -9,19 +9,19 @@ pycoze/api/__init__.py,sha256=GGRRRPop0ZxdXe5JRhg2XvHITGIWfNcHA25opJZ0f1w,313
|
|
9
9
|
pycoze/api/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
pycoze/api/lib/tab_cls.py,sha256=lD2Uvylzi-zsHj-27YI1mS4ggbIGtCi3vypvGvY48gM,2619
|
11
11
|
pycoze/api/lib/view.py,sha256=_PIpTfeuTPPlMDKshMGsqFQYMq7ZiO4Hg5XwHwDoU60,7357
|
12
|
-
pycoze/api/lib/window_cls.py,sha256=
|
12
|
+
pycoze/api/lib/window_cls.py,sha256=bTkQCzQZ7i3pYXB70bUSTBNJ9C4TW_X3yMae1VkquGk,1944
|
13
13
|
pycoze/bot/__init__.py,sha256=JxnRoCCqx_LFyVb3pLu0qYCsH8ZLuAaMXAtvVUuCHuE,78
|
14
14
|
pycoze/bot/agent_chat.py,sha256=ARXXsIVCTpmBojz2C4BR69nB0QhM6gkEngL3iq34JPo,4178
|
15
15
|
pycoze/bot/bot.py,sha256=_qmUTZ09FmRLifHrW5stDZWGVK6yuMEMBC3fmeYJnqk,844
|
16
16
|
pycoze/bot/agent/__init__.py,sha256=3wE8_FFQS8j2BY-g9Cr-onV0POEvDRZaw_NCzpqrNus,265
|
17
17
|
pycoze/bot/agent/agent.py,sha256=qkLIRgSMNT1VD_UD0e6kYUuOTOqylQiYSCay6HZ12LA,3653
|
18
18
|
pycoze/bot/agent/assistant.py,sha256=5LIgPIVVzx6uIOWT5S_XDDyPPjPHRBBNpIU3GiOkVHc,1186
|
19
|
-
pycoze/bot/agent/chat.py,sha256=
|
19
|
+
pycoze/bot/agent/chat.py,sha256=9wZ24CPdSbSnPCWmCQJle05U5VlDGgZhZ9z1mezLst0,816
|
20
20
|
pycoze/bot/agent/agent_types/__init__.py,sha256=zmU2Kmrv5mCdfg-QlPn2H6pWxbGeq8s7YTqLhpzJC6k,179
|
21
21
|
pycoze/bot/agent/agent_types/const.py,sha256=BfUKPrhAHREoMLHuFNG2bCIEkC1-f7K0LEqNg4RwiRE,70
|
22
22
|
pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=6aKnUQDINyUaCW24oa9Qjkm5w3ctZ6lxAgcE4m9YHwE,6701
|
23
23
|
pycoze/reference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
|
-
pycoze/reference/bot.py,sha256=
|
24
|
+
pycoze/reference/bot.py,sha256=d5uB0OH1MF3LXGoBAF6vX6y50IV3sOrNi_5hXAHAmGU,2255
|
25
25
|
pycoze/reference/lib.py,sha256=0xQJTLTHedGzQBsjuTFNBVqYc4-8Yl65gGCrAhWyOX8,2155
|
26
26
|
pycoze/reference/tool.py,sha256=CYUS95M_XGnUcl4uWayjzKOM9jGpylS7vWJ66JfNTjI,1710
|
27
27
|
pycoze/reference/workflow.py,sha256=LiubvvhGa6KoVIP8W8D8zTZaL595M4Dorsa_kxZ8UgQ,2028
|
@@ -35,8 +35,8 @@ pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
|
|
35
35
|
pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
|
36
36
|
pycoze/utils/socket.py,sha256=bZbFFRH4mfThzRqt55BAAGQ6eICx_ja4x8UGGrUdAm8,2428
|
37
37
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
38
|
-
pycoze-0.1.
|
39
|
-
pycoze-0.1.
|
40
|
-
pycoze-0.1.
|
41
|
-
pycoze-0.1.
|
42
|
-
pycoze-0.1.
|
38
|
+
pycoze-0.1.285.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
39
|
+
pycoze-0.1.285.dist-info/METADATA,sha256=Qb3Dk-FsO1-K9xMul-gH7ds6KoH56qCjAH2RpUJPNqY,755
|
40
|
+
pycoze-0.1.285.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
|
41
|
+
pycoze-0.1.285.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
42
|
+
pycoze-0.1.285.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|