ollama_server / src /run1.py
Teenu0Detect's picture
Added Ollama server files
e95d3cf verified
raw
history blame
657 Bytes
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)