pycoze 0.1.341__tar.gz → 0.1.342__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 (44) hide show
  1. {pycoze-0.1.341 → pycoze-0.1.342}/PKG-INFO +1 -1
  2. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/bot/chat.py +130 -100
  3. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze.egg-info/PKG-INFO +1 -1
  4. {pycoze-0.1.341 → pycoze-0.1.342}/setup.py +1 -1
  5. {pycoze-0.1.341 → pycoze-0.1.342}/LICENSE +0 -0
  6. {pycoze-0.1.341 → pycoze-0.1.342}/README.md +0 -0
  7. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/__init__.py +0 -0
  8. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ai/__init__.py +0 -0
  9. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ai/llm/__init__.py +0 -0
  10. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ai/llm/chat.py +0 -0
  11. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ai/llm/text_to_image_prompt.py +0 -0
  12. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ai/llm/think.py +0 -0
  13. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ai/vram_reserve.py +0 -0
  14. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/api/__init__.py +0 -0
  15. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/api/lib/__init__.py +0 -0
  16. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/api/lib/tab.py +0 -0
  17. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/api/lib/view.py +0 -0
  18. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/api/lib/web.py +0 -0
  19. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/api/lib/window.py +0 -0
  20. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/bot/__init__.py +0 -0
  21. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/bot/chat_base.py +0 -0
  22. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/bot/lib.py +0 -0
  23. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/bot/message.py +0 -0
  24. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/bot/prompt.md +0 -0
  25. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/bot/tools.py +0 -0
  26. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/reference/__init__.py +0 -0
  27. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/reference/bot.py +0 -0
  28. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/reference/lib.py +0 -0
  29. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/reference/tool.py +0 -0
  30. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/reference/workflow.py +0 -0
  31. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ui/__init__.py +0 -0
  32. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ui/base.py +0 -0
  33. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ui/color.py +0 -0
  34. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ui/typ.py +0 -0
  35. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/ui/ui_def.py +0 -0
  36. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/utils/__init__.py +0 -0
  37. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/utils/arg.py +0 -0
  38. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/utils/env.py +0 -0
  39. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/utils/socket.py +0 -0
  40. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze/utils/text_or_file.py +0 -0
  41. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze.egg-info/SOURCES.txt +0 -0
  42. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze.egg-info/dependency_links.txt +0 -0
  43. {pycoze-0.1.341 → pycoze-0.1.342}/pycoze.egg-info/top_level.txt +0 -0
  44. {pycoze-0.1.341 → pycoze-0.1.342}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.341
3
+ Version: 0.1.342
4
4
  Summary: Package for pycoze only!
5
5
  Home-page: UNKNOWN
6
6
  Author: Yuan Jie Xiong
