neuro-simulator 0.0.2__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/cli.py +12 -12
- neuro_simulator/config.py +5 -5
- neuro_simulator/letta.py +4 -1
- neuro_simulator/main.py +11 -1
- {neuro_simulator-0.0.2.dist-info → neuro_simulator-0.0.4.dist-info}/METADATA +74 -91
- {neuro_simulator-0.0.2.dist-info → neuro_simulator-0.0.4.dist-info}/RECORD +10 -10
- /neuro_simulator/{settings.yaml.example → config.yaml.example} +0 -0
- {neuro_simulator-0.0.2.dist-info → neuro_simulator-0.0.4.dist-info}/WHEEL +0 -0
- {neuro_simulator-0.0.2.dist-info → neuro_simulator-0.0.4.dist-info}/entry_points.txt +0 -0
- {neuro_simulator-0.0.2.dist-info → neuro_simulator-0.0.4.dist-info}/top_level.txt +0 -0
neuro_simulator/cli.py
CHANGED
@@ -8,7 +8,7 @@ from pathlib import Path
|
|
8
8
|
|
9
9
|
def main():
|
10
10
|
parser = argparse.ArgumentParser(description="Neuro-Simulator Server")
|
11
|
-
parser.add_argument("-D", "--dir", help="Working directory containing
|
11
|
+
parser.add_argument("-D", "--dir", help="Working directory containing config.yaml")
|
12
12
|
parser.add_argument("-H", "--host", help="Host to bind the server to")
|
13
13
|
parser.add_argument("-P", "--port", type=int, help="Port to bind the server to")
|
14
14
|
|
@@ -28,38 +28,38 @@ def main():
|
|
28
28
|
# Change to working directory
|
29
29
|
os.chdir(work_dir)
|
30
30
|
|
31
|
-
# Handle
|
32
|
-
settings_example_path = work_dir / "
|
33
|
-
settings_path = work_dir / "
|
31
|
+
# Handle config.yaml.example
|
32
|
+
settings_example_path = work_dir / "config.yaml.example"
|
33
|
+
settings_path = work_dir / "config.yaml"
|
34
34
|
|
35
|
-
# Copy
|
35
|
+
# Copy config.yaml.example from package if it doesn't exist
|
36
36
|
if not settings_example_path.exists():
|
37
37
|
try:
|
38
38
|
# Try pkg_resources first (for installed packages)
|
39
39
|
try:
|
40
40
|
import pkg_resources
|
41
|
-
example_path = pkg_resources.resource_filename('neuro_simulator', '
|
41
|
+
example_path = pkg_resources.resource_filename('neuro_simulator', 'config.yaml.example')
|
42
42
|
if os.path.exists(example_path):
|
43
43
|
shutil.copy(example_path, settings_example_path)
|
44
44
|
print(f"Created {settings_example_path} from package example")
|
45
45
|
else:
|
46
46
|
# Fallback to relative path (for development mode)
|
47
|
-
dev_example_path = Path(__file__).parent / "
|
47
|
+
dev_example_path = Path(__file__).parent / "config.yaml.example"
|
48
48
|
if dev_example_path.exists():
|
49
49
|
shutil.copy(dev_example_path, settings_example_path)
|
50
50
|
print(f"Created {settings_example_path} from development example")
|
51
51
|
else:
|
52
|
-
print("Warning:
|
52
|
+
print("Warning: config.yaml.example not found in package or development folder")
|
53
53
|
except Exception:
|
54
54
|
# Fallback to relative path (for development mode)
|
55
|
-
dev_example_path = Path(__file__).parent / "
|
55
|
+
dev_example_path = Path(__file__).parent / "config.yaml.example"
|
56
56
|
if dev_example_path.exists():
|
57
57
|
shutil.copy(dev_example_path, settings_example_path)
|
58
58
|
print(f"Created {settings_example_path} from development example")
|
59
59
|
else:
|
60
|
-
print("Warning:
|
60
|
+
print("Warning: config.yaml.example not found in package or development folder")
|
61
61
|
except Exception as e:
|
62
|
-
print(f"Warning: Could not copy
|
62
|
+
print(f"Warning: Could not copy config.yaml.example from package: {e}")
|
63
63
|
|
64
64
|
# Handle media folder
|
65
65
|
media_dir = work_dir / "media"
|
@@ -101,7 +101,7 @@ def main():
|
|
101
101
|
# Now check for required files and handle errors appropriately
|
102
102
|
errors = []
|
103
103
|
|
104
|
-
# Check for
|
104
|
+
# Check for config.yaml (required for running)
|
105
105
|
if not settings_path.exists():
|
106
106
|
if settings_example_path.exists():
|
107
107
|
errors.append(f"Error: {settings_path} not found. Please copy {settings_example_path} to {settings_path} and configure it.")
|
neuro_simulator/config.py
CHANGED
@@ -88,7 +88,7 @@ class AppSettings(BaseModel):
|
|
88
88
|
|
89
89
|
# --- 2. 加载和管理配置的逻辑 ---
|
90
90
|
|
91
|
-
CONFIG_FILE_PATH = "
|
91
|
+
CONFIG_FILE_PATH = "config.yaml"
|
92
92
|
|
93
93
|
def _deep_update(source: dict, overrides: dict) -> dict:
|
94
94
|
"""
|
@@ -120,7 +120,7 @@ class ConfigManager:
|
|
120
120
|
|
121
121
|
def _load_config_from_yaml(self) -> dict:
|
122
122
|
if not os.path.exists(CONFIG_FILE_PATH):
|
123
|
-
logging.warning(f"{CONFIG_FILE_PATH} not found. Using default settings. You can create it from
|
123
|
+
logging.warning(f"{CONFIG_FILE_PATH} not found. Using default settings. You can create it from config.yaml.example.")
|
124
124
|
return {}
|
125
125
|
try:
|
126
126
|
with open(CONFIG_FILE_PATH, 'r', encoding='utf-8') as f:
|
@@ -141,14 +141,14 @@ class ConfigManager:
|
|
141
141
|
missing_keys.append("api_keys.neuro_agent_id")
|
142
142
|
|
143
143
|
if missing_keys:
|
144
|
-
raise ValueError(f"Critical config missing in
|
145
|
-
f"Please check your
|
144
|
+
raise ValueError(f"Critical config missing in config.yaml: {', '.join(missing_keys)}. "
|
145
|
+
f"Please check your config.yaml file against config.yaml.example.")
|
146
146
|
|
147
147
|
logging.info("Configuration loaded successfully.")
|
148
148
|
return base_settings
|
149
149
|
|
150
150
|
def save_settings(self):
|
151
|
-
"""Saves the current configuration to
|
151
|
+
"""Saves the current configuration to config.yaml."""
|
152
152
|
try:
|
153
153
|
# 1. Get the current settings from memory
|
154
154
|
config_to_save = self.settings.model_dump(mode='json', exclude={'api_keys'})
|
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
|
-
|
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
|
-
|
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
1
|
Metadata-Version: 2.4
|
2
|
-
Name:
|
3
|
-
Version: 0.0.
|
2
|
+
Name: neuro_simulator
|
3
|
+
Version: 0.0.4
|
4
4
|
Summary: Neuro Simulator Server
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
@@ -28,33 +29,27 @@ Requires-Dist: pydantic
|
|
28
29
|
Requires-Dist: jinja2
|
29
30
|
Requires-Dist: python-multipart
|
30
31
|
Requires-Dist: mutagen
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
Dynamic: home-page
|
37
|
-
Dynamic: requires-dist
|
38
|
-
Dynamic: requires-python
|
39
|
-
Dynamic: summary
|
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"
|
40
37
|
|
41
38
|
# Neuro-Simulator 服务端
|
42
39
|
|
43
|
-
*关注Vedal喵,关注Vedal谢谢喵*
|
44
|
-
|
45
40
|
*本临时README由AI自动生成*
|
46
41
|
|
47
|
-
这是 Neuro Simulator
|
42
|
+
这是 Neuro Simulator 的服务端,负责处理直播逻辑、AI 交互、TTS 合成等核心功能。
|
48
43
|
|
49
44
|
## 功能特性
|
50
45
|
|
51
|
-
-
|
46
|
+
- **动态观众**:调用无状态LLM,动态生成观众聊天内容,支持 Gemini 和 OpenAI API
|
52
47
|
- **配置管理**:支持通过 API 动态修改和热重载配置
|
53
48
|
- **外部控制**:完全使用外部API端点操控服务端运行
|
54
49
|
|
55
50
|
## 目录结构
|
56
51
|
|
57
|
-
```
|
52
|
+
``` main
|
58
53
|
neuro_simulator/
|
59
54
|
├── main.py # 应用入口和核心逻辑
|
60
55
|
├── config.py # 配置管理模块
|
@@ -68,87 +63,73 @@ neuro_simulator/
|
|
68
63
|
├── shared_state.py # 全局状态管理
|
69
64
|
├── log_handler.py # 日志处理模块
|
70
65
|
├── requirements.txt # Python 依赖列表
|
71
|
-
├──
|
66
|
+
├── pyproject.toml # Python 包安装配置
|
72
67
|
├── cli.py # 命令行启动脚本
|
73
|
-
├──
|
68
|
+
├── config.yaml.example # 自带的备用配置模板
|
74
69
|
└── media/ # 自带的备用媒体文件
|
75
|
-
|
70
|
+
└── neuro_start.mp4 # 用来计算Start Soon长度,仅读取时长
|
76
71
|
```
|
77
72
|
|
78
|
-
```
|
79
|
-
working_dir_example/ #
|
73
|
+
``` workin'dir
|
74
|
+
working_dir_example/ # 工作目录结构,请将这个目录重命名和复制到你想要的位置(推荐放到~/.config/neuro-simulator)
|
80
75
|
├── media/ # 媒体文件夹,如缺失会使用自带资源覆盖
|
81
|
-
│
|
82
|
-
├──
|
83
|
-
└──
|
76
|
+
│ └── neuro_start.mp4 # 用来计算Start Soon长度,仅读取时长,请和客户端的视频保持一致
|
77
|
+
├── config.yaml # 由用户手工创建的配置文件
|
78
|
+
└── config.yaml.example # 自动生成的配置文件模板,必须手动重命名和填写
|
84
79
|
```
|
85
80
|
|
86
81
|
## 安装与配置
|
87
82
|
|
88
|
-
0.
|
89
|
-
|
90
|
-
|
91
|
-
|
83
|
+
0. **在运行server前,必须有已经配置完成的Letta Agent。**
|
84
|
+
1. 复制一份 `../docs/working_dir_example` 到你想要的位置,作为配置文件目录.
|
85
|
+
- 程序会在未指定 `--dir` 的情况下自动生成一个工作目录,路径为 `~/.config/neuro-simulator/`
|
86
|
+
2. 然后进入配置文件目录,复制 `config.yaml.example` 到 `config.yaml`
|
87
|
+
3. 编辑 `config.yaml` 文件,填入必要的 API 密钥和配置项:
|
92
88
|
- Letta Token 和 Agent ID
|
93
89
|
- Gemini/OpenAI API Key
|
94
90
|
- Azure TTS Key 和 Region
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# Windows
|
138
|
-
venv\Scripts\activate
|
139
|
-
# macOS/Linux
|
140
|
-
source venv/bin/activate
|
141
|
-
```
|
142
|
-
|
143
|
-
2. **安装依赖**
|
144
|
-
```bash
|
145
|
-
pip install -r requirements.txt
|
146
|
-
```
|
147
|
-
|
148
|
-
3. **启动服务**
|
149
|
-
```bash
|
150
|
-
uvicorn main:app --host 127.0.0.1 --port 8000
|
151
|
-
```
|
91
|
+
|
92
|
+
可以执行替换media/neuro_start.mp4为其它视频文件,但记得手动替换client中的同名文件。
|
93
|
+
|
94
|
+
### 直接安装方式(无需二次开发)
|
95
|
+
|
96
|
+
若无需二次开发,可以直接使用pip安装:
|
97
|
+
```bash
|
98
|
+
python3 -m venv venv
|
99
|
+
# Windows
|
100
|
+
venv/Scripts/pip install neuro-simulator
|
101
|
+
# macOS/Linux
|
102
|
+
venv/bin/pip install neuro-simulator
|
103
|
+
```
|
104
|
+
|
105
|
+
### 二次开发方式
|
106
|
+
|
107
|
+
若需要二次开发,请克隆项目,在server下建立venv,然后pip install -e ./:
|
108
|
+
```bash
|
109
|
+
git clone https://github.com/your-username/Neuro-Simulator.git
|
110
|
+
cd Neuro-Simulator/server
|
111
|
+
python3 -m venv venv
|
112
|
+
# Windows
|
113
|
+
venv/Scripts/pip install -e .
|
114
|
+
# macOS/Linux
|
115
|
+
venv/bin/pip install -e .
|
116
|
+
```
|
117
|
+
|
118
|
+
### 运行服务
|
119
|
+
|
120
|
+
```bash
|
121
|
+
# 使用默认配置 (位于~/.config/neuro-simulator/)
|
122
|
+
neuro
|
123
|
+
|
124
|
+
# 指定工作目录
|
125
|
+
neuro -D /path/to/your/config
|
126
|
+
|
127
|
+
# 指定主机和端口
|
128
|
+
neuro -H 0.0.0.0 -P 8080
|
129
|
+
|
130
|
+
# 组合使用
|
131
|
+
neuro -D /path/to/your/config -H 0.0.0.0 -P 8080
|
132
|
+
```
|
152
133
|
|
153
134
|
服务默认运行在 `http://127.0.0.1:8000`。
|
154
135
|
|
@@ -169,7 +150,7 @@ working_dir_example/ # 工作目录结构
|
|
169
150
|
|
170
151
|
## 配置说明
|
171
152
|
|
172
|
-
配置文件 `
|
153
|
+
配置文件 `config.yaml` 包含以下主要配置项:
|
173
154
|
|
174
155
|
- `api_keys` - 各种服务的 API 密钥
|
175
156
|
- `stream_metadata` - 直播元数据(标题、分类、标签等)
|
@@ -179,11 +160,13 @@ working_dir_example/ # 工作目录结构
|
|
179
160
|
- `performance` - 性能相关设置
|
180
161
|
- `server` - 服务器设置(主机、端口、CORS 等)
|
181
162
|
|
163
|
+
有关配置文件的完整示例,请参阅项目根目录下的 `docs/working_dir_example/` 文件夹。
|
164
|
+
|
182
165
|
## 安全说明
|
183
166
|
|
184
167
|
1. 通过 `panel_password` 配置项可以设置控制面板访问密码
|
185
168
|
2. 敏感配置项(如 API 密钥)不会通过 API 接口暴露
|
186
|
-
3. 支持 CORS
|
169
|
+
3. 支持 CORS,仅允许预配置的来源访问
|
187
170
|
|
188
171
|
## 故障排除
|
189
172
|
|
@@ -1,20 +1,20 @@
|
|
1
1
|
neuro_simulator/__init__.py,sha256=JJWUFh_lBowSfGMhmC9zixE70cB7GG1pTbjGY4Kg3mU,29
|
2
2
|
neuro_simulator/audio_synthesis.py,sha256=fwS0car42-aheCFVQDgRpUTnqLv4DU9Re66PCa6zTBM,2938
|
3
3
|
neuro_simulator/chatbot.py,sha256=qQamPO5QTPwV1avNXrzjZpiJlWN3X_6vxSZPSA17jb0,5152
|
4
|
-
neuro_simulator/cli.py,sha256=
|
5
|
-
neuro_simulator/config.py,sha256=
|
6
|
-
neuro_simulator/
|
4
|
+
neuro_simulator/cli.py,sha256=gf_9Ar_uIodL8O2ZhrXhtXXFJzaQ6QCEzWoQub-JOeI,5978
|
5
|
+
neuro_simulator/config.py,sha256=7ek1hKi4mxTRv1IdrkkFgY8Hb_JaPL8a637z71TKHpw,9613
|
6
|
+
neuro_simulator/config.yaml.example,sha256=uywVEnoFZGZ4g6qdp616Qoi78F2AF21rSG99gtFiY-s,6003
|
7
|
+
neuro_simulator/letta.py,sha256=5lcypQE8bnOXVAELSjoRJ27RlLU2C_Skvy4QB85J3Nk,6623
|
7
8
|
neuro_simulator/log_handler.py,sha256=JlCtJ7wJ0pruVGVO5u-kz-F5uaYhlBl4H5xoGUFhT18,1079
|
8
|
-
neuro_simulator/main.py,sha256=
|
9
|
+
neuro_simulator/main.py,sha256=1otrYFzSLO6ctYYV04tKWMNJFCwEuulfPTlsdHH2Uwk,22444
|
9
10
|
neuro_simulator/process_manager.py,sha256=KqW11PRJR5e4RSBytaZdkgbd3wxRtWqlz6D0TA4oR1s,2492
|
10
|
-
neuro_simulator/settings.yaml.example,sha256=uywVEnoFZGZ4g6qdp616Qoi78F2AF21rSG99gtFiY-s,6003
|
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.
|
17
|
-
neuro_simulator-0.0.
|
18
|
-
neuro_simulator-0.0.
|
19
|
-
neuro_simulator-0.0.
|
20
|
-
neuro_simulator-0.0.
|
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,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|