-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
77 lines (59 loc) · 1.98 KB
/
Copy pathmain.py
File metadata and controls
77 lines (59 loc) · 1.98 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
67
68
69
70
71
72
73
74
75
76
# from flask import Flask, request, jsonify
# app = Flask(__name__)
# @app.route('/chat', methods=['GET', 'POST'])
# def chat():
# if request.method == 'POST':
# data = request.json
# message = data.get('message', "No message found")
# print("message:", message)
# return jsonify({"response": "I have received your message"})
# else:
# return jsonify({"response": "Please send a POST request"})
# if __name__ == "__main__":
# app.run(host="0.0.0.0", port=8080, debug=True)
'''
import yaml
from retaillm import RetaiLLM
from flask import Flask, request, jsonify
def main():
config = yaml.safe_load(open("./config.yaml"))
agent_config = config["Agent"]
while True:
user_input = input("enter a sentence: ")
retaillm = RetaiLLM(
api_key = agent_config["api_key"],
base_url = agent_config["base_url"],
model_id = agent_config["model_id"],
debug = agent_config["debug"]
)
response = retaillm.chat(user_input)
print("response", response)
# if __name__ == "__main__":
# app.run(host="0.0.0.0", port = 8080, debug=True)
main()
'''
import yaml
from flask import Flask, request, jsonify
from retaillm import RetaiLLM
app = Flask(__name__)
# Load configuration once at startup
with open("./config.yaml") as f:
config = yaml.safe_load(f)
agent_config = config["Agent"]
# Initialize RetaiLLM once
retaillm = RetaiLLM(
api_key=agent_config["api_key"],
base_url=agent_config["base_url"],
model_id=agent_config["model_id"],
debug=agent_config["debug"]
)
@app.route('/chat', methods=['POST'])
def chat():
data = request.get_json()
if not data or 'user_input' not in data:
return jsonify({"error": "Missing 'user_input' in request"}), 400
user_input = data['user_input']
response = retaillm.chat(user_input)
return jsonify({"response": response})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5005)