File size: 439 Bytes
0c91bd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import Response
import ollama

app = FastAPI()

@app.get('/')
def home():
    return "Hello world"

@app.post("/chat")
async def chat(query: str):
    if not query:
        return {"error": "Message cannot be empty."}

    response = ollama.chat(model="llama3", messages=[{"role": "user", "content": query}])
    return {"response": response['message']['content']}