pycoze 0.1.206__py3-none-any.whl → 0.1.207__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
pycoze/bot/bot.py CHANGED
@@ -1,77 +1,31 @@
1
- import signal
2
- import sys
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
-
13
- # 信号处理函数
14
- def handle_interrupt(signum, frame):
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
8
 
22
- def read_input():
23
- while True:
9
+ class PeekableQueue(queue.Queue):
10
+ def peek(self):
24
11
  try:
25
- input_text = input()
26
- if input_text.startswith(INPUT_MESSAGE):
27
- yield input_text
28
- else:
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
- for input_text in read_input():
36
- try:
37
- message = json.loads(input_text[len(INPUT_MESSAGE):])
38
- history.append(HumanMessage(message["content"]))
39
- clear_chat_data()
40
-
41
- # 创建一个事件来控制子进程的退出
42
- should_exit = Event()
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
- if parent_conn.poll():
50
- result = parent_conn.recv()
51
- print(result)
52
-
53
- # 检查是否收到了中断信号
54
- while agent_chat_process.is_alive():
55
- if interrupt_flag:
56
- should_exit.set() # 设置退出标志
57
- break
58
- 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"]))
59
27
 
60
- # 确保子进程已经退出
61
- agent_chat_process.join()
62
28
 
63
- # 如果没有收到中断信号,记录输出
64
- if not interrupt_flag:
65
- history.append(AIMessage(content=CHAT_DATA["output"]))
66
-
67
- # 重置中断标志
68
- interrupt_flag = False
69
- except json.JSONDecodeError:
70
- print("Invalid JSON format in input message.")
71
- except KeyError:
72
- print("Missing 'content' key in input message.")
73
- except Exception as e:
74
- print(f"An error occurred: {e}")
75
29
 
76
30
 
77
31
  def get_chat_response(bot_setting_file: str, input_text: str):
@@ -79,4 +33,4 @@ def get_chat_response(bot_setting_file: str, input_text: str):
79
33
  clear_chat_data()
80
34
  should_exit = threading.Event()
81
35
  asyncio.run(agent_chat(bot_setting_file, history, should_exit))
82
- return CHAT_DATA["output"]
36
+ return CHAT_DATA["output"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.206
3
+ Version: 0.1.207
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -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=C5Mfkn6uvckgomDRVG6OEW0qvdFg4J1_nmsRXUXKn8s,2882
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.206.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
32
- pycoze-0.1.206.dist-info/METADATA,sha256=eRPCFXeO4X-sz1aRm8ampoBSEFTqMQdNzGE2i4WKw_g,726
33
- pycoze-0.1.206.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
34
- pycoze-0.1.206.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
35
- pycoze-0.1.206.dist-info/RECORD,,
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,,