mereith commited on
Commit
679e281
·
1 Parent(s): fae0e6c
Files changed (2) hide show
  1. README.md +95 -40
  2. requirements.txt +70 -0
README.md CHANGED
@@ -1,25 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # ODR Demo
2
 
3
- A demonstration project containing async SSE (Server-Sent Events) interface request functionality.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- ## Features
 
 
 
6
 
7
- - Async SSE streaming requests
8
- - Support for custom parameters (deep thinking mode, debug mode, etc.)
9
- - Returns async iterator for real-time data processing
10
- - Supports both raw data and parsed JSON data modes
11
- - Structured event parsing with `event` and `data` fields
12
- - Proper SSE event type detection and handling
13
 
14
- ## Install Dependencies
15
 
16
  ```bash
17
- pip install -r requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  ```
19
 
20
- ## Usage
21
 
22
- ### Basic Usage (Raw SSE Events)
23
 
24
  ```python
25
  import asyncio
@@ -37,7 +87,7 @@ async def main():
37
  asyncio.run(main())
38
  ```
39
 
40
- ### Using Parsed Data (JSON Parsed)
41
 
42
  ```python
43
  import asyncio
@@ -55,7 +105,7 @@ async def main():
55
  asyncio.run(main())
56
  ```
57
 
58
- ### Using Class Methods (More Control)
59
 
60
  ```python
61
  import asyncio
@@ -66,9 +116,9 @@ async def main():
66
 
67
  async for event_data in client.stream_chat(
68
  query="Explain deep learning",
69
- deep_thinking_mode=True, # Enable deep thinking
70
- debug=True, # Enable debug mode
71
- chat_id="my_custom_id" # Custom chat ID
72
  ):
73
  event_type = event_data.get('event', 'unknown')
74
  data_content = event_data.get('data', '')
@@ -78,37 +128,42 @@ async def main():
78
  asyncio.run(main())
79
  ```
80
 
81
- ## Run Examples
82
 
83
- ```bash
84
- python example_usage.py
85
- ```
86
-
87
- ## API Parameters
88
-
89
- - `query`: Required, user query content
90
- - `deep_thinking_mode`: Optional, whether to enable deep thinking mode, default False
91
- - `search_before_planning`: Optional, whether to search before planning, default False
92
- - `debug`: Optional, whether to enable debug mode, default False
93
- - `chat_id`: Optional, chat ID, will be auto-generated if not provided
94
 
95
- ## Data Structure
96
 
97
- All functions return an async iterator yielding dictionaries with the following structure:
98
 
99
  ```python
100
  {
101
- "event": "message", # SSE event type (e.g., "message", "error", "data", etc.)
102
- "data": "..." # Event data content
103
  }
104
  ```
105
 
106
- - `request_sse_stream()`: Returns raw data where `data` field contains the original string
107
- - `request_sse_stream_parsed()`: Returns parsed data where `data` field contains JSON objects (when possible)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
- ## File Description
110
 
111
- - `api.py`: Main SSE client implementation
112
- - `example_usage.py`: Usage examples
113
- - `requirements.txt`: Project dependencies
114
- - `app.py`: Gradio application (if exists)
 
1
+ ---
2
+ title: ODR Demo - Async SSE Chat Interface
3
+ emoji: 🤖
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: "4.0.0"
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ short_description: 一个演示项目,包含异步 SSE(服务器发送事件)接口请求功能,支持实时流式聊天体验
12
+ tags:
13
+ - chatbot
14
+ - sse
15
+ - streaming
16
+ - real-time
17
+ - gradio
18
+ - async
19
+ suggested_hardware: cpu-basic
20
+ hf_oauth: false
21
+ disable_embedding: false
22
+ ---
23
+
24
  # ODR Demo
25
 
26
+ 一个演示项目,包含异步 SSE(服务器发送事件)接口请求功能,支持实时流式聊天体验。
27
+
28
+ ## 🌟 特性
29
+
30
+ - 异步 SSE 流式请求
31
+ - 支持自定义参数(深度思考模式、调试模式等)
32
+ - 返回异步迭代器进行实时数据处理
33
+ - 支持原始数据和解析 JSON 数据模式
34
+ - 结构化事件解析,包含 `event` 和 `data` 字段
35
+ - 正确的 SSE 事件类型检测和处理
36
+ - 实时 Markdown 渲染和可折叠工具调用显示
37
+
38
+ ## 🚀 快速开始
39
+
40
+ 这个应用部署在 Hugging Face Spaces 上,你可以直接访问 Web 界面进行交互:
41
 
42
+ 1. 在输入框中输入你的英文问题
43
+ 2. 点击 "Run" 按钮开始处理
44
+ 3. 观察实时的 Agent 和工具调用过程
45
+ 4. 可以随时点击 "Stop" 按钮停止处理
46
 
47
+ ## 📦 本地安装
 
 
 
 
 
48
 
49
+ 如果你想在本地运行此项目:
50
 
51
  ```bash
52
+ # 克隆项目
53
+ git clone <repository-url>
54
+ cd odr-demo
55
+
56
+ # 创建虚拟环境
57
+ python -m venv venv
58
+ source venv/bin/activate # 在 Windows 上使用: venv\Scripts\activate
59
+
60
+ # 安装依赖
61
+ pip install gradio aiohttp
62
+
63
+ # 设置环境变量
64
+ export API_ENDPOINT="your-api-endpoint-here"
65
+
66
+ # 运行应用
67
+ python app.py
68
  ```
