Update app.py
Browse files
app.py
CHANGED
|
@@ -43,7 +43,6 @@ async def proxy_handler(url: str, request: Request):
|
|
| 43 |
body = await request.body()
|
| 44 |
|
| 45 |
async with await get_http_client() as client:
|
| 46 |
-
# 判断是否需要流式传输
|
| 47 |
if await is_stream_request(request):
|
| 48 |
# 流式请求
|
| 49 |
response = await client.stream(
|
|
@@ -61,8 +60,11 @@ async def proxy_handler(url: str, request: Request):
|
|
| 61 |
|
| 62 |
async def stream_generator():
|
| 63 |
try:
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
print(f"Streaming error: {e}")
|
| 68 |
finally:
|
|
|
|
| 43 |
body = await request.body()
|
| 44 |
|
| 45 |
async with await get_http_client() as client:
|
|
|
|
| 46 |
if await is_stream_request(request):
|
| 47 |
# 流式请求
|
| 48 |
response = await client.stream(
|
|
|
|
| 60 |
|
| 61 |
async def stream_generator():
|
| 62 |
try:
|
| 63 |
+
buffer = b""
|
| 64 |
+
async for chunk in response.aiter_raw():
|
| 65 |
+
# 立即发送每个收到的块
|
| 66 |
+
if chunk:
|
| 67 |
+
yield chunk
|
| 68 |
except Exception as e:
|
| 69 |
print(f"Streaming error: {e}")
|
| 70 |
finally:
|