Spaces:
Sleeping
Sleeping
Gemini
commited on
Commit
·
f03dace
1
Parent(s):
7c8e447
fix: Change chat endpoint to /chat_api and add /hello
Browse files- main.py +6 -3
- static/script.js +1 -1
main.py
CHANGED
|
@@ -16,8 +16,7 @@ app = FastAPI()
|
|
| 16 |
# Mount the static directory to serve CSS and JS files
|
| 17 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 18 |
|
| 19 |
-
|
| 20 |
-
@app.post("/api/chat")
|
| 21 |
async def chat_endpoint(request: Request):
|
| 22 |
body = await request.json()
|
| 23 |
model = body.get("model", "llama3")
|
|
@@ -41,6 +40,10 @@ async def chat_endpoint(request: Request):
|
|
| 41 |
except Exception as e:
|
| 42 |
raise HTTPException(status_code=500, detail=str(e))
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# API v1 Router (secured)
|
| 45 |
api_v1 = APIRouter()
|
| 46 |
|
|
@@ -83,4 +86,4 @@ async def root():
|
|
| 83 |
|
| 84 |
@app.get("/chat")
|
| 85 |
async def chat_page():
|
| 86 |
-
return FileResponse('chat.html')
|
|
|
|
| 16 |
# Mount the static directory to serve CSS and JS files
|
| 17 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 18 |
|
| 19 |
+
@app.post("/chat_api")
|
|
|
|
| 20 |
async def chat_endpoint(request: Request):
|
| 21 |
body = await request.json()
|
| 22 |
model = body.get("model", "llama3")
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
raise HTTPException(status_code=500, detail=str(e))
|
| 42 |
|
| 43 |
+
@app.get("/hello")
|
| 44 |
+
async def hello():
|
| 45 |
+
return {"message": "Hello, world!"}
|
| 46 |
+
|
| 47 |
# API v1 Router (secured)
|
| 48 |
api_v1 = APIRouter()
|
| 49 |
|
|
|
|
| 86 |
|
| 87 |
@app.get("/chat")
|
| 88 |
async def chat_page():
|
| 89 |
+
return FileResponse('chat.html')
|
static/script.js
CHANGED
|
@@ -18,7 +18,7 @@ function sendMessage() {
|
|
| 18 |
appendMessage(message, 'user-message');
|
| 19 |
messageInput.value = '';
|
| 20 |
|
| 21 |
-
fetch('/
|
| 22 |
method: 'POST',
|
| 23 |
headers: {
|
| 24 |
'Content-Type': 'application/json'
|
|
|
|
| 18 |
appendMessage(message, 'user-message');
|
| 19 |
messageInput.value = '';
|
| 20 |
|
| 21 |
+
fetch('/chat_api', {
|
| 22 |
method: 'POST',
|
| 23 |
headers: {
|
| 24 |
'Content-Type': 'application/json'
|