69
 
70
+ ## 💻 基本用法
71
 
72
+ ### 原始 SSE 事件
73
 
74
  ```python
75
  import asyncio
 
87
  asyncio.run(main())
88
  ```
89
 
90
+ ### 解析后的数据
91
 
92
  ```python
93
  import asyncio
 
105
  asyncio.run(main())
106
  ```
107
 
108
+ ### 使用类方法(更多控制)
109
 
110
  ```python
111
  import asyncio
 
116
 
117
  async for event_data in client.stream_chat(
118
  query="Explain deep learning",
119
+ deep_thinking_mode=True, # 启用深度思考
120
+ debug=True, # 启用调试模式
121
+ chat_id="my_custom_id" # 自定义聊天 ID
122
  ):
123
  event_type = event_data.get('event', 'unknown')
124
  data_content = event_data.get('data', '')
 
128
  asyncio.run(main())
129
  ```
130
 
131
+ ## ⚙️ API 参数
132
 
133
+ - `query`: 必需,用户查询内容
134
+ - `deep_thinking_mode`: 可选,是否启用深度思考模式,默认 False
135
+ - `search_before_planning`: 可选,是否在规划前搜索,默认 False
136
+ - `debug`: 可选,是否启用调试模式,默认 False
137
+ - `chat_id`: 可选,聊天 ID,如未提供将自动生成
 
 
 
 
 
 
138
 
139
+ ## 📊 数据结构
140
 
141
+ 所有函数返回异步迭代器,产生以下结构的字典:
142
 
143
  ```python
144
  {
145
+ "event": "message", # SSE 事件类型(如 "message", "error", "data" 等)
146
+ "data": "..." # 事件数据内容
147
  }
148
  ```
149
 
150
+ - `request_sse_stream()`: 返回原始数据,`data` 字段包含原始字符串
151
+ - `request_sse_stream_parsed()`: 返回解析后的数据,`data` 字段包含 JSON 对象(如果可能)
152
+
153
+ ## 📁 文件说明
154
+
155
+ - `api.py`: 主要的 SSE 客户端实现
156
+ - `app.py`: Gradio Web 应用程序
157
+ - `utils.py`: 工具函数
158
+ - `README.md`: 项目文档
159
+
160
+ ## 🎯 注意事项
161
+
162
+ - 目前仅支持英文输入
163
+ - 需要设置有效的 `API_ENDPOINT` 环境变量
164
+ - 实时显示包括代理处理过程和工具调用详情
165
+ - 支持错误处理和中断操作
166
 
167
+ ## 📄 许可证
168
 
169
+ MIT License
 
 
 
requirements.txt ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ aiohappyeyeballs==2.6.1
3
+ aiohttp==3.12.15
4
+ aiosignal==1.4.0
5
+ annotated-types==0.7.0
6
+ anyio==4.10.0
7
+ async-timeout==5.0.1
8
+ attrs==25.3.0
9
+ certifi==2025.8.3
10
+ charset-normalizer==3.4.3
11
+ click==8.1.8
12
+ contourpy==1.3.0
13
+ cycler==0.12.1
14
+ exceptiongroup==1.3.0
15
+ fastapi==0.116.1
16
+ ffmpy==0.6.1
17
+ filelock==3.19.1
18
+ fonttools==4.59.1
19
+ frozenlist==1.7.0
20
+ fsspec==2025.7.0
21
+ gradio==4.44.1
22
+ gradio_client==1.3.0
23
+ h11==0.16.0
24
+ hf-xet==1.1.8
25
+ httpcore==1.0.9
26
+ httpx==0.28.1
27
+ huggingface-hub==0.34.4
28
+ idna==3.10
29
+ importlib_resources==6.5.2
30
+ Jinja2==3.1.6
31
+ kiwisolver==1.4.7
32
+ markdown-it-py==3.0.0
33
+ MarkupSafe==2.1.5
34
+ matplotlib==3.9.4
35
+ mdurl==0.1.2
36
+ multidict==6.6.4
37
+ numpy==2.0.2
38
+ orjson==3.11.2
39
+ packaging==25.0
40
+ pandas==2.3.2
41
+ pillow==10.4.0
42
+ propcache==0.3.2
43
+ pydantic==2.11.7
44
+ pydantic_core==2.33.2
45
+ pydub==0.25.1
46
+ Pygments==2.19.2
47
+ pyparsing==3.2.3
48
+ python-dateutil==2.9.0.post0
49
+ python-multipart==0.0.20
50
+ pytz==2025.2
51
+ PyYAML==6.0.2
52
+ requests==2.32.5
53
+ rich==14.1.0
54
+ ruff==0.12.10
55
+ semantic-version==2.10.0
56
+ shellingham==1.5.4
57
+ six==1.17.0
58
+ sniffio==1.3.1
59
+ starlette==0.47.3
60
+ tomlkit==0.12.0
61
+ tqdm==4.67.1
62
+ typer==0.16.1
63
+ typing-inspection==0.4.1
64
+ typing_extensions==4.15.0
65
+ tzdata==2025.2
66
+ urllib3==2.5.0
67
+ uvicorn==0.35.0
68
+ websockets==12.0
69
+ yarl==1.20.1
70
+ zipp==3.23.0