Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import os
|
| 2 |
-
from fastapi import FastAPI
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import dashscope
|
| 5 |
from dashscope import Generation
|
|
@@ -8,6 +8,7 @@ from dashscope import Generation
|
|
| 8 |
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
| 9 |
dashscope.api_key = headers
|
| 10 |
print(dashscope.api_key)
|
|
|
|
| 11 |
app = FastAPI()
|
| 12 |
|
| 13 |
math_messages = []
|
|
@@ -43,3 +44,9 @@ async def solve_math(query: MathQuery):
|
|
| 43 |
answer = get_math_response(user_question)
|
| 44 |
return {"question": user_question, "answer": answer}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from fastapi import FastAPI, HTTPException
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import dashscope
|
| 5 |
from dashscope import Generation
|
|
|
|
| 8 |
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
| 9 |
dashscope.api_key = headers
|
| 10 |
print(dashscope.api_key)
|
| 11 |
+
|
| 12 |
app = FastAPI()
|
| 13 |
|
| 14 |
math_messages = []
|
|
|
|
| 44 |
answer = get_math_response(user_question)
|
| 45 |
return {"question": user_question, "answer": answer}
|
| 46 |
|
| 47 |
+
# Optional: Handle 404 errors gracefully without defining additional routes
|
| 48 |
+
@app.exception_handler(HTTPException)
|
| 49 |
+
async def http_exception_handler(request, exc):
|
| 50 |
+
if exc.status_code == 404:
|
| 51 |
+
return {"detail": "Not Found. Use /math-solver to submit a math question."}
|
| 52 |
+
return await request.app.default_exception_handler(request, exc)
|