DevsDoCode commited on
Commit
cbbe463
·
verified ·
1 Parent(s): e858097

Upload 4 files

Browse files
Files changed (4) hide show
  1. api_info.py +73 -0
  2. flask_app.py +40 -0
  3. mistral_8x7b.py +21 -0
  4. requirements.txt +3 -3
api_info.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ developer_info = {
2
+ 'developer': 'Devs Do Code',
3
+ 'contact': {
4
+ 'Telegram': 'https://t.me/devsdocode',
5
+ 'YouTube Channel': 'https://www.youtube.com/@DevsDoCode',
6
+ 'LinkedIn': 'https://www.linkedin.com/in/developer-sreejan/',
7
+ 'Discord Server': 'https://discord.gg/ehwfVtsAts',
8
+ 'Instagram': {
9
+ 'Personal': 'https://www.instagram.com/sree.shades_/',
10
+ 'Channel': 'https://www.instagram.com/devsdocode_/'
11
+ }
12
+ }
13
+ }
14
+
15
+
16
+ default_info = """This API is developed and being maintained by Devs Do Code (Sreejan).
17
+
18
+ **About the Developer**
19
+
20
+ Sreejan, a high school student from Patna, Bihar, India, has emerged as a notable figure in the technology sector.
21
+ His creation of an API is a testament to his dedication and expertise. Despite his youth, Sreejan's contributions
22
+ to artificial intelligence and machine learning are significant. As an AI & ML Engineer, he specializes in Deep Learning,
23
+ Natural Language Processing (NLP), and Robotics, with proficiency in Python, Java, and Mobile App Development.
24
+ Beyond his role as a technology consumer, Sreejan is an active open-source contributor, notably to projects like Hugging Face.
25
+
26
+ He is also recognized for his role in community development, particularly through "Devs Do Code," a platform he
27
+ founded to provide quality coding resources, tutorials, and projects. His mission is to equip developers with the
28
+ necessary skills to thrive in the ever-evolving tech landscape. Sreejan's commitment to sharing knowledge and
29
+ fostering collaboration is evident in his accessibility and engagement with the community across various platforms.
30
+
31
+ Connect with Sreejan and follow his journey in technology and innovation:
32
+
33
+ - Telegram: https://t.me/devsdocode
34
+ - YouTube Channel: https://www.youtube.com/@DevsDoCode
35
+ - LinkedIn: https://www.linkedin.com/in/developer-sreejan/
36
+ - Discord Server: https://discord.gg/ehwfVtsAts
37
+ - Instagram
38
+ - Personal: https://www.instagram.com/sree.shades_/
39
+ - Channel: https://www.instagram.com/devsdocode_/
40
+
41
+ Sreejan stands out not only as a developer but as a visionary and leader, driving change in the tech industry
42
+ with his passion, expertise, and unwavering commitment to community building. He continues to shape the
43
+ future of technology, one line of code at a time.
44
+ """
45
+
46
+
47
+ endpoint = {
48
+ 'route': "/generate",
49
+ 'params': {
50
+ "query": "[SEARCH QUERY]"
51
+ },
52
+ 'optional_params': {
53
+ "max_tokens": "[]",
54
+ "temperature": "[]",
55
+ "system_prompt": "[]"
56
+ },
57
+ 'url_demo' : '/generate?query=Who is Devs Do Code&&max_tokens=500&&temperature=0.7&&system_prompt=Your Owner is "Devs Do Code"'
58
+ }
59
+
60
+ available_models = {
61
+ "model": "Mixtral-8x7B-Instruct-v0.1"
62
+ }
63
+
64
+ error_message = {
65
+ 'developer_contact': {
66
+ 'Telegram': 'https://t.me/DevsDoCode',
67
+ 'Instagram': 'https://www.instagram.com/sree.shades_/',
68
+ 'Discord': 'https://discord.gg/ehwfVtsAts',
69
+ 'LinkedIn': 'https://www.linkedin.com/in/developer-sreejan/',
70
+ 'Twitter': 'https://twitter.com/Anand_Sreejan'
71
+ },
72
+ 'error': 'Oops! Something went wrong. Please contact the developer Devs Do Code.'
73
+ }
flask_app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import mistral_8x7b
3
+ import api_info
4
+
5
+ app = Flask(__name__)
6
+
7
+ @app.route('/')
8
+ def initial():
9
+ return '<pre>' + api_info.default_info + '</pre>'
10
+
11
+ @app.route("/available_models", methods=['GET'])
12
+ def available_models():
13
+ return jsonify(api_info.available_models)
14
+
15
+ @app.route("/endpoints", methods=['GET'])
16
+ def endpoints():
17
+ return jsonify(api_info.endpoint)
18
+
19
+ @app.route("/developer_info", methods=['GET'])
20
+ def developer_info():
21
+ return jsonify(api_info.developer_info)
22
+
23
+ @app.route('/generate', methods=['GET'])
24
+ def generate():
25
+
26
+ query = request.args.get('query') # Question to ask
27
+ system_prompt = str(request.args.get('system', "Be Helpful and Friendly. Keep your response straightfoward, short and concise")) # Optional parameter with default value
28
+ max_tokens = int(request.args.get('max_tokens', 1280)) # Optional parameter with default value
29
+ temperature = float(request.args.get('temperature', 0.9)) # Optional parameter with default value
30
+
31
+ if query:
32
+ response = mistral_8x7b.generate(query, system_prompt=system_prompt, max_tokens=max_tokens, temperature=temperature)
33
+ return jsonify([{'response': response}, {'developer_info': api_info.developer_info}])
34
+ else:
35
+ return jsonify(api_info.error_message), 400
36
+
37
+ if __name__ == '__main__':
38
+ app.run(debug=True)
39
+
40
+
mistral_8x7b.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+
4
+ def generate(message: str, system_prompt: str="Talk Like Shakespeare", max_tokens: int=2048, temperature: float=0.9):
5
+ url = "https://api.yep.com/v1/chat/completions"
6
+ payload = {
7
+ "stream": False,
8
+ "max_tokens": max_tokens,
9
+ "top_p": 0.7,
10
+ "temperature": temperature,
11
+ "messages": [{"content": f"## SYSTEM MESSAGE: {system_prompt}\n\nQUERY: {message}", "role": "user"}],
12
+ "model": "Mixtral-8x7B-Instruct-v0.1"
13
+ }
14
+
15
+ response = requests.post(url, data=json.dumps(payload)).json()
16
+ try : return response['choices'][0]['message']['content']
17
+ except Exception as e : return f"Error processing response: {str(e)}"
18
+
19
+ if __name__ == "__main__":
20
+ query = "What is the capital of India"
21
+ print(generate(query))
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- flask==3.0.0
2
- gunicorn
3
- requests
 
1
+ Flask==3.0.3
2
+ Requests==2.31.0
3
+ gunicorn