arshadrana commited on
Commit
77335d6
·
verified ·
1 Parent(s): 9f99956

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -1,12 +1,12 @@
1
  import os
2
- from fastapi import FastAPI, HTTPException
3
  from pydantic import BaseModel
4
  import dashscope
5
  from dashscope import Generation
6
 
7
  # Set up the API key for Dashscope
8
- dashscope.api_key = os.getenv('HF_TOKEN') # Ensure the environment variable is set
9
- print(dashscope.api_key)
10
 
11
  app = FastAPI()
12
 
@@ -43,9 +43,6 @@ async def solve_math(query: MathQuery):
43
  answer = get_math_response(user_question)
44
  return {"question": user_question, "answer": answer}
45
 
46
- # Optional: Handle 404 errors gracefully without defining additional routes
47
- @app.exception_handler(HTTPException)
48
- async def http_exception_handler(request, exc):
49
- if exc.status_code == 404:
50
- return {"detail": "Not Found. Use /math-solver to submit a math question."}
51
- return await request.app.default_exception_handler(request, exc)
 
1
  import os
2
+ from fastapi import FastAPI, Request
3
  from pydantic import BaseModel
4
  import dashscope
5
  from dashscope import Generation
6
 
7
  # Set up the API key for Dashscope
8
+ YOUR_API_TOKEN = os.getenv('HF_TOKEN')
9
+ dashscope.api_key = YOUR_API_TOKEN
10
 
11
  app = FastAPI()
12
 
 
43
  answer = get_math_response(user_question)
44
  return {"question": user_question, "answer": answer}
45
 
46
+ @app.get("/")
47
+ def root():
48
+ return {"message": "Welcome to the FastAPI Math Solver!"}