AIMaster7 commited on
Commit
9a0435e
·
verified ·
1 Parent(s): 770bf77

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -9
main.py CHANGED
@@ -5,7 +5,7 @@ import socket
5
 
6
  app = FastAPI()
7
 
8
- REAL_API_KEY = "sk-94NDKhKQkhKoYnY65mg4NAIFK5BqNiCtxo8u3PsDpb0IucZt"
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
- # For streaming, use .stream()
50
- upstream_response = await client.stream(
51
  method=request.method,
52
  url=target_url,
53
  headers=headers,
54
  content=body
55
- )
56
 
57
- async def stream_generator():
58
- async for chunk in upstream_response.aiter_bytes():
59
- yield chunk
60
 
61
- return StreamingResponse(stream_generator(), status_code=upstream_response.status_code, media_type="text/event-stream")
 
 
 
 
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,