Sirorororo commited on
Commit
faa03b1
·
1 Parent(s): 6ace0b8

Fix Request Timeout issue

Browse files
Files changed (2) hide show
  1. app.py +15 -4
  2. requirements.txt +0 -2
app.py CHANGED
@@ -139,10 +139,11 @@
139
  # return response.json()
140
 
141
 
142
- from fastapi import FastAPI, Request
143
  import httpx
144
  from pydantic import BaseModel
145
 
 
146
  class RequestBody(BaseModel):
147
  data: dict
148
 
@@ -158,7 +159,17 @@ async def proxy_get(path: str):
158
 
159
  @app.post("/proxy/{path:path}")
160
  async def proxy_post(path: str, request_body: RequestBody):
 
 
161
  """ Forwards POST requests to the target server """
162
- async with httpx.AsyncClient() as client:
163
- response = await client.post(f"{TARGET_SERVER}/{path}", json = request_body.model_dump())
164
- return response.json()
 
 
 
 
 
 
 
 
 
139
  # return response.json()
140
 
141
 
142
+ from fastapi import FastAPI
143
  import httpx
144
  from pydantic import BaseModel
145
 
146
+
147
  class RequestBody(BaseModel):
148
  data: dict
149
 
 
159
 
160
  @app.post("/proxy/{path:path}")
161
  async def proxy_post(path: str, request_body: RequestBody):
162
+ print(request_body)
163
+ print(request_body.model_dump())
164
  """ Forwards POST requests to the target server """
165
+ try:
166
+ data = request_body.model_dump()["data"]
167
+
168
+ async with httpx.AsyncClient() as client:
169
+ response = await client.post(f"{TARGET_SERVER}/{path}", json=data, timeout=120)
170
+ return response.json()
171
+ except Exception as e:
172
+ print(e)
173
+ return {"error": str(e)}
174
+
175
+
requirements.txt CHANGED
@@ -1,7 +1,5 @@
1
  fastapi
2
  uvicorn
3
  ollama
4
- openai
5
  pydantic
6
- requests
7
  httpx
 
1
  fastapi
2
  uvicorn
3
  ollama
 
4
  pydantic
 
5
  httpx