Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -5,7 +5,7 @@ import socket
|
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
-
REAL_API_KEY = "sk-
|
9 |
BASE_URL = "https://fast.typegpt.net"
|
10 |
PUBLIC_AUTH_TOKEN = "TypeGPT-Free4ALL"
|
11 |
|
@@ -46,21 +46,23 @@ async def proxy(request: Request, path: str, authorization: str = Header(None)):
|
|
46 |
async with httpx.AsyncClient(timeout=60) as client:
|
47 |
try:
|
48 |
if is_stream:
|
49 |
-
|
50 |
-
upstream_response = await client.stream(
|
51 |
method=request.method,
|
52 |
url=target_url,
|
53 |
headers=headers,
|
54 |
content=body
|
55 |
-
)
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
62 |
else:
|
63 |
-
# For normal response, use .request()
|
64 |
response = await client.request(
|
65 |
method=request.method,
|
66 |
url=target_url,
|
|
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
+
REAL_API_KEY = "sk-kwWVUQPDsLemvilLcyzSSWRzo8sctCzxzlbdN0ZC5ZUCCv0m"
|
9 |
BASE_URL = "https://fast.typegpt.net"
|
10 |
PUBLIC_AUTH_TOKEN = "TypeGPT-Free4ALL"
|
11 |
|
|
|
46 |
async with httpx.AsyncClient(timeout=60) as client:
|
47 |
try:
|
48 |
if is_stream:
|
49 |
+
async with client.stream(
|
|
|
50 |
method=request.method,
|
51 |
url=target_url,
|
52 |
headers=headers,
|
53 |
content=body
|
54 |
+
) as upstream_response:
|
55 |
|
56 |
+
async def stream_generator():
|
57 |
+
async for chunk in upstream_response.aiter_bytes():
|
58 |
+
yield chunk
|
59 |
|
60 |
+
return StreamingResponse(
|
61 |
+
stream_generator(),
|
62 |
+
status_code=upstream_response.status_code,
|
63 |
+
media_type="text/event-stream"
|
64 |
+
)
|
65 |
else:
|
|
|
66 |
response = await client.request(
|
67 |
method=request.method,
|
68 |
url=target_url,
|