pycoze 0.1.252__tar.gz → 0.1.254__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. {pycoze-0.1.252 → pycoze-0.1.254}/PKG-INFO +1 -1
  2. pycoze-0.1.254/pycoze/ai/__init__.py +14 -0
  3. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ai/llm/__init__.py +9 -0
  4. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ai/vram_reserve.py +1 -1
  5. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/__init__.py +2 -0
  6. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +1 -2
  7. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/agent/assistant.py +1 -1
  8. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/agent_chat.py +2 -2
  9. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/bot.py +0 -1
  10. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ui/__init__.py +28 -0
  11. pycoze-0.1.254/pycoze/utils/__init__.py +5 -0
  12. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/utils/arg.py +0 -2
  13. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/utils/env.py +6 -2
  14. pycoze-0.1.254/pycoze/utils/socket.py +72 -0
  15. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze.egg-info/PKG-INFO +1 -1
  16. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze.egg-info/SOURCES.txt +1 -0
  17. {pycoze-0.1.252 → pycoze-0.1.254}/setup.py +1 -1
  18. pycoze-0.1.252/pycoze/ai/__init__.py +0 -2
  19. pycoze-0.1.252/pycoze/utils/__init__.py +0 -3
  20. {pycoze-0.1.252 → pycoze-0.1.254}/LICENSE +0 -0
  21. {pycoze-0.1.252 → pycoze-0.1.254}/README.md +0 -0
  22. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/__init__.py +0 -0
  23. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ai/llm/chat.py +0 -0
  24. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ai/llm/text_to_image_prompt.py +0 -0
  25. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ai/llm/think.py +0 -0
  26. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/agent/__init__.py +0 -0
  27. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/agent/agent.py +0 -0
  28. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/agent/agent_types/__init__.py +0 -0
  29. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/agent/agent_types/const.py +0 -0
  30. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/bot/agent/chat.py +0 -0
  31. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/reference/__init__.py +0 -0
  32. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/reference/bot.py +0 -0
  33. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/reference/lib.py +0 -0
  34. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/reference/tool.py +0 -0
  35. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/reference/workflow.py +0 -0
  36. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ui/base.py +0 -0
  37. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ui/color.py +0 -0
  38. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ui/typ.py +0 -0
  39. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/ui/ui_def.py +0 -0
  40. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze/utils/text_or_file.py +0 -0
  41. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze.egg-info/dependency_links.txt +0 -0
  42. {pycoze-0.1.252 → pycoze-0.1.254}/pycoze.egg-info/top_level.txt +0 -0
  43. {pycoze-0.1.252 → pycoze-0.1.254}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.252
3
+ Version: 0.1.254
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -0,0 +1,14 @@
1
+ from .vram_reserve import reserve_vram, reserve_vram_retry, unreserve_vram
2
+ from .llm import chat, chat_stream, extract, yes_or_no, extract_code, text_to_image_prompt
3
+
4
+ __all__ = [
5
+ reserve_vram,
6
+ reserve_vram_retry,
7
+ unreserve_vram,
8
+ chat,
9
+ chat_stream,
10
+ extract,
11
+ yes_or_no,
12
+ extract_code,
13
+ text_to_image_prompt
14
+ ]
@@ -1,2 +1,11 @@
1
1
  from .text_to_image_prompt import text_to_image_prompt
2
2
  from .chat import chat, chat_stream, extract, yes_or_no, extract_code
3
+
4
+ __all__ = [
5
+ text_to_image_prompt,
6
+ chat,
7
+ chat_stream,
8
+ extract,
9
+ yes_or_no,
10
+ extract_code
11
+ ]
@@ -8,7 +8,7 @@ import sys
8
8
  from pycoze import utils
9
9
 
10
10
  # 定义数据库连接和初始化
11
- params = utils.read_params_file()
11
+ params = utils.params
12
12
  if params:
13
13
  DATABASE_PATH = params["appPath"] + "/vram_usage.db"
