Files
Web-Dev-For-Beginners/09-chat-project/solution/backend/api.py
2025-08-28 13:58:47 +00:00

30 lines
690 B
Python

# api
from flask import Flask, request, jsonify
from llm import call_llm
from flask_cors import CORS
app = Flask(__name__)
CORS(app) # * example.com
@app.route("/", methods=["GET"])
def index():
return "Welcome to this lesson"
@app.route("/test", methods=["GET"])
def test():
return "Test"
@app.route("/hello", methods=["POST"])
def hello():
# get message from request body { "message": "do this taks for me" }
data = request.get_json()
message = data.get("message", "")
response = call_llm(message, "You are a helpful assistant.")
return jsonify({
"response": response
})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)