Spaces:
Sleeping
Sleeping
File size: 657 Bytes
e95d3cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from fastapi import FastAPI
import requests
URL = "http://localhost:11434/api/chat"
headers = {"Content-Type": "application/json"}
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "hello world"}
@app.post("/api/chat")
def get_chat_response(body: dict):
print(f"Received body: {body}")
try:
response = requests.post(url=URL, headers=headers, json=body, timeout=600)
return response.json()
except ConnectionRefusedError as error:
return {"error": f"Connection refused from backend with error: {error}"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
|