Spaces:
Sleeping
Sleeping
from fastapi import FastAPI | |
import requests | |
URL = "http://localhost:11434/api/chat" | |
headers = {"Content-Type": "application/json"} | |
app = FastAPI() | |
def read_root(): | |
return {"message": "hello world"} | |
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) | |