pycoze 0.1.205__py3-none-any.whl → 0.1.207__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/bot/bot.py +18 -59
- {pycoze-0.1.205.dist-info → pycoze-0.1.207.dist-info}/METADATA +1 -1
- {pycoze-0.1.205.dist-info → pycoze-0.1.207.dist-info}/RECORD +6 -6
- {pycoze-0.1.205.dist-info → pycoze-0.1.207.dist-info}/LICENSE +0 -0
- {pycoze-0.1.205.dist-info → pycoze-0.1.207.dist-info}/WHEEL +0 -0
- {pycoze-0.1.205.dist-info → pycoze-0.1.207.dist-info}/top_level.txt +0 -0
pycoze/bot/bot.py
CHANGED
@@ -1,72 +1,31 @@
|
|
1
|
-
import
|
2
|
-
import
|
1
|
+
from langchain_core.messages import HumanMessage, AIMessage
|
2
|
+
import threading
|
3
|
+
import queue
|
3
4
|
import json
|
4
5
|
from .agent import INPUT_MESSAGE, output, CHAT_DATA, clear_chat_data
|
5
6
|
from .agent_chat import agent_chat
|
6
|
-
from multiprocessing import Process, Event
|
7
7
|
import asyncio
|
8
|
-
from langchain_core.messages import HumanMessage, AIMessage
|
9
|
-
|
10
|
-
# 用于标记中断请求
|
11
|
-
interrupt_flag = False
|
12
8
|
|
13
|
-
|
14
|
-
def
|
15
|
-
global interrupt_flag
|
16
|
-
interrupt_flag = True
|
17
|
-
print("Interrupt signal received. Waiting for the current operation to complete...")
|
18
|
-
|
19
|
-
# 设置信号处理器
|
20
|
-
signal.signal(signal.SIGINT, handle_interrupt)
|
21
|
-
|
22
|
-
def read_input():
|
23
|
-
while True:
|
9
|
+
class PeekableQueue(queue.Queue):
|
10
|
+
def peek(self):
|
24
11
|
try:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
raise ValueError("Invalid message")
|
30
|
-
except EOFError: # 如果输入流结束,则退出循环
|
31
|
-
break
|
12
|
+
return self._get()
|
13
|
+
except queue.Empty:
|
14
|
+
return None
|
15
|
+
|
32
16
|
|
33
17
|
def chat(bot_setting_file: str):
|
34
18
|
history = []
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# 使用进程来运行 agent_chat
|
45
|
-
agent_chat_process = Process(target=asyncio.run, args=(agent_chat(bot_setting_file, history, should_exit),))
|
46
|
-
agent_chat_process.start()
|
47
|
-
|
48
|
-
# 检查是否收到了中断信号
|
49
|
-
while agent_chat_process.is_alive():
|
50
|
-
if interrupt_flag:
|
51
|
-
should_exit.set() # 设置退出标志
|
52
|
-
break
|
53
|
-
time.sleep(0.1) # 每隔 0.1 秒检查一次
|
19
|
+
while True:
|
20
|
+
input_text = input()
|
21
|
+
if not input_text.startswith(INPUT_MESSAGE):
|
22
|
+
raise ValueError("Invalid message")
|
23
|
+
message = json.loads(input_text[len(INPUT_MESSAGE) :])
|
24
|
+
history.append(HumanMessage(message["content"]))
|
25
|
+
result = agent_chat(bot_setting_file, history)
|
26
|
+
history.append(AIMessage(result["output"]))
|
54
27
|
|
55
|
-
# 确保子进程已经退出
|
56
|
-
agent_chat_process.join()
|
57
28
|
|
58
|
-
# 如果没有收到中断信号,记录输出
|
59
|
-
if not interrupt_flag:
|
60
|
-
history.append(AIMessage(content=CHAT_DATA["output"]))
|
61
|
-
|
62
|
-
# 重置中断标志
|
63
|
-
interrupt_flag = False
|
64
|
-
except json.JSONDecodeError:
|
65
|
-
print("Invalid JSON format in input message.")
|
66
|
-
except KeyError:
|
67
|
-
print("Missing 'content' key in input message.")
|
68
|
-
except Exception as e:
|
69
|
-
print(f"An error occurred: {e}")
|
70
29
|
|
71
30
|
|
72
31
|
def get_chat_response(bot_setting_file: str, input_text: str):
|
@@ -74,4 +33,4 @@ def get_chat_response(bot_setting_file: str, input_text: str):
|
|
74
33
|
clear_chat_data()
|
75
34
|
should_exit = threading.Event()
|
76
35
|
asyncio.run(agent_chat(bot_setting_file, history, should_exit))
|
77
|
-
return CHAT_DATA["output"]
|
36
|
+
return CHAT_DATA["output"]
|
@@ -6,7 +6,7 @@ pycoze/automation/browser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
6
6
|
pycoze/automation/browser/edge_driver_manager.py,sha256=gpgseunph5owZH6EskSYthuhey2SU3UP204gY0yIcuI,3022
|
7
7
|
pycoze/bot/__init__.py,sha256=6HHMxDQVOyZM9dtSjQm9tjGnhj4h7CixD0JOvEwTi48,41
|
8
8
|
pycoze/bot/agent_chat.py,sha256=hr0jGTd-lvLSe4vCcvaN2rKhB7BMBcVBtI1FpVa6ngs,3016
|
9
|
-
pycoze/bot/bot.py,sha256=
|
9
|
+
pycoze/bot/bot.py,sha256=rxPX8J544cUyondpECP5R2PSobRpHsviIGF74CWl0ko,1098
|
10
10
|
pycoze/bot/agent/__init__.py,sha256=3wE8_FFQS8j2BY-g9Cr-onV0POEvDRZaw_NCzpqrNus,265
|
11
11
|
pycoze/bot/agent/agent.py,sha256=Ueste4xWvkQFk5Giklv4c-kcxiPL-D-KafzZ4DONosY,3613
|
12
12
|
pycoze/bot/agent/assistant.py,sha256=3iLxnRvf_ia0cP-FHK5Fv4ylltlnzPq1KscRCFYqjkc,1147
|
@@ -28,8 +28,8 @@ pycoze/utils/__init__.py,sha256=Gi5EnrWZGMD2JRejgV4c_VLCXyvA2wwBFI_niDF5MUE,110
|
|
28
28
|
pycoze/utils/arg.py,sha256=GtfGbMTMdaK75Fwh6MpUe1pCA5X6Ep4LFG7a72YrzjI,525
|
29
29
|
pycoze/utils/env.py,sha256=W04lhvTHhAAC6EldP6kk2xrctqtu8K6kl1vDLZDNeh8,561
|
30
30
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
31
|
-
pycoze-0.1.
|
32
|
-
pycoze-0.1.
|
33
|
-
pycoze-0.1.
|
34
|
-
pycoze-0.1.
|
35
|
-
pycoze-0.1.
|
31
|
+
pycoze-0.1.207.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
32
|
+
pycoze-0.1.207.dist-info/METADATA,sha256=_LAs5qiAkjI_0gSXm9aHkdo1omUZZjVD6Rm_GlDdQK8,726
|
33
|
+
pycoze-0.1.207.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
|
34
|
+
pycoze-0.1.207.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
35
|
+
pycoze-0.1.207.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|