pycoze 0.1.212__tar.gz → 0.1.214__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {pycoze-0.1.212 → pycoze-0.1.214}/PKG-INFO +1 -1
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/agent_chat.py +39 -6
- pycoze-0.1.214/pycoze/bot/bot.py +24 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/ui/ui_def.py +13 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze.egg-info/PKG-INFO +1 -1
- {pycoze-0.1.212 → pycoze-0.1.214}/setup.py +1 -1
- pycoze-0.1.212/pycoze/bot/bot.py +0 -39
- {pycoze-0.1.212 → pycoze-0.1.214}/LICENSE +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/README.md +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/ai/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/ai/vram_reserve.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/automation/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/automation/browser/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/automation/browser/edge_driver_manager.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/agent/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/agent/agent.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/agent/agent_types/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/agent/agent_types/const.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/agent/agent_types/openai_func_call_agent.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/agent/assistant.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/bot/agent/chat.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/reference/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/reference/bot.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/reference/lib.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/reference/tool.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/reference/workflow.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/ui/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/ui/base.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/ui/color.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/ui/typ.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/utils/__init__.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/utils/arg.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/utils/env.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze/utils/text_or_file.py +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze.egg-info/SOURCES.txt +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze.egg-info/dependency_links.txt +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/pycoze.egg-info/top_level.txt +0 -0
- {pycoze-0.1.212 → pycoze-0.1.214}/setup.cfg +0 -0
@@ -1,12 +1,13 @@
|
|
1
1
|
import json
|
2
2
|
from langchain_openai import ChatOpenAI
|
3
|
-
from .agent import run_agent, Runnable, output
|
3
|
+
from .agent import run_agent, Runnable, output, CHAT_DATA, clear_chat_data
|
4
4
|
import asyncio
|
5
5
|
from pycoze import utils
|
6
6
|
from pycoze.reference.bot import ref_bot
|
7
7
|
from pycoze.reference.tool import ref_tools
|
8
8
|
from pycoze.reference.workflow import ref_workflow
|
9
9
|
from langchain_core.utils.function_calling import convert_to_openai_tool
|
10
|
+
import os
|
10
11
|
|
11
12
|
cfg = utils.read_json_file("llm.json")
|
12
13
|
|
@@ -34,6 +35,36 @@ def load_abilities(bot_setting_file: str):
|
|
34
35
|
return abilities
|
35
36
|
|
36
37
|
|
38
|
+
async def check_interrupt_file(interval, interrupt_file,agent_task):
|
39
|
+
while True:
|
40
|
+
await asyncio.sleep(interval)
|
41
|
+
if os.path.exists(interrupt_file):
|
42
|
+
os.remove(interrupt_file)
|
43
|
+
agent_task.cancel()
|
44
|
+
break
|
45
|
+
|
46
|
+
async def run_with_interrupt_check(agent, history, tool_compatibility_mode, interrupt_file, check_interval=1):
|
47
|
+
clear_chat_data()
|
48
|
+
try:
|
49
|
+
agent_task = asyncio.create_task(run_agent(agent, history, tool_compatibility_mode))
|
50
|
+
check_task = asyncio.create_task(check_interrupt_file(check_interval, interrupt_file, agent_task))
|
51
|
+
result = await agent_task
|
52
|
+
return result
|
53
|
+
except asyncio.CancelledError:
|
54
|
+
return CHAT_DATA['info']
|
55
|
+
except Exception as e:
|
56
|
+
import traceback
|
57
|
+
print(traceback.format_exc())
|
58
|
+
return None # 返回 None 或者处理异常后的结果
|
59
|
+
finally:
|
60
|
+
# 确保即使发生异常也会取消检查任务
|
61
|
+
if not check_task.done():
|
62
|
+
check_task.cancel()
|
63
|
+
try:
|
64
|
+
await check_task
|
65
|
+
except asyncio.CancelledError:
|
66
|
+
pass # 忽略取消错误
|
67
|
+
|
37
68
|
async def agent_chat(bot_setting_file, history):
|
38
69
|
role_setting = load_role_setting(bot_setting_file)
|
39
70
|
abilities = load_abilities(bot_setting_file)
|
@@ -77,9 +108,11 @@ async def agent_chat(bot_setting_file, history):
|
|
77
108
|
assistant_message=prompt,
|
78
109
|
tool_compatibility_mode=cfg["toolCompatibilityMode"],
|
79
110
|
)
|
80
|
-
|
111
|
+
params = utils.read_params_file()
|
112
|
+
if "interruptFile" in params:
|
113
|
+
interrupt_file_path = params["interruptFile"]
|
114
|
+
result = await run_with_interrupt_check(agent, history, cfg["toolCompatibilityMode"], interrupt_file_path)
|
115
|
+
else:
|
81
116
|
result = await run_agent(agent, history, cfg["toolCompatibilityMode"])
|
82
|
-
|
83
|
-
|
84
|
-
return CHAT_DATA["info"]
|
85
|
-
|
117
|
+
return result
|
118
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
from langchain_core.messages import HumanMessage, AIMessage
|
2
|
+
import threading
|
3
|
+
import json
|
4
|
+
from .agent import INPUT_MESSAGE, output, CHAT_DATA, clear_chat_data
|
5
|
+
from .agent_chat import agent_chat
|
6
|
+
import asyncio
|
7
|
+
|
8
|
+
|
9
|
+
def chat(bot_setting_file: str):
|
10
|
+
history = []
|
11
|
+
while True:
|
12
|
+
input_text = input()
|
13
|
+
if not input_text.startswith(INPUT_MESSAGE):
|
14
|
+
raise ValueError("Invalid message")
|
15
|
+
message = json.loads(input_text[len(INPUT_MESSAGE) :])
|
16
|
+
history.append(HumanMessage(message["content"]))
|
17
|
+
result = asyncio.run(agent_chat(bot_setting_file, history))
|
18
|
+
output("assistant", result)
|
19
|
+
history.append(AIMessage(result))
|
20
|
+
|
21
|
+
|
22
|
+
def get_chat_response(bot_setting_file: str, input_text: str):
|
23
|
+
result = asyncio.run(agent_chat(bot_setting_file, [HumanMessage(input_text)]))
|
24
|
+
return result
|
@@ -184,3 +184,16 @@ def multi_video_select(
|
|
184
184
|
|
185
185
|
def seed(name, default=0, tip="", hide_if="", style="", cls="") -> int:
|
186
186
|
return useDefault(name, default)
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
_cache_button_ui = get_ui()
|
191
|
+
def button( name, tip="", hide_if="")->bool:
|
192
|
+
value = useDefault(name, -1)
|
193
|
+
if value is None: #value==None只会发生在在首次打开UI,后续每次运行都不会进入这里
|
194
|
+
value = _cache_button_ui[name]
|
195
|
+
if value != _cache_button_ui[name]:
|
196
|
+
_cache_button_ui[name] = value # 更新last_value的值
|
197
|
+
return True
|
198
|
+
return False
|
199
|
+
|
pycoze-0.1.212/pycoze/bot/bot.py
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
from langchain_core.messages import HumanMessage, AIMessage
|
2
|
-
import threading
|
3
|
-
import queue
|
4
|
-
import json
|
5
|
-
from .agent import INPUT_MESSAGE, output, CHAT_DATA, clear_chat_data
|
6
|
-
from .agent_chat import agent_chat
|
7
|
-
import asyncio
|
8
|
-
|
9
|
-
class PeekableQueue(queue.Queue):
|
10
|
-
def peek(self):
|
11
|
-
try:
|
12
|
-
return self._get()
|
13
|
-
except queue.Empty:
|
14
|
-
return None
|
15
|
-
|
16
|
-
|
17
|
-
def chat(bot_setting_file: str):
|
18
|
-
history = []
|
19
|
-
while True:
|
20
|
-
try:
|
21
|
-
input_text = input()
|
22
|
-
if not input_text.startswith(INPUT_MESSAGE):
|
23
|
-
raise ValueError("Invalid message")
|
24
|
-
message = json.loads(input_text[len(INPUT_MESSAGE) :])
|
25
|
-
history.append(HumanMessage(message["content"]))
|
26
|
-
result = asyncio.run(agent_chat(bot_setting_file, history))
|
27
|
-
history.append(AIMessage(result))
|
28
|
-
except KeyboardInterrupt:
|
29
|
-
pass
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def get_chat_response(bot_setting_file: str, input_text: str):
|
36
|
-
history = [HumanMessage(input_text)]
|
37
|
-
clear_chat_data()
|
38
|
-
asyncio.run(agent_chat(bot_setting_file, history))
|
39
|
-
return CHAT_DATA["output"]
|
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
|
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
|