-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
70 lines (54 loc) · 2.25 KB
/
app.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
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
67
68
69
70
from flask import Flask, request, jsonify, stream_with_context, Response
from agentObject import Agent
from flask_cors import CORS
from dbObject import dbObject
app = Flask(__name__)
CORS(app)
# this needs to be passed in by the request but for now it's just for testing user interactions
# to run a user chat, pyhton3 app.py, then python3 userChatDemo.py
db = dbObject()
agent = Agent(network_id="grapevine-test", agent_id="6", db=db)
@app.route('/')
def index():
return "This is SADIE API"
@app.route('/chat', methods=['POST'])
def chat():
data = request.json
question = data.get('question', '')
def generate():
response = agent.handle_user_chat(question)
for char in response:
yield char
yield '\n'
return Response(stream_with_context(generate()), content_type='text/event-stream')
@app.route('/interaction', methods=['POST'])
def interaction():
data = request.json
partner_agent_id = data.get('partner_agent_id', '')
def generate():
response = agent.handle_agent_interaction(partner_agent_id)
for char in response:
yield char
yield '\n'
return Response(stream_with_context(generate()), content_type='text/event-stream')
# just added this, it's direct, no agent in the middle to update the agent's context prompt (included at the begining of every prompt).
# post agent_id, and new_instructions
@app.route('/update_instructions', methods=['POST'])
def update_instructions():
data = request.json
new_instructions = data.get('new_nstructions', None)
agent_id = data.get('agent_id', None)
db_obj = dbObject()
db_obj.update_instructions(agent_id=agent_id, new_instructions=new_instructions)
return jsonify({'message': 'Instructions updated :)'})
# post agent_id, and new_toxicity_settings
@app.route('/update_toxicity_settings', methods=['POST'])
def update_toxicity_settings():
data = request.json
new_toxicity_settings = data.get('new_toxicity_settings', None)
agent_id = data.get('agent_id', None)
db_obj = dbObject()
db_obj.update_toxicity_settings(agent_id=agent_id, new_toxicity_settings=new_toxicity_settings)
return jsonify({'message': 'Instructions updated :)'})
if __name__ == "__main__":
app.run(debug=True, port=3000)