14
14
  else:
@@ -1 +1,3 @@
1
1
  from .bot import chat, get_chat_response
2
+
3
+ __all__ = [chat, get_chat_response]
@@ -92,7 +92,7 @@ def create_openai_func_call_agent_executor(
92
92
 
93
93
  return [SystemMessage(content=system_message)] + msgs
94
94
 
95
- if tools and tool_compatibility_mode:
95
+ if tools and not tool_compatibility_mode:
96
96
  llm_with_tools = llm.bind(tools=[convert_to_openai_tool(t) for t in tools])
97
97
  else:
98
98
  llm_with_tools = llm
@@ -106,7 +106,6 @@ def create_openai_func_call_agent_executor(
106
106
  if last_message.content.strip().endswith("```"):
107
107
  last_message.content = last_message.content + "\n\n" # 避免影响阅读
108
108
  tools = get_tools(last_message)
109
- print("tools", tools)
110
109
  if last_message.tool_calls or tools:
111
110
  return 'continue'
112
111
  return 'end'
@@ -26,7 +26,7 @@ class Runnable(RunnableBinding):
26
26
  )
27
27
  agent_executor = agent_executor.with_config({"recursion_limit": 50})
28
28
  super().__init__(
29
- tools=tools,
29
+ tools=tools if not tool_compatibility_mode else [],
30
30
  llm=llm,
31
31
  agent_execution_mode=agent_execution_mode,
32
32
  assistant_message=assistant_message,
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  from langchain_openai import ChatOpenAI
3
- from .agent import run_agent, Runnable, output, CHAT_DATA, clear_chat_data
3
+ from .agent import run_agent, Runnable,CHAT_DATA, clear_chat_data
4
4
  import asyncio
5
5
  from pycoze import utils
6
6
  from pycoze.reference.bot import ref_bot
@@ -100,7 +100,7 @@ async def agent_chat(bot_setting_file, history):
100
100
  assistant_message=prompt,
101
101
  tool_compatibility_mode=cfg["toolCompatibilityMode"],
102
102
  )
103
- params = utils.read_params_file()
103
+ params = utils.params
104
104
  if "interruptFile" in params:
105
105
  interrupt_file_path = params["interruptFile"]
106
106
  result = await run_with_interrupt_check(agent, history, cfg["toolCompatibilityMode"], interrupt_file_path)
@@ -1,5 +1,4 @@
1
1
  from langchain_core.messages import HumanMessage, AIMessage
2
- import threading
3
2
  import json
4
3
  from .agent import INPUT_MESSAGE, output, CHAT_DATA, clear_chat_data
5
4
  from .agent_chat import agent_chat
@@ -25,3 +25,31 @@ from .ui_def import (
25
25
  seed,
26
26
  button
27
27
  )
28
+
29
+ __all__ = [
30
+ get_ui,
31
+ get_ui_text,
32
+ label,
33
+ number,
34
+ text,
35
+ textarea,
36
+ password,
37
+ tool,
38
+ color,
39
+ checkbox,
40
+ single_select,
41
+ multi_select,
42
+ single_file_select,
43
+ multi_file_select,
44
+ single_folder_select,
45
+ multi_folder_select,
46
+ folder_tree,
47
+ single_image_select,
48
+ multi_image_select,
49
+ single_audio_select,
50
+ multi_audio_select,
51
+ single_video_select,
52
+ multi_video_select,
53
+ seed,
54
+ button
55
+ ]
@@ -0,0 +1,5 @@
1
+ from .arg import read_arg
2
+ from .env import read_params_file, params, read_json_file
3
+ from .text_or_file import to_text
4
+
5
+ __all__ = [read_arg, read_params_file, params, read_json_file, to_text]
@@ -1,6 +1,4 @@
1
1
  import sys
2
- import json
3
- import os
4
2
 
5
3
 
6
4
  def read_arg(param, is_path=False, posix=True):
@@ -13,9 +13,13 @@ def read_params_file():
13
13
  print(e)
14
14
  return params
15
15
 
16
+
17
+ params = read_params_file()
18
+
19
+
16
20
  def read_json_file(filename):
17
- params = read_params_file()
18
21
  json_file = os.path.join(params['appPath'], 'JsonStorage', filename)
19
22
  with open(json_file, encoding='utf-8') as f:
20
23
  return json.load(f)
21
-
24
+
25
+
@@ -0,0 +1,72 @@
1
+ import socket
2
+ import json
3
+ import uuid
4
+
5
+
6
+ tcp_port = read_arg("tcp_port")
7
+
8
+
9
+
10
+ class TcpSocket:
11
+ def __init__(self):
12
+ self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
13
+ self.socket.connect(("localhost", int(tcp_port)))
14
+ self.is_connected = True
15
+
16
+ def post(self, subject, message):
17
+ subject = "python-event:" + subject
18
+ message = message.copy()
19
+ message["subject"] = subject
20
+ message = json.dumps(message)
21
+ message_bytes = message.encode()
22
+ message_length = len(message_bytes)
23
+ message_length_bytes = message_length.to_bytes(4, byteorder='big')
24
+
25
+ self.socket.sendall(message_length_bytes + message_bytes)
26
+
27
+ def recv(self):
28
+ # 接收消息长度
29
+ message_length_bytes = self.socket.recv(4)
30
+ message_length = int.from_bytes(message_length_bytes, byteorder='big')
31
+ # 初始化接收到的消息
32
+ message = b''
33
+ # 循环接收直到收到完整的消息
34
+ while len(message) < message_length:
35
+ # 接收剩余的消息
36
+ chunk = self.socket.recv(message_length - len(message))
37
+ if not chunk: # 如果没有接收到数据,则断开连接
38
+ raise RuntimeError("Socket connection broken")
39
+ message += chunk
40
+ message = json.loads(message.decode())
41
+ return message
42
+
43
+ def post_and_recv_result(self, subject, message):
44
+ message = message.copy()
45
+ message["uid"] = str(uuid.uuid4())
46
+ socket_subscribe(subject + ":" + message["uid"]) # 先订阅,再发送,防止消息丢失
47
+ self.post(subject, message)
48
+ ret_val = self.recv()
49
+ result = ret_val["result"] if "result" in ret_val else None # 传输时,可能会丢失result字段,因此需要判断
50
+ return result
51
+
52
+ def close(self):
53
+ if self.is_connected:
54
+ self.is_connected = False
55
+
56
+ def __del__(self):
57
+ # 垃圾回收时自动关闭socket
58
+ if self.is_connected:
59
+ self.close()
60
+
61
+ def __exit__(self, exc_type, exc_value, traceback):
62
+ # with 语句块结束时自动触发的
63
+ if self.is_connected:
64
+ self.close()
65
+
66
+
67
+ socket = TcpSocket()
68
+
69
+ def socket_subscribe(subject: str):
70
+ subject = "python-event:" + subject
71
+ socket.post(subject, {"subscribe": subject})
72
+ return socket
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.252
3
+ Version: 0.1.254
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -35,4 +35,5 @@ pycoze/ui/ui_def.py
35
35
  pycoze/utils/__init__.py
36
36
  pycoze/utils/arg.py
37
37
  pycoze/utils/env.py
38
+ pycoze/utils/socket.py
38
39
  pycoze/utils/text_or_file.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.252",
5
+ version="0.1.254",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
@@ -1,2 +0,0 @@
1
- from .vram_reserve import reserve_vram, reserve_vram_retry, unreserve_vram
2
- from .llm import chat, chat_stream, extract, yes_or_no, extract_code, text_to_image_prompt
@@ -1,3 +0,0 @@
1
- from .arg import read_arg
2
- from .env import read_params_file, read_json_file
3
- from .text_or_file import to_text
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