2025-01-23 21:50:55 +08:00
|
|
|
from fastapi import Form
|
|
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from asyncio import to_thread
|
|
|
|
from pipeline_setup import pipe
|
|
|
|
|
|
|
|
# async def text_query(question: str = Form(...)):
|
|
|
|
# """
|
|
|
|
# API endpoint to process text input with the user's query.
|
|
|
|
# """
|
|
|
|
# try:
|
|
|
|
# response = await to_thread(pipe, question)
|
2025-01-24 14:11:46 +08:00
|
|
|
# return JSONResponse({"query": question, "response": response.text})
|
2025-01-23 21:50:55 +08:00
|
|
|
# except Exception as e:
|
2025-01-24 14:11:46 +08:00
|
|
|
# return JSONResponse({"query": question, "error": str(e)})
|
|
|
|
|
|
|
|
async def text_query(question: str = Form(...)):
|
|
|
|
"""
|
|
|
|
API endpoint to process text input with the user's query.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
response = await to_thread(pipe, question)
|
|
|
|
return {"query": question, "response": response.text}
|
|
|
|
except Exception as e:
|
|
|
|
return {"query": question, "error": str(e)}
|