-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
45 lines (30 loc) · 1.16 KB
/
bot.py
File metadata and controls
45 lines (30 loc) · 1.16 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
from groq import Groq
import os
import requests
from flask_cors import CORS
from flask import Flask,jsonify,request
app = Flask(__name__)
CORS(app)
API_KEY_LLAMA = "cb95a6b8-29ef-4c5c-bd98-3fe6df21c3cd"
def generate_llama_response(context,prompt):
pre_defined=f"""answer in the same language as user
You will recieve user's medical history :{context}\n
You are a professional doctor,you have to assist the user with his basic questions: {prompt}
"""
client = Groq(api_key=API_KEY_LLAMA)
response = client.chat.completions.create(
messages=[{"role": "user", "content": pre_defined}],
model="llama3-8b-8192",
)
return response.choices[0].message.content
@app.route('/chat', methods=['POST'])
def chat():
data=request.get_json()
if not 'prompt' or 'user_data' not in data:
return jsonify({"error": "Invalid input. Please provide 'user_data' in JSON format."}), 400
query = data['prompt']
user= data['user_data']
response=generate_llama_response(user,query)
return jsonify({"response": response})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)