pycoze 0.1.15__tar.gz → 0.1.16__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 (30) hide show
  1. {pycoze-0.1.15 → pycoze-0.1.16}/PKG-INFO +1 -1
  2. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/__init__.py +4 -3
  3. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/agent/agent.py +72 -67
  4. pycoze-0.1.16/pycoze/ui/ui_def.py +167 -0
  5. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze.egg-info/PKG-INFO +1 -1
  6. {pycoze-0.1.15 → pycoze-0.1.16}/setup.py +1 -1
  7. pycoze-0.1.15/pycoze/ui/ui_def.py +0 -110
  8. {pycoze-0.1.15 → pycoze-0.1.16}/LICENSE +0 -0
  9. {pycoze-0.1.15 → pycoze-0.1.16}/README.md +0 -0
  10. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/__init__.py +0 -0
  11. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/agent/__init__.py +0 -0
  12. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  13. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
  14. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/agent/agent_types/react_agent.py +0 -0
  15. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/agent/agent_types/react_prompt.py +0 -0
  16. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/agent/assistant.py +0 -0
  17. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/agent/chat.py +0 -0
  18. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/base.py +0 -0
  19. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/bot/bot.py +0 -0
  20. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/module.py +0 -0
  21. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/ui/__init__.py +0 -0
  22. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/ui/base.py +0 -0
  23. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/ui/color.py +0 -0
  24. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/ui/typ.py +0 -0
  25. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/utils/__init__.py +0 -0
  26. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze/utils/arg.py +0 -0
  27. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze.egg-info/SOURCES.txt +0 -0
  28. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze.egg-info/dependency_links.txt +0 -0
  29. {pycoze-0.1.15 → pycoze-0.1.16}/pycoze.egg-info/top_level.txt +0 -0
  30. {pycoze-0.1.15 → pycoze-0.1.16}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.15
