-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path03_04.py
29 lines (21 loc) · 1.01 KB
/
03_04.py
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
26
27
28
29
from flask import Flask, render_template, request, jsonify
import ollama
app = Flask(__name__)
context = "You are the manager of a 5-star restaurant - give precise and accurate responses. Here are some details about the restaurant - Opens at 5pm, Closes at 11pm and it is closed on Tuesdays. The restaurant specializes in European cuisines. Respond to guest inquiries accordingly. Here is the first query: "
messages = [{"role": "system", "content": context}]
@app.route('/')
def home():
return render_template("index.html")
@app.route("/chat", methods=["POST"])
def chat():
user_message = request.json["message"]
messages.append({"role": "user", "content": user_message})
response = ollama.chat(
model='llama3.2',
messages=messages
)
ai_response = response["message"]["content"]
messages.append({"role": "assistant", "content": ai_response})
return jsonify({"response": ai_response})
if __name__ == "__main__":
app.run(debug=True)