@@ -1,100 +1,130 @@
1
- import json
2
- from .chat_base import handle_user_inputs
3
- from .lib import get_abilities, get_system_prompt
4
- from .message import INPUT_MESSAGE, output, CHAT_DATA, clear_chat_data
5
- import os
6
- import asyncio
7
- from pycoze import utils
8
- import tempfile
9
-
10
-
11
- async def check_interrupt_file(interval, interrupt_file, chat_task):
12
- while True:
13
- await asyncio.sleep(interval)
14
- if os.path.exists(interrupt_file):
15
- os.remove(interrupt_file)
16
- chat_task.cancel()
17
- break
18
-
19
-
20
- async def run_with_interrupt_check(conversation_history, user_input, cwd: str, abilities, has_any_tool, bot_setting, interrupt_file):
21
- clear_chat_data()
22
- try:
23
- chat_task = asyncio.create_task(
24
- handle_user_inputs(conversation_history, user_input, cwd, abilities, has_any_tool, bot_setting)
25
- )
26
- check_task = asyncio.create_task(
27
- check_interrupt_file(0.5, interrupt_file, chat_task)
28
- )
29
- result = await chat_task
30
- return result
31
- except asyncio.CancelledError:
32
- return CHAT_DATA["info"]
33
- except Exception as e:
34
- import traceback
35
-
36
- print(traceback.format_exc())
37
- return None # 返回 None 或者处理异常后的结果
38
- finally:
39
- if not chat_task.done():
40
- chat_task.cancel()
41
- # 确保即使发生异常也会取消检查任务
42
- if not check_task.done():
43
- check_task.cancel()
44
- try:
45
- await check_task
46
- except asyncio.CancelledError:
47
- pass # 忽略取消错误
48
-
49
-
50
- def chat(bot_setting_file: str):
51
- with open(bot_setting_file, encoding="utf-8") as f:
52
- bot_setting = json.load(f)
53
- abilities = get_abilities(bot_setting)
54
- cwd = tempfile.mkdtemp()
55
- system_prompt, has_any_tool = get_system_prompt(abilities, bot_setting)
56
- conversation_history = [
57
- {
58
- "role": "system",
59
- "content": system_prompt,
60
- }
61
- ]
62
- while True:
63
- clear_chat_data()
64
- input_text = input()
65
- if not input_text.startswith(INPUT_MESSAGE):
66
- raise ValueError("Invalid message")
67
- message = json.loads(input_text[len(INPUT_MESSAGE) :])
68
- user_input = message["content"]
69
- params = utils.params
70
- if "interruptFile" in params:
71
- asyncio.run(
72
- run_with_interrupt_check(
73
- conversation_history, user_input, cwd, abilities, has_any_tool, bot_setting, params["interruptFile"]
74
- )
75
- )
76
- else:
77
- asyncio.run(
78
- handle_user_inputs(conversation_history, user_input, cwd, abilities, has_any_tool, bot_setting)
79
- )
80
-
81
- output("assistant", CHAT_DATA["info"])
82
-
83
-
84
- def get_chat_response(bot_setting_file: str, user_input: str):
85
- with open(bot_setting_file, encoding="utf-8") as f:
86
- bot_setting = json.load(f)
87
- abilities = get_abilities(bot_setting)
88
- cwd = tempfile.mkdtemp()
89
- system_prompt, has_any_tool = get_system_prompt(abilities, bot_setting)
90
- conversation_history = [
91
- {
92
- "role": "system",
93
- "content": system_prompt,
94
- }
95
- ]
96
- asyncio.run(
97
- handle_user_inputs(conversation_history, user_input, cwd, abilities, has_any_tool, bot_setting)
98
- )
99
-
100
- return CHAT_DATA["info"]
1
+ import json
2
+ from .chat_base import handle_user_inputs
3
+ from .lib import get_abilities, get_system_prompt
4
+ from .message import INPUT_MESSAGE, output, CHAT_DATA, clear_chat_data
5
+ import os
6
+ import asyncio
7
+ from pycoze import utils
8
+ import tempfile
9
+
10
+
11
+ async def check_interrupt_file(interval, interrupt_file, chat_task):
12
+ while True:
13
+ await asyncio.sleep(interval)
14
+ if os.path.exists(interrupt_file):
15
+ os.remove(interrupt_file)
16
+ chat_task.cancel()
17
+ break
18
+
19
+
20
+ async def run_with_interrupt_check(
21
+ conversation_history,
22
+ user_input,
23
+ cwd: str,
24
+ abilities,
25
+ has_any_tool,
26
+ bot_setting,
27
+ interrupt_file,
28
+ ):
29
+ clear_chat_data()
30
+ try:
31
+ chat_task = asyncio.create_task(
32
+ handle_user_inputs(
33
+ conversation_history,
34
+ user_input,
35
+ cwd,
36
+ abilities,
37
+ has_any_tool,
38
+ bot_setting,
39
+ )
40
+ )
41
+ check_task = asyncio.create_task(
42
+ check_interrupt_file(0.5, interrupt_file, chat_task)
43
+ )
44
+ result = await chat_task
45
+ return result
46
+ except asyncio.CancelledError:
47
+ return CHAT_DATA["info"]
48
+ except Exception as e:
49
+ import traceback
50
+
51
+ print(traceback.format_exc())
52
+ return None # 返回 None 或者处理异常后的结果
53
+ finally:
54
+ if not chat_task.done():
55
+ chat_task.cancel()
56
+ # 确保即使发生异常也会取消检查任务
57
+ if not check_task.done():
58
+ check_task.cancel()
59
+ try:
60
+ await check_task
61
+ except asyncio.CancelledError:
62
+ pass # 忽略取消错误
63
+
64
+
65
+ def chat(bot_setting_file: str):
66
+ with open(bot_setting_file, encoding="utf-8") as f:
67
+ bot_setting = json.load(f)
68
+ abilities = get_abilities(bot_setting)
69
+ cwd = tempfile.mkdtemp()
70
+ system_prompt, has_any_tool = get_system_prompt(abilities, bot_setting)
71
+ conversation_history = [
72
+ {
73
+ "role": "system",
74
+ "content": system_prompt,
75
+ }
76
+ ]
77
+ while True:
78
+ clear_chat_data()
79
+ input_text = input()
80
+ if not input_text.startswith(INPUT_MESSAGE):
81
+ raise ValueError("Invalid message")
82
+ message = json.loads(input_text[len(INPUT_MESSAGE) :])
83
+ user_input = message["content"]
84
+ params = utils.params
85
+ if "interruptFile" in params:
86
+ asyncio.run(
87
+ run_with_interrupt_check(
88
+ conversation_history,
89
+ user_input,
90
+ cwd,
91
+ abilities,
92
+ has_any_tool,
93
+ bot_setting,
94
+ params["interruptFile"],
95
+ )
96
+ )
97
+ else:
98
+ asyncio.run(
99
+ handle_user_inputs(
100
+ conversation_history,
101
+ user_input,
102
+ cwd,
103
+ abilities,
104
+ has_any_tool,
105
+ bot_setting,
106
+ )
107
+ )
108
+ print("has_output")
109
+ output("assistant", CHAT_DATA["info"])
110
+
111
+
112
+ def get_chat_response(bot_setting_file: str, user_input: str):
113
+ with open(bot_setting_file, encoding="utf-8") as f:
114
+ bot_setting = json.load(f)
115
+ abilities = get_abilities(bot_setting)
116
+ cwd = tempfile.mkdtemp()
117
+ system_prompt, has_any_tool = get_system_prompt(abilities, bot_setting)
118
+ conversation_history = [
119
+ {
120
+ "role": "system",
121
+ "content": system_prompt,
122
+ }
123
+ ]
124
+ asyncio.run(
125
+ handle_user_inputs(
126
+ conversation_history, user_input, cwd, abilities, has_any_tool, bot_setting
127
+ )
128
+ )
129
+
130
+ return CHAT_DATA["info"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.341
3
+ Version: 0.1.342
4
4
  Summary: Package for pycoze only!
5
5
  Home-page: UNKNOWN
6
6
  Author: Yuan Jie Xiong
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="pycoze",
5
- version="0.1.341",
5
+ version="0.1.342",
6
6
  packages=find_packages(),
7
7
  install_requires=[],
8
8
  author="Yuan Jie Xiong",
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes