Skip to content
Snippets Groups Projects
Commit 7f957236 authored by zehe's avatar zehe
Browse files

cleanup

parent c79eb420
Branches main
No related tags found
No related merge requests found
...@@ -165,70 +165,6 @@ async def startup_event(): ...@@ -165,70 +165,6 @@ async def startup_event():
asyncio.create_task(update_api_pods()) asyncio.create_task(update_api_pods())
class Document(BaseModel):
text: str
"""
@app.post("/kallimachosPipeline")
async def process_document(request: Request):
logger.info(f"Received request")
# Read the body as raw bytes
raw_body = await request.body()
# First, try to parse as JSON.
try:
body = json.loads(raw_body)
except json.JSONDecodeError:
# If JSON decoding fails, try to parse as URL-encoded data.
qs = raw_body.decode("utf-8")
parsed_qs = urllib.parse.parse_qs(qs)
# parse_qs returns a dict with list values; extract the first item.
body = {k: v[0] for k, v in parsed_qs.items() if v}
text = body.get("text")
if not text:
return {"error": "Missing 'text' in request body."}
# Wait until one pod is available.
pod_ip, pod_name = await get_free_pod()
logger.info(f"Selected pod: {pod_ip, pod_name}")
await asyncio.sleep(10)
try:
# Prepare the file to send to the API pod.
# We assume the API pod is listening on port 80.
url = f"http://{pod_ip}:80/kallimachosPipeline"
myobj = {'text': text}
headers = {'Content-type': 'application/json; charset=utf-8'}
async with httpx.AsyncClient(timeout=None) as client:
response = await client.post(url, data=myobj, headers=headers)
if response.status_code != 200:
raise HTTPException(
status_code=response.status_code,
detail=f"Error from upstream API pod: {response.text}"
)
# Optionally, pass through relevant headers (adjust as needed)
headers = {
key: value
for key, value in response.headers.items()
if key.lower() in ["content-type", "content-disposition"]
}
return Response(
content=response.content,
status_code=response.status_code,
headers=headers
)
except Exception as err:
raise HTTPException(status_code=500, detail=str(err))
finally:
await mark_pod_free(pod_ip, pod_name)
"""
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]) @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"])
async def proxy(path: str, request: Request): async def proxy(path: str, request: Request):
logger = app.logger if hasattr(app, "logger") else print logger = app.logger if hasattr(app, "logger") else print
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment