-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (53 loc) · 1.59 KB
/
app.py
File metadata and controls
66 lines (53 loc) · 1.59 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from flask import Flask, request
from api import db, ai
app = Flask(__name__)
@app.route("/call",methods=["POST"])
def callback_callmessage():
"""
{
"user_id": <UID>,
"chat_id": <INT>,
"content": <TEXT>
}
"""
uid: str = request.json["user_id"]
chat_id: int = int(request.json["chat_id"])
content: str = request.json["content"]
# get chat history
chat = db.getchat(uid, chat_id)
# send add message query to db
new_message = db.addmessage(uid, chat_id, content, "user")
# new message append to chat(variable)
chat.messages.append(new_message)
reply = ai.run(chat)
# send add reply query to db
reply_message = db.addmessage(uid, chat_id, reply, "assistant")
chat.messages.append(reply_message)
return chat.get_content()
@app.route("/chats/ids",methods=["GET"])
def callback_get_user_chatids():
user_id: str = request.args.get("id", type=str)
return {"result": db.getuserschatid(user_id)}
@app.route("/chats/messages",methods=["GET"])
def callback_get_chat_messages():
"""
{
"user_id": <UID>,
"chat_id": <INT>
}
"""
user_id: str = request.args.get("user_id", type=str)
chat_id: int = request.args.get("chat_id", type=int)
return db.getchat(user_id, chat_id).get_content()
@app.route("/chats/new",methods=["POST"])
def callback_new_chat():
"""
{
"user_id": <UID>
}
"""
user_id: str = request.json["user_id"]
return db.newchat(user_id)
@app.route("/",methods=["GET"])
def callback_route_get():
return "THIS IS GET TEST 0825."