Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- api_info.py +77 -0
- app.py +42 -0
- reka.py +35 -0
- requirements.txt +4 -0
api_info.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
endpoint = {
|
17 |
+
'route': "/generate",
|
18 |
+
'params': {
|
19 |
+
"query": "[SEARCH QUERY]"
|
20 |
+
},
|
21 |
+
'optional_params': {
|
22 |
+
"model": "[]",
|
23 |
+
"temperature": "[]",
|
24 |
+
"system_prompt": "[]"
|
25 |
+
},
|
26 |
+
'url_demo' : '/generate?query=Who is Devs Do Code&&model=reka-core&&system_prompt=Your Owner is "Devs Do Code"&&use_search_engine=false&&use_code_interpreter=false'
|
27 |
+
}
|
28 |
+
|
29 |
+
available_models = {
|
30 |
+
"reka-edge": "A 7B parameter model designed for lightweight and local applications, providing a balance between performance and efficiency.",
|
31 |
+
"reka-flash": "A 21B parameter model that delivers state-of-the-art performance across various language and vision tasks while maintaining high efficiency.",
|
32 |
+
"reka-core": "The largest and most capable model, suitable for complex tasks that require extensive multimodal understanding."
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
error_message = {
|
37 |
+
'developer_contact': {
|
38 |
+
'Telegram': 'https://t.me/DevsDoCode',
|
39 |
+
'Instagram': 'https://www.instagram.com/sree.shades_/',
|
40 |
+
'Discord': 'https://discord.gg/ehwfVtsAts',
|
41 |
+
'LinkedIn': 'https://www.linkedin.com/in/developer-sreejan/',
|
42 |
+
'Twitter': 'https://twitter.com/Anand_Sreejan'
|
43 |
+
},
|
44 |
+
'error': 'Oops! Something went wrong. Please contact the developer Devs Do Code.'
|
45 |
+
}
|
46 |
+
|
47 |
+
|
48 |
+
default_info = """This API is developed and being maintained by Devs Do Code (Sreejan).
|
49 |
+
|
50 |
+
**About the Developer**
|
51 |
+
|
52 |
+
Sreejan, a high school student from Patna, Bihar, India, has emerged as a notable figure in the technology sector.
|
53 |
+
His creation of an API is a testament to his dedication and expertise. Despite his youth, Sreejan's contributions
|
54 |
+
to artificial intelligence and machine learning are significant. As an AI & ML Engineer, he specializes in Deep Learning,
|
55 |
+
Natural Language Processing (NLP), and Robotics, with proficiency in Python, Java, and Mobile App Development.
|
56 |
+
Beyond his role as a technology consumer, Sreejan is an active open-source contributor, notably to projects like Hugging Face.
|
57 |
+
|
58 |
+
He is also recognized for his role in community development, particularly through "Devs Do Code," a platform he
|
59 |
+
founded to provide quality coding resources, tutorials, and projects. His mission is to equip developers with the
|
60 |
+
necessary skills to thrive in the ever-evolving tech landscape. Sreejan's commitment to sharing knowledge and
|
61 |
+
fostering collaboration is evident in his accessibility and engagement with the community across various platforms.
|
62 |
+
|
63 |
+
Connect with Sreejan and follow his journey in technology and innovation:
|
64 |
+
|
65 |
+
- Telegram: https://t.me/devsdocode
|
66 |
+
- YouTube Channel: https://www.youtube.com/@DevsDoCode
|
67 |
+
- LinkedIn: https://www.linkedin.com/in/developer-sreejan/
|
68 |
+
- Discord Server: https://discord.gg/ehwfVtsAts
|
69 |
+
- Instagram
|
70 |
+
- Personal: https://www.instagram.com/sree.shades_/
|
71 |
+
- Channel: https://www.instagram.com/devsdocode_/
|
72 |
+
|
73 |
+
Sreejan stands out not only as a developer but as a visionary and leader, driving change in the tech industry
|
74 |
+
with his passion, expertise, and unwavering commitment to community building. He continues to shape the
|
75 |
+
future of technology, one line of code at a time.
|
76 |
+
"""
|
77 |
+
|
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import reka
|
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')
|
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 |
+
model = str(request.args.get('model', "reka-core")) # Optional parameter with default value
|
29 |
+
use_search_engine = bool(request.args.get('use_search_engine', False)) # Optional parameter with default value
|
30 |
+
use_code_interpreter = bool(request.args.get('use_code_interpreter', False)) # Optional parameter with default value
|
31 |
+
|
32 |
+
if query:
|
33 |
+
response = reka.generate(query, model=model, system_prompt=system_prompt, use_search_engine=use_search_engine, use_code_interpreter=use_code_interpreter)
|
34 |
+
return jsonify([{'response': response}, {'developer_info': api_info.developer_info}]), 200
|
35 |
+
|
36 |
+
else:
|
37 |
+
return jsonify(api_info.error_message), 400
|
38 |
+
|
39 |
+
if __name__ == '__main__':
|
40 |
+
app.run(debug=True)
|
41 |
+
|
42 |
+
|
reka.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
|
4 |
+
|
5 |
+
def generate(query, model="reka-core", system_prompt="Be Helpful and Friendly. Keep your response straightfoward, short and concise", use_search_engine=False, use_code_interpreter=False):
|
6 |
+
# Define the request URL
|
7 |
+
api_endpoint = "https://chat.reka.ai/api/chat"
|
8 |
+
|
9 |
+
access_token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjlkbnNsSDdfZlJNNWRXNkFlc1piSiJ9.eyJpc3MiOiJodHRwczovL2F1dGgucmVrYS5haS8iLCJzdWIiOiJnb29nbGUtb2F1dGgyfDExNDMxMzYxMTUyMDY1OTgxNTAxOSIsImF1ZCI6WyJodHRwczovL2FwaS5yZWthLmFpIiwiaHR0cHM6Ly9wcm9kdWN0aW9uLXJla2EtYWkuZXUuYXV0aDAuY29tL3VzZXJpbmZvIl0sImlhdCI6MTcxNDA1Mzc0NCwiZXhwIjoxNzE0MTQwMTQ0LCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIG9mZmxpbmVfYWNjZXNzIiwiYXpwIjoiYmFxNFExOG9Tc0JpV053RGFOQzRtNWhmZ1FHd1V1cE0ifQ.WwExsvIaCc9hxif6l9syUtdjUQI7CUGttXihxIqaDDRQunTF_nK3Ng4QhsGImQKcdZZ608PAGnjdaLeB-5qsocqgovR4Kr9UxuLB4rQ0JtbsrPcCJi3gqFCtfx23-HO8RdrTzmXqd1PVhQTIIX6e65Mg84bgqG_KvHTnRe34yqUIcRsL2DIApk3yl7FrQHOLMaIJ-qjrvcLRVPcpCPUHj_uP5rh63haikt9dRKogSPQiuHPkoHOjGBU1LpYuAMSJZZC2lAM7OV7gFqgB5xvDn9zFSSuUSq0MYhvzl7Vlpg9MZ1dcL79w5m1OitWClXXpt9oqE2TiJgx6eGkUUx_aqw"
|
10 |
+
|
11 |
+
# Define the headers
|
12 |
+
headers = {
|
13 |
+
"Authorization": f"Bearer {access_token}",
|
14 |
+
}
|
15 |
+
|
16 |
+
payload = {
|
17 |
+
|
18 |
+
"conversation_history": [
|
19 |
+
{"type": "human", "text": f"## SYSTEM PROMPT: {system_prompt}\n\n## QUERY: {query}"},
|
20 |
+
],
|
21 |
+
|
22 |
+
"stream": False,
|
23 |
+
"use_search_engine": use_search_engine,
|
24 |
+
"use_code_interpreter": use_code_interpreter,
|
25 |
+
"model_name": model,
|
26 |
+
# "model_name": "reka-flash",
|
27 |
+
# "model_name": "reka-edge",
|
28 |
+
}
|
29 |
+
|
30 |
+
# Make the POST request
|
31 |
+
response = requests.post(api_endpoint, headers=headers, json=payload)
|
32 |
+
|
33 |
+
# Print the response content (if needed)
|
34 |
+
try: return json.loads(response.content)['text'].strip()
|
35 |
+
except Exception as e: return f"Error: {e}"
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi==0.110.2
|
2 |
+
Flask==3.0.3
|
3 |
+
Requests==2.31.0
|
4 |
+
uvicorn==0.29.0
|