mirror of
https://github.com/microsoft/Web-Dev-For-Beginners.git
synced 2025-10-04 10:11:47 +02:00
final draft
This commit is contained in:
30
09-chat-project/solution/backend/api.py
Normal file
30
09-chat-project/solution/backend/api.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# 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)
|
Reference in New Issue
Block a user