neuro-simulator 0.0.3__py3-none-any.whl → 0.0.4__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.
neuro_simulator/letta.py CHANGED
@@ -2,6 +2,7 @@
2
2
  from letta_client import Letta, MessageCreate, TextContent, LlmConfig, AssistantMessage
3
3
  from fastapi import HTTPException, status
4
4
  from .config import config_manager
5
+ import asyncio
5
6
 
6
7
  # 初始化 Letta 客户端
7
8
  letta_client: Letta | None = None
@@ -106,7 +107,9 @@ async def get_neuro_response(chat_messages: list[dict]) -> str:
106
107
  print(f"正在向 Neuro Agent 发送输入 (包含 {len(chat_messages)} 条消息)..." )
107
108
 
108
109
  try:
109
- response = letta_client.agents.messages.create(
110
+ # 使用 asyncio.to_thread 在线程池中执行阻塞调用,避免阻塞事件循环
111
+ response = await asyncio.to_thread(
112
+ letta_client.agents.messages.create,
110
113
  agent_id=config_manager.settings.api_keys.neuro_agent_id,
111
114
  messages=[MessageCreate(role="user", content=injected_chat_text)]
112
115
  )
neuro_simulator/main.py CHANGED
@@ -155,7 +155,17 @@ async def neuro_response_cycle():
155
155
  current_queue_snapshot = get_all_neuro_input_chats()
156
156
  sample_size = min(config_manager.settings.neuro_behavior.input_chat_sample_size, len(current_queue_snapshot))
157
157
  selected_chats = random.sample(current_queue_snapshot, sample_size)
158
- ai_full_response_text = await get_neuro_response(selected_chats)
158
+
159
+ # 使用 asyncio.wait_for 添加超时机制,避免长时间阻塞
160
+ try:
161
+ ai_full_response_text = await asyncio.wait_for(
162
+ get_neuro_response(selected_chats),
163
+ timeout=10.0 # 默认10秒超时
164
+ )
165
+ except asyncio.TimeoutError:
166
+ print("警告: Letta 响应超时,跳过本轮。")
167
+ await asyncio.sleep(5)
168
+ continue
159
169
 
160
170
  async with shared_state.neuro_last_speech_lock:
161
171
  if ai_full_response_text and ai_full_response_text.strip():
@@ -1,13 +1,14 @@
1
- Metadata-Version: 2.1
2
- Name: neuro-simulator
3
- Version: 0.0.3
1
+ Metadata-Version: 2.4
2
+ Name: neuro_simulator
3
+ Version: 0.0.4
4
4
  Summary: Neuro Simulator Server
5
- Home-page: https://github.com/Moha-Master/neuro-simulator
6
- Author: Moha-Master
7
- Author-email: hongkongreporter@outlook.com
5
+ Author-email: Moha-Master <hongkongreporter@outlook.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Moha-Master/neuro-simulator
8
+ Project-URL: Repository, https://github.com/Moha-Master/neuro-simulator
9
+ Project-URL: Issues, https://github.com/Moha-Master/neuro-simulator/issues
8
10
  Classifier: Development Status :: 4 - Beta
9
11
  Classifier: Intended Audience :: Developers
10
- Classifier: License :: OSI Approved :: MIT License
11
12
  Classifier: Operating System :: OS Independent
12
13
  Classifier: Programming Language :: Python :: 3
13
14
  Classifier: Programming Language :: Python :: 3.8
@@ -17,17 +18,22 @@ Classifier: Programming Language :: Python :: 3.11
17
18
  Classifier: Programming Language :: Python :: 3.12
18
19
  Requires-Python: >=3.8
19
20
  Description-Content-Type: text/markdown
20
- Requires-Dist: azure-cognitiveservices-speech
21
21
  Requires-Dist: fastapi
22
+ Requires-Dist: uvicorn
22
23
  Requires-Dist: google-genai
23
- Requires-Dist: jinja2
24
+ Requires-Dist: azure-cognitiveservices-speech
24
25
  Requires-Dist: letta-client
25
- Requires-Dist: mutagen
26
26
  Requires-Dist: openai
27
+ Requires-Dist: pyyaml
27
28
  Requires-Dist: pydantic
29
+ Requires-Dist: jinja2
28
30
  Requires-Dist: python-multipart
29
- Requires-Dist: pyyaml
30
- Requires-Dist: uvicorn
31
+ Requires-Dist: mutagen
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=6.0; extra == "dev"
34
+ Requires-Dist: pytest-cov; extra == "dev"
35
+ Requires-Dist: black; extra == "dev"
36
+ Requires-Dist: flake8; extra == "dev"
31
37
 
32
38
  # Neuro-Simulator 服务端
33
39
 
@@ -57,7 +63,7 @@ neuro_simulator/
57
63
  ├── shared_state.py # 全局状态管理
58
64
  ├── log_handler.py # 日志处理模块
59
65
  ├── requirements.txt # Python 依赖列表
60
- ├── setup.py # Python 包安装配置
66
+ ├── pyproject.toml # Python 包安装配置
61
67
  ├── cli.py # 命令行启动脚本
62
68
  ├── config.yaml.example # 自带的备用配置模板
63
69
  └── media/ # 自带的备用媒体文件
@@ -75,7 +81,8 @@ working_dir_example/ # 工作目录结构,请将这个目录重命名和
75
81
  ## 安装与配置
76
82
 
77
83
  0. **在运行server前,必须有已经配置完成的Letta Agent。**
78
- 1. 复制一份 `../docs/working_dir_example` 到你想要的位置,作为配置文件目录
84
+ 1. 复制一份 `../docs/working_dir_example` 到你想要的位置,作为配置文件目录.
85
+ - 程序会在未指定 `--dir` 的情况下自动生成一个工作目录,路径为 `~/.config/neuro-simulator/`
79
86
  2. 然后进入配置文件目录,复制 `config.yaml.example` 到 `config.yaml`
80
87
  3. 编辑 `config.yaml` 文件,填入必要的 API 密钥和配置项:
81
88
  - Letta Token 和 Agent ID
@@ -4,17 +4,17 @@ neuro_simulator/chatbot.py,sha256=qQamPO5QTPwV1avNXrzjZpiJlWN3X_6vxSZPSA17jb0,51
4
4
  neuro_simulator/cli.py,sha256=gf_9Ar_uIodL8O2ZhrXhtXXFJzaQ6QCEzWoQub-JOeI,5978
5
5
  neuro_simulator/config.py,sha256=7ek1hKi4mxTRv1IdrkkFgY8Hb_JaPL8a637z71TKHpw,9613
6
6
  neuro_simulator/config.yaml.example,sha256=uywVEnoFZGZ4g6qdp616Qoi78F2AF21rSG99gtFiY-s,6003
7
- neuro_simulator/letta.py,sha256=F0PbnL9vmcznxwkTQKiK9PoGsp42FbCpSbiDuFdjUWo,6475
7
+ neuro_simulator/letta.py,sha256=5lcypQE8bnOXVAELSjoRJ27RlLU2C_Skvy4QB85J3Nk,6623
8
8
  neuro_simulator/log_handler.py,sha256=JlCtJ7wJ0pruVGVO5u-kz-F5uaYhlBl4H5xoGUFhT18,1079
9
- neuro_simulator/main.py,sha256=NlYM9OSv9sxmDIP7KEPOFyDRsU8VlQ2ngqNoNMo9CAE,22043
9
+ neuro_simulator/main.py,sha256=1otrYFzSLO6ctYYV04tKWMNJFCwEuulfPTlsdHH2Uwk,22444
10
10
  neuro_simulator/process_manager.py,sha256=KqW11PRJR5e4RSBytaZdkgbd3wxRtWqlz6D0TA4oR1s,2492
11
11
  neuro_simulator/shared_state.py,sha256=cvYg8vGrkuDmb0e-4J1xvIjXVwspRisuxQaIR9YgsyQ,459
12
12
  neuro_simulator/stream_chat.py,sha256=X655rrOW8oQ77qAFK-dQDhHT3bYiE9w44a9Na_ikM2w,997
13
13
  neuro_simulator/stream_manager.py,sha256=vA88HQGgYguFb3_GUDSY-FpTG0rsjt8J-JFtMoCWWCo,6720
14
14
  neuro_simulator/websocket_manager.py,sha256=a9mMAN7xmgK2w9tVDOOzy4DuWSwdAPatSp6bW9fhE3I,2183
15
15
  neuro_simulator/media/neuro_start.mp4,sha256=xCLnNzv4THnzRYwkdV6EiqXc-XtFd867R2ZVLDvNp0Y,8226418
16
- neuro_simulator-0.0.3.dist-info/METADATA,sha256=aB8eWL6ZQKWQyS4b7xqMHh8Pyg3yOn0FvjM7Mzpe-F8,5940
17
- neuro_simulator-0.0.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
18
- neuro_simulator-0.0.3.dist-info/entry_points.txt,sha256=qVd5ypnRRgU8Cw7rWfZ7o0OXyS9P9hgY-cRoN_mgz9g,51
19
- neuro_simulator-0.0.3.dist-info/top_level.txt,sha256=V8awSKpcrFnjJDiJxSfy7jtOrnuE2BgAR9hLmfMDWK8,16
20
- neuro_simulator-0.0.3.dist-info/RECORD,,
16
+ neuro_simulator-0.0.4.dist-info/METADATA,sha256=MOHKocm9fsjdBrtzLGVCWQSr2bNQ6NtEJxk5itbH2LE,6366
17
+ neuro_simulator-0.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
+ neuro_simulator-0.0.4.dist-info/entry_points.txt,sha256=qVd5ypnRRgU8Cw7rWfZ7o0OXyS9P9hgY-cRoN_mgz9g,51
19
+ neuro_simulator-0.0.4.dist-info/top_level.txt,sha256=V8awSKpcrFnjJDiJxSfy7jtOrnuE2BgAR9hLmfMDWK8,16
20
+ neuro_simulator-0.0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5