Commit
·
d750996
1
Parent(s):
dbad759
bug fixes
Browse files
main.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import re
|
| 3 |
import httpx
|
| 4 |
from fastapi import FastAPI, Request, HTTPException, Security
|
| 5 |
-
from fastapi.responses import StreamingResponse
|
| 6 |
from fastapi.security import APIKeyHeader, APIKeyQuery
|
| 7 |
from itertools import cycle
|
| 8 |
import asyncio
|
|
@@ -110,10 +110,13 @@ async def proxy(request: Request, model_path: str, api_key: str = Security(get_a
|
|
| 110 |
if "streamGenerateContent" in model_path:
|
| 111 |
return StreamingResponse(stream_response(response), media_type=response.headers.get("content-type"))
|
| 112 |
else:
|
| 113 |
-
# For non-streaming, read the response and return
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
if __name__ == "__main__":
|
| 119 |
import uvicorn
|
|
|
|
| 2 |
import re
|
| 3 |
import httpx
|
| 4 |
from fastapi import FastAPI, Request, HTTPException, Security
|
| 5 |
+
from fastapi.responses import StreamingResponse, Response
|
| 6 |
from fastapi.security import APIKeyHeader, APIKeyQuery
|
| 7 |
from itertools import cycle
|
| 8 |
import asyncio
|
|
|
|
| 110 |
if "streamGenerateContent" in model_path:
|
| 111 |
return StreamingResponse(stream_response(response), media_type=response.headers.get("content-type"))
|
| 112 |
else:
|
| 113 |
+
# For non-streaming, read the response and return a new response object.
|
| 114 |
+
response_data = await response.aread()
|
| 115 |
+
return Response(
|
| 116 |
+
content=response_data,
|
| 117 |
+
status_code=response.status_code,
|
| 118 |
+
headers=dict(response.headers),
|
| 119 |
+
)
|
| 120 |
|
| 121 |
if __name__ == "__main__":
|
| 122 |
import uvicorn
|