3
+ Version: 0.1.16
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -1,3 +1,4 @@
1
- from . import bot
2
- from . import utils
3
- from . import ui
1
+ from . import bot
2
+ from . import gpu
3
+ from . import ui
4
+ from . import utils
@@ -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
- content_list = []
14
- async for event in agent.astream_events(inputs, version="v2"):
15
- kind = event["event"]
16
- if kind == "on_chat_model_stream":
17
- content = event["data"]["chunk"].content
18
- if content:
19
- content_list.append(content)
20
- info("assistant", content)
21
- elif kind == "on_chain_start":
22
- data = event["data"]
23
- if "input" in data:
24
- input_list = data["input"] if isinstance(data["input"], list) else [data["input"]]
25
- msg = input_list[-1]
26
- if isinstance(msg, AIMessage) and not isinstance(msg, AIMessageChunk):
27
- if "tool_calls" in msg.additional_kwargs:
28
- tools = [t["function"]["name"] for t in msg.additional_kwargs["tool_calls"]]
29
- tools_str = ",".join(tools)
30
- info("assistant", f"(调用工具:{tools_str})")
31
-
32
- return "".join(content_list)
33
- else:
34
- assert agent.agent_execution_mode == 'ReAct'
35
- inputs_msg = {'input': inputs[-1].content,'chat_history': inputs[:-1]}
36
- use_tools = []
37
- async for event in agent.astream_events(inputs_msg, version="v2"):
38
- kind = event["event"]
39
- result = None
40
- if kind == "on_chain_end":
41
- if 'data' in event:
42
- if 'output' in event['data']:
43
- output = event['data']['output']
44
- if 'agent_outcome' in output and "input" in output:
45
- outcome = output['agent_outcome']
46
- if isinstance(outcome, AgentFinish):
47
- result = outcome.return_values['output']
48
- elif kind == "on_tool_start":
49
- use_tools.append(event['name'])
50
- info("assistant", f"(调用工具:{use_tools})")
51
- return result
52
-
53
-
54
- if __name__ == "__main__":
55
- from langchain_experimental.tools import PythonREPLTool
56
- llm_file = r"C:\Users\aiqqq\AppData\Roaming\pycoze\JsonStorage\llm.json"
57
- with open(llm_file, "r", encoding="utf-8") as f:
58
- cfg = json.load(f)
59
- chat = ChatOpenAI(api_key=cfg["apiKey"], base_url=cfg['baseURL'], model=cfg["model"], temperature=0)
60
- python_tool = PythonREPLTool()
61
- agent = Runnable(agent_execution_mode='FuncCall', # 'FuncCall' or 'ReAct',大模型支持FuncCall的话就用FuncCall
62
- tools=[python_tool],
63
- llm=chat,
64
- assistant_message="请以女友的口吻回答,输出不小于100字,可以随便说点其他的",)
65
-
66
- inputs = [HumanMessage(content="计算根号7+根号88")]
67
- print(asyncio.run(run_agent(agent, inputs)))
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)))
@@ -0,0 +1,167 @@
1
+ from .base import get_ui
2
+ from .typ import useDefaultType
3
+ from typing import Union, List
4
+ from .color import hex_to_rgb, rgb_to_hsl, ColorFormat
5
+ import sys
6
+
7
+
8
+ def useDefault(name, default):
9
+ ui_data = get_ui()
10
+ if name not in ui_data:
11
+ return default
12
+ return useDefaultType(ui_data[name], default)
13
+
14
+
15
+ def get_ui_text():
16
+ ui = get_ui()
17
+ output = ""
18
+ for key, value in ui.items():
19
+ output += f"{key}: {value}\n"
20
+ return output
21
+
22
+
23
+ def label(name, tip="", hide_if="", style="", cls=""):
24
+ pass
25
+
26
+
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
38
+ return useDefault(name, default)
39
+
40
+
41
+ def text(name, default, tip="", hide_if="", style="", cls="") -> str:
42
+ return useDefault(name, default)
43
+
44
+
45
+ def textarea(name, default, tip="", hide_if="", style="", cls="") -> str:
46
+ return useDefault(name, default)
47
+
48
+
49
+ def password(name, default, tip="", hide_if="", style="", cls="") -> str:
50
+ return useDefault(name, default)
51
+
52
+
53
+ def color(
54
+ name,
55
+ default,
56
+ color_format: ColorFormat = "hex",
57
+ tip="",
58
+ hide_if="",
59
+ style="",
60
+ cls="",
61
+ ) -> str:
62
+ rgbhex = useDefault(name, default)
63
+ if color_format == "hex":
64
+ return rgbhex
65
+ elif color_format == "rgb":
66
+ return hex_to_rgb(rgbhex)
67
+ elif color_format == "hsl":
68
+ return rgb_to_hsl(hex_to_rgb(rgbhex))
69
+ return rgbhex
70
+
71
+
72
+ def checkbox(name, default, tip="", hide_if="", style="", cls="") -> bool:
73
+ return useDefault(name, default)
74
+
75
+
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
+ ):
97
+ return useDefault(name, default)
98
+
99
+
100
+ def single_file_select(name, default: str, tip="", hide_if="", style="", cls="") -> str:
101
+ return useDefault(name, default)
102
+
103
+
104
+ def multi_file_select(
105
+ name, default: List[str], tip="", hide_if="", style="", cls=""
106
+ ) -> List[str]:
107
+ return useDefault(name, default)
108
+
109
+
110
+ def single_folder_select(
111
+ name, default: str, tip="", hide_if="", style="", cls=""
112
+ ) -> str:
113
+ return useDefault(name, default)
114
+
115
+
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:
125
+ if default is None:
126
+ default = []
127
+ return useDefault(name, default)
128
+
129
+
130
+ def single_image_select(
131
+ name, default: str, tip="", hide_if="", style="", cls=""
132
+ ) -> str:
133
+ return useDefault(name, default)
134
+
135
+
136
+ def multi_image_select(
137
+ name, default: List[str], tip="", hide_if="", style="", cls=""
138
+ ) -> List[str]:
139
+ return useDefault(name, default)
140
+
141
+
142
+ def single_audio_select(
143
+ name, default: str, tip="", hide_if="", style="", cls=""
144
+ ) -> str:
145
+ return useDefault(name, default)
146
+
147
+
148
+ def multi_audio_select(
149
+ name, default: List[str], tip="", hide_if="", style="", cls=""
150
+ ) -> List[str]:
151
+ return useDefault(name, default)
152
+
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.15
3
+ Version: 0.1.16
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.15",
5
+ version="0.1.16",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -1,110 +0,0 @@
1
- from .base import get_ui
2
- from .typ import useDefaultType
3
- from typing import Union, List
4
- from .color import hex_to_rgb, rgb_to_hsl, ColorFormat
5
- import sys
6
-
7
-
8
-
9
- def useDefault(name, default):
10
- ui_data = get_ui()
11
- if name not in ui_data:
12
- return default
13
- return useDefaultType(ui_data[name], default)
14
-
15
-
16
- def get_ui_text():
17
- ui = get_ui()
18
- output = ''
19
- for key, value in ui.items():
20
- output += f'{key}: {value}\n'
21
- return output
22
-
23
-
24
- def label(name, tip="", hide_if="", style="", cls=""):
25
- pass
26
-
27
-
28
- def number(name,
29
- default,
30
- min=-sys.maxsize - 1,
31
- max=sys.maxsize,
32
- step=1,
33
- tip="",
34
- hide_if="",
35
- style="",
36
- cls="") -> Union[int, float]: # 注意Python3.9不兼容int|float
37
- return useDefault(name, default)
38
-
39
-
40
- def text(name, default, tip="", hide_if="", style="", cls="") -> str:
41
- return useDefault(name, default)
42
-
43
-
44
- def textarea(name, default, tip="", hide_if="", style="", cls="") -> str:
45
- return useDefault(name, default)
46
-
47
-
48
- def password(name, default, tip="", hide_if="", style="", cls="") -> str:
49
- return useDefault(name, default)
50
-
51
-
52
- def color(name, default, color_format: ColorFormat = "hex", tip="", hide_if="", style="", cls="") -> str:
53
- rgbhex = useDefault(name, default)
54
- if color_format == "hex":
55
- return rgbhex
56
- elif color_format == "rgb":
57
- return hex_to_rgb(rgbhex)
58
- elif color_format == "hsl":
59
- return rgb_to_hsl(hex_to_rgb(rgbhex))
60
- return rgbhex
61
-
62
-
63
- def checkbox(name, default, tip="", hide_if="", style="", cls="") -> bool:
64
- return useDefault(name, default)
65
-
66
-
67
- def single_select(name, default: Union[str, int, float, bool], options, tip="", hide_if="", style="", cls=""):
68
- return useDefault(name, default)
69
-
70
-
71
- def multi_select(name,
72
- default: Union[List[str], List[int], List[float], List[bool]],
73
- options,
74
- tip="",
75
- hide_if="",
76
- style="",
77
- cls=""):
78
- return useDefault(name, default)
79
-
80
-
81
- def file(name, default: Union[str, List[str]], is_multiple: bool, tip="", hide_if="", style="", cls="") -> str:
82
- return useDefault(name, default)
83
-
84
-
85
- def folder(name, default: Union[str, List[str]], is_multiple: bool, tip="", hide_if="", style="", cls="") -> str:
86
- return useDefault(name, default)
87
-
88
-
89
- def folder_tree(name, root="", default: List[str] = None, tip="", hide_if="", style="", cls="") -> dict:
90
- if default is None:
91
- default = []
92
- return useDefault(name, default)
93
-
94
-
95
- def image(name, default: Union[str, List[str]], is_multiple: bool=False, tip="", hide_if="", style="", cls="") -> str:
96
- return useDefault(name, default)
97
-
98
-
99
- def audio(name, default: Union[str, List[str]], is_multiple: bool=False, tip="", hide_if="", style="", cls="") -> str:
100
- return useDefault(name, default)
101
-
102
-
103
- def video(name, default: Union[str, List[str]], is_multiple: bool=False, tip="", hide_if="", style="", cls="") -> str:
104
- return useDefault(name, default)
105
-
106
-
107
- def seed(name, default=0, tip="", hide_if="", style="", cls="") -> int:
108
- return useDefault(name, default)
109
-
110
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes