pycoze 0.1.14__py3-none-any.whl → 0.1.16__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/__init__.py +4 -3
- pycoze/bot/agent/agent.py +72 -67
- pycoze/ui/ui_def.py +85 -28
- {pycoze-0.1.14.dist-info → pycoze-0.1.16.dist-info}/METADATA +1 -1
- {pycoze-0.1.14.dist-info → pycoze-0.1.16.dist-info}/RECORD +8 -8
- {pycoze-0.1.14.dist-info → pycoze-0.1.16.dist-info}/LICENSE +0 -0
- {pycoze-0.1.14.dist-info → pycoze-0.1.16.dist-info}/WHEEL +0 -0
- {pycoze-0.1.14.dist-info → pycoze-0.1.16.dist-info}/top_level.txt +0 -0
pycoze/__init__.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
from . import bot
|
2
|
-
from . import
|
3
|
-
from . import ui
|
1
|
+
from . import bot
|
2
|
+
from . import gpu
|
3
|
+
from . import ui
|
4
|
+
from . import utils
|
pycoze/bot/agent/agent.py
CHANGED
@@ -1,67 +1,72 @@
|
|
1
|
-
import asyncio
|
2
|
-
import json
|
3
|
-
from langchain_openai import ChatOpenAI
|
4
|
-
from .chat import info
|
5
|
-
from .assistant import Runnable
|
6
|
-
from langchain_core.messages import HumanMessage, AIMessage,AIMessageChunk
|
7
|
-
from langchain_core.agents import AgentFinish
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
async def run_agent(agent, inputs: list):
|
12
|
-
if agent.agent_execution_mode == 'FuncCall':
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
1
|
+
import asyncio
|
2
|
+
import json
|
3
|
+
from langchain_openai import ChatOpenAI
|
4
|
+
from .chat import info
|
5
|
+
from .assistant import Runnable
|
6
|
+
from langchain_core.messages import HumanMessage, AIMessage,AIMessageChunk
|
7
|
+
from langchain_core.agents import AgentFinish
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
async def run_agent(agent, inputs: list):
|
12
|
+
if agent.agent_execution_mode == 'FuncCall':
|
13
|
+
exist_ids = set()
|
14
|
+
content_list = []
|
15
|
+
async for event in agent.astream_events(inputs, version="v2"):
|
16
|
+
kind = event["event"]
|
17
|
+
if kind == "on_chat_model_stream":
|
18
|
+
content = event["data"]["chunk"].content
|
19
|
+
if content:
|
20
|
+
content_list.append(content)
|
21
|
+
info("assistant", content)
|
22
|
+
elif kind == "on_chain_start":
|
23
|
+
data = event["data"]
|
24
|
+
if "input" in data:
|
25
|
+
input_list = data["input"] if isinstance(data["input"], list) else [data["input"]]
|
26
|
+
msg = input_list[-1]
|
27
|
+
if isinstance(msg, AIMessage) and not isinstance(msg, AIMessageChunk):
|
28
|
+
if "tool_calls" in msg.additional_kwargs:
|
29
|
+
tool_calls = msg.additional_kwargs["tool_calls"]
|
30
|
+
for t in tool_calls:
|
31
|
+
if t["id"] in exist_ids:
|
32
|
+
continue
|
33
|
+
exist_ids.add(t["id"])
|
34
|
+
tool = t["function"]["name"]
|
35
|
+
info("assistant", f"[调用工具:{tool}]")
|
36
|
+
|
37
|
+
return "".join(content_list)
|
38
|
+
else:
|
39
|
+
assert agent.agent_execution_mode == 'ReAct'
|
40
|
+
inputs_msg = {'input': inputs[-1].content,'chat_history': inputs[:-1]}
|
41
|
+
use_tools = []
|
42
|
+
async for event in agent.astream_events(inputs_msg, version="v2"):
|
43
|
+
kind = event["event"]
|
44
|
+
result = None
|
45
|
+
if kind == "on_chain_end":
|
46
|
+
if 'data' in event:
|
47
|
+
if 'output' in event['data']:
|
48
|
+
output = event['data']['output']
|
49
|
+
if 'agent_outcome' in output and "input" in output:
|
50
|
+
outcome = output['agent_outcome']
|
51
|
+
if isinstance(outcome, AgentFinish):
|
52
|
+
result = outcome.return_values['output']
|
53
|
+
elif kind == "on_tool_start":
|
54
|
+
use_tools.append(event['name'])
|
55
|
+
info("assistant", f"[调用工具:{use_tools}]")
|
56
|
+
return result
|
57
|
+
|
58
|
+
|
59
|
+
if __name__ == "__main__":
|
60
|
+
from langchain_experimental.tools import PythonREPLTool
|
61
|
+
llm_file = r"C:\Users\aiqqq\AppData\Roaming\pycoze\JsonStorage\llm.json"
|
62
|
+
with open(llm_file, "r", encoding="utf-8") as f:
|
63
|
+
cfg = json.load(f)
|
64
|
+
chat = ChatOpenAI(api_key=cfg["apiKey"], base_url=cfg['baseURL'], model=cfg["model"], temperature=0)
|
65
|
+
python_tool = PythonREPLTool()
|
66
|
+
agent = Runnable(agent_execution_mode='FuncCall', # 'FuncCall' or 'ReAct',大模型支持FuncCall的话就用FuncCall
|
67
|
+
tools=[python_tool],
|
68
|
+
llm=chat,
|
69
|
+
assistant_message="请以女友的口吻回答,输出不小于100字,可以随便说点其他的",)
|
70
|
+
|
71
|
+
inputs = [HumanMessage(content="计算根号7+根号88")]
|
72
|
+
print(asyncio.run(run_agent(agent, inputs)))
|
pycoze/ui/ui_def.py
CHANGED
@@ -5,7 +5,6 @@ from .color import hex_to_rgb, rgb_to_hsl, ColorFormat
|
|
5
5
|
import sys
|
6
6
|
|
7
7
|
|
8
|
-
|
9
8
|
def useDefault(name, default):
|
10
9
|
ui_data = get_ui()
|
11
10
|
if name not in ui_data:
|
@@ -15,9 +14,9 @@ def useDefault(name, default):
|
|
15
14
|
|
16
15
|
def get_ui_text():
|
17
16
|
ui = get_ui()
|
18
|
-
output =
|
17
|
+
output = ""
|
19
18
|
for key, value in ui.items():
|
20
|
-
output += f
|
19
|
+
output += f"{key}: {value}\n"
|
21
20
|
return output
|
22
21
|
|
23
22
|
|
@@ -25,15 +24,17 @@ def label(name, tip="", hide_if="", style="", cls=""):
|
|
25
24
|
pass
|
26
25
|
|
27
26
|
|
28
|
-
def number(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
def number(
|
28
|
+
name,
|
29
|
+
default,
|
30
|
+
min=-sys.maxsize - 1,
|
31
|
+
max=sys.maxsize,
|
32
|
+
step=1,
|
33
|
+
tip="",
|
34
|
+
hide_if="",
|
35
|
+
style="",
|
36
|
+
cls="",
|
37
|
+
) -> Union[int, float]: # 注意Python3.9不兼容int|float
|
37
38
|
return useDefault(name, default)
|
38
39
|
|
39
40
|
|
@@ -49,7 +50,15 @@ def password(name, default, tip="", hide_if="", style="", cls="") -> str:
|
|
49
50
|
return useDefault(name, default)
|
50
51
|
|
51
52
|
|
52
|
-
def color(
|
53
|
+
def color(
|
54
|
+
name,
|
55
|
+
default,
|
56
|
+
color_format: ColorFormat = "hex",
|
57
|
+
tip="",
|
58
|
+
hide_if="",
|
59
|
+
style="",
|
60
|
+
cls="",
|
61
|
+
) -> str:
|
53
62
|
rgbhex = useDefault(name, default)
|
54
63
|
if color_format == "hex":
|
55
64
|
return rgbhex
|
@@ -64,47 +73,95 @@ def checkbox(name, default, tip="", hide_if="", style="", cls="") -> bool:
|
|
64
73
|
return useDefault(name, default)
|
65
74
|
|
66
75
|
|
67
|
-
def single_select(
|
76
|
+
def single_select(
|
77
|
+
name,
|
78
|
+
default: Union[str, int, float, bool],
|
79
|
+
options,
|
80
|
+
tip="",
|
81
|
+
hide_if="",
|
82
|
+
style="",
|
83
|
+
cls="",
|
84
|
+
):
|
85
|
+
return useDefault(name, default)
|
86
|
+
|
87
|
+
|
88
|
+
def multi_select(
|
89
|
+
name,
|
90
|
+
default: Union[List[str], List[int], List[float], List[bool]],
|
91
|
+
options,
|
92
|
+
tip="",
|
93
|
+
hide_if="",
|
94
|
+
style="",
|
95
|
+
cls="",
|
96
|
+
):
|
68
97
|
return useDefault(name, default)
|
69
98
|
|
70
99
|
|
71
|
-
def
|
72
|
-
default: Union[List[str], List[int], List[float], List[bool]],
|
73
|
-
options,
|
74
|
-
tip="",
|
75
|
-
hide_if="",
|
76
|
-
style="",
|
77
|
-
cls=""):
|
100
|
+
def single_file_select(name, default: str, tip="", hide_if="", style="", cls="") -> str:
|
78
101
|
return useDefault(name, default)
|
79
102
|
|
80
103
|
|
81
|
-
def
|
104
|
+
def multi_file_select(
|
105
|
+
name, default: List[str], tip="", hide_if="", style="", cls=""
|
106
|
+
) -> List[str]:
|
82
107
|
return useDefault(name, default)
|
83
108
|
|
84
109
|
|
85
|
-
def
|
110
|
+
def single_folder_select(
|
111
|
+
name, default: str, tip="", hide_if="", style="", cls=""
|
112
|
+
) -> str:
|
86
113
|
return useDefault(name, default)
|
87
114
|
|
88
115
|
|
89
|
-
def
|
116
|
+
def multi_folder_select(
|
117
|
+
name, default: List[str], tip="", hide_if="", style="", cls=""
|
118
|
+
) -> List[str]:
|
119
|
+
return useDefault(name, default)
|
120
|
+
|
121
|
+
|
122
|
+
def folder_tree(
|
123
|
+
name, root="", default: List[str] = None, tip="", hide_if="", style="", cls=""
|
124
|
+
) -> dict:
|
90
125
|
if default is None:
|
91
126
|
default = []
|
92
127
|
return useDefault(name, default)
|
93
128
|
|
94
129
|
|
95
|
-
def
|
130
|
+
def single_image_select(
|
131
|
+
name, default: str, tip="", hide_if="", style="", cls=""
|
132
|
+
) -> str:
|
96
133
|
return useDefault(name, default)
|
97
134
|
|
98
135
|
|
99
|
-
def
|
136
|
+
def multi_image_select(
|
137
|
+
name, default: List[str], tip="", hide_if="", style="", cls=""
|
138
|
+
) -> List[str]:
|
100
139
|
return useDefault(name, default)
|
101
140
|
|
102
141
|
|
103
|
-
def
|
142
|
+
def single_audio_select(
|
143
|
+
name, default: str, tip="", hide_if="", style="", cls=""
|
144
|
+
) -> str:
|
104
145
|
return useDefault(name, default)
|
105
146
|
|
106
147
|
|
107
|
-
def
|
148
|
+
def multi_audio_select(
|
149
|
+
name, default: List[str], tip="", hide_if="", style="", cls=""
|
150
|
+
) -> List[str]:
|
108
151
|
return useDefault(name, default)
|
109
152
|
|
110
153
|
|
154
|
+
def single_video_select(
|
155
|
+
name, default: str, tip="", hide_if="", style="", cls=""
|
156
|
+
) -> str:
|
157
|
+
return useDefault(name, default)
|
158
|
+
|
159
|
+
|
160
|
+
def multi_video_select(
|
161
|
+
name, default: List[str], tip="", hide_if="", style="", cls=""
|
162
|
+
) -> List[str]:
|
163
|
+
return useDefault(name, default)
|
164
|
+
|
165
|
+
|
166
|
+
def seed(name, default=0, tip="", hide_if="", style="", cls="") -> int:
|
167
|
+
return useDefault(name, default)
|
@@ -1,10 +1,10 @@
|
|
1
|
-
pycoze/__init__.py,sha256=
|
1
|
+
pycoze/__init__.py,sha256=laqZFyAUfDnxpQQhullPKNaM1vKiaju7eOX_4yfWurc,73
|
2
2
|
pycoze/module.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
pycoze/bot/__init__.py,sha256=pciDtfcIXda7iFt9uI5Fpm0JKpGBhdXHmJv4966WTVU,21
|
4
4
|
pycoze/bot/base.py,sha256=-2EfIdcPZvFm1cjRyTIhjYsyRuAaSVdhdXJR5_7r4CE,2616
|
5
5
|
pycoze/bot/bot.py,sha256=3BxTejG164_7DFS47lDrEk-C49CrXa2WPnFxgSvZ6Wk,1836
|
6
6
|
pycoze/bot/agent/__init__.py,sha256=IaYqQCJ3uBor92JdOxI_EY4HtYOHgej8lijr3UrN1Vc,161
|
7
|
-
pycoze/bot/agent/agent.py,sha256=
|
7
|
+
pycoze/bot/agent/agent.py,sha256=vDbTCorUL6Eh2Az4uzwGsLa3Hp4EPcOkq62JpQXt8-s,3435
|
8
8
|
pycoze/bot/agent/assistant.py,sha256=QLeWaPi415P9jruYOm8qcIbC94cXXAhJYmLTkyC9NTQ,1267
|
9
9
|
pycoze/bot/agent/chat.py,sha256=C2X0meUcIPbn5FCxvhkhxozldPG7qdb2jVR-WnPqqnQ,791
|
10
10
|
pycoze/bot/agent/agent_types/__init__.py,sha256=PoYsSeQld0kdROjejN3BNjC9NsgKNekjNy4FqtWRJqM,227
|
@@ -15,11 +15,11 @@ pycoze/ui/__init__.py,sha256=OLPOfXhWGlMVImUhpsOzhs4Jmhrg73lPSUMTTdA7q0I,181
|
|
15
15
|
pycoze/ui/base.py,sha256=nXNXRTZ5Tl1AQp5nfjzLvOVzt_1nLSCn2IOyfxAN_fc,1471
|
16
16
|
pycoze/ui/color.py,sha256=cT9Ib8uNzkOKxyW0IwVj46o4LwdB1xgNCj1_Rou9d_4,854
|
17
17
|
pycoze/ui/typ.py,sha256=NpT0FrbHvByOszBZMFtroRp7I7pN-38tYz_zPOPejF4,1723
|
18
|
-
pycoze/ui/ui_def.py,sha256=
|
18
|
+
pycoze/ui/ui_def.py,sha256=Tsdc4sCxQZRQaN_hLmci8wcBrel999uZBgFaOSRnGn0,3701
|
19
19
|
pycoze/utils/__init__.py,sha256=GMP9EhOsbRM0EfIzS2ll1fXKKSpY3zqpqkm66fPGBaM,39
|
20
20
|
pycoze/utils/arg.py,sha256=VKinJRPiNw0TPvuRFwLg0Vz8u8HXx_ejGfOojfE9b_Y,706
|
21
|
-
pycoze-0.1.
|
22
|
-
pycoze-0.1.
|
23
|
-
pycoze-0.1.
|
24
|
-
pycoze-0.1.
|
25
|
-
pycoze-0.1.
|
21
|
+
pycoze-0.1.16.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
22
|
+
pycoze-0.1.16.dist-info/METADATA,sha256=DmRaOWoSIrHN7Y6_4OCTrMH4OO4mPi-vF46tPPjiIiA,719
|
23
|
+
pycoze-0.1.16.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
|
24
|
+
pycoze-0.1.16.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
25
|
+
pycoze-0.1.16.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|