DevsDoCode commited on
Commit
8e34cea
·
verified ·
1 Parent(s): 864c556

Upload groq_flask.py

Browse files
Files changed (1) hide show
  1. groq_flask.py +50 -0
groq_flask.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import groq_LPU_inference
3
+
4
+ app = Flask(__name__)
5
+
6
+ @app.route('/chat', methods=['GET'])
7
+ def chat():
8
+
9
+ query = request.args.get('query') # Assuming the query is sent in JSON format
10
+ model = str(request.args.get('model', "mistral")) # Optional parameter with default value
11
+ max_tokens = int(request.args.get('max_tokens', 300))
12
+ temperature = float(request.args.get('temperature', 0.7)) # Optional parameter with default value
13
+ assistant = str(request.args.get('assistant', "")) # Optional parameter with default value
14
+ system = str(request.args.get('system', "Be Helpful and Friendly. Keep your response straightfoward, short and concise")) # Optional parameter with default value
15
+
16
+ # Developer information
17
+ developer_info = {
18
+ 'developer': 'Devs Do Code',
19
+ 'contact': {
20
+ 'Telegram': 'https://t.me/devsdocode',
21
+ 'YouTube Channel': 'https://www.youtube.com/@DevsDoCode',
22
+ 'Discord Server': 'https://discord.gg/ehwfVtsAts',
23
+ 'Instagram': {
24
+ 'Personal': 'https://www.instagram.com/sree.shades_/',
25
+ 'Channel': 'https://www.instagram.com/devsdocode_/'
26
+ }
27
+ }
28
+ }
29
+
30
+ if query:
31
+ response = groq_LPU_inference.Groq_Inference(query, model=model, system=system, assistant=assistant, temp=temperature, max_tokens=max_tokens)
32
+ return jsonify([{'response': response}, {'developer_info': developer_info}])
33
+
34
+ else:
35
+ error_message = {
36
+ 'developer_contact': {
37
+ 'telegram': 'https://t.me/DevsDoCode',
38
+ 'instagram': 'https://www.instagram.com/sree.shades_/',
39
+ 'discord': 'https://discord.gg/ehwfVtsAts',
40
+ 'linkedin': 'https://www.linkedin.com/in/developer-sreejan/',
41
+ 'twitter': 'https://twitter.com/Anand_Sreejan'
42
+ },
43
+ 'error': 'Oops! Something went wrong. Please contact the developer Devs Do Code.'
44
+ }
45
+ return jsonify(error_message), 400
46
+
47
+ if __name__ == '__main__':
48
+ app.run(debug=True)
49
+
50
+