Upload 28 files
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +9 -7
- auth/__pycache__/key.cpython-311.pyc +0 -0
- auth/key.py +34 -0
- models/__pycache__/fetch.cpython-311.pyc +0 -0
- models/fetch.py +2 -1
- requirements.txt +2 -1
- service.json +13 -0
- test2.py +37 -0
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -6,6 +6,7 @@ from models.text.vercel.main import XaiAPI, GroqAPI, DeepinfraAPI
|
|
6 |
from models.image.vercel.main import FalAPI
|
7 |
from models.image.together.main import TogetherImageAPI
|
8 |
from models.fetch import FetchModel
|
|
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
@@ -125,15 +126,16 @@ async def text_generate(request: Request):
|
|
125 |
data = await request.json()
|
126 |
messages = data['messages']
|
127 |
choice = data['model']
|
128 |
-
api_key = data
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
135 |
|
136 |
-
if not messages or not
|
137 |
return {"error": "Invalid request. 'messages' and 'model' are required."}
|
138 |
|
139 |
model = FetchModel().select_model(choice)
|
|
|
6 |
from models.image.vercel.main import FalAPI
|
7 |
from models.image.together.main import TogetherImageAPI
|
8 |
from models.fetch import FetchModel
|
9 |
+
from auth.key import NimbusAuthKey
|
10 |
|
11 |
app = FastAPI()
|
12 |
|
|
|
126 |
data = await request.json()
|
127 |
messages = data['messages']
|
128 |
choice = data['model']
|
129 |
+
api_key = data.get('api_key')
|
130 |
|
131 |
+
auth = NimbusAuthKey()
|
132 |
+
user = auth.get_user(data.get('api_key'))
|
133 |
+
if not user:
|
134 |
+
return {"error": "Invalid API key"}
|
135 |
+
if not api_key:
|
136 |
+
return {"error": "API key is required"}
|
137 |
|
138 |
+
if not messages or not choice:
|
139 |
return {"error": "Invalid request. 'messages' and 'model' are required."}
|
140 |
|
141 |
model = FetchModel().select_model(choice)
|
auth/__pycache__/key.cpython-311.pyc
ADDED
Binary file (1.8 kB). View file
|
|
auth/key.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import firebase_admin
|
2 |
+
from firebase_admin import credentials
|
3 |
+
from firebase_admin import db
|
4 |
+
|
5 |
+
# Initialize Firebase Admin with your service account credentials
|
6 |
+
cred = credentials.Certificate('service.json')
|
7 |
+
firebase_admin.initialize_app(cred, {
|
8 |
+
'databaseURL': 'https://chipling-ai-default-rtdb.firebaseio.com'
|
9 |
+
})
|
10 |
+
|
11 |
+
db = firebase_admin.db
|
12 |
+
|
13 |
+
class NimbusAuthKey:
|
14 |
+
"""
|
15 |
+
Nimbus Authentication Key
|
16 |
+
"""
|
17 |
+
|
18 |
+
def __init__(self):
|
19 |
+
self.name = "Nimbus"
|
20 |
+
|
21 |
+
def get_user(self, key):
|
22 |
+
"""
|
23 |
+
Get user from firebase
|
24 |
+
"""
|
25 |
+
try:
|
26 |
+
database = db.reference('users')
|
27 |
+
users = database.get()
|
28 |
+
for uid, user_data in users.items():
|
29 |
+
if user_data.get('apiKey') == key:
|
30 |
+
return uid
|
31 |
+
return None
|
32 |
+
except Exception as e:
|
33 |
+
print(f"Error fetching user: {e}")
|
34 |
+
return None
|
models/__pycache__/fetch.cpython-311.pyc
CHANGED
Binary files a/models/__pycache__/fetch.cpython-311.pyc and b/models/__pycache__/fetch.cpython-311.pyc differ
|
|
models/fetch.py
CHANGED
@@ -88,7 +88,8 @@ class FetchModel:
|
|
88 |
|
89 |
return models
|
90 |
|
91 |
-
|
|
|
92 |
if id == "llama-4-maverick-17b":
|
93 |
options = ['meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8']
|
94 |
model = random.choice(options)
|
|
|
88 |
|
89 |
return models
|
90 |
|
91 |
+
@staticmethod
|
92 |
+
def select_model(id):
|
93 |
if id == "llama-4-maverick-17b":
|
94 |
options = ['meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8']
|
95 |
model = random.choice(options)
|
requirements.txt
CHANGED
@@ -6,4 +6,5 @@ uvicorn[standard]
|
|
6 |
asyncio
|
7 |
jinja2
|
8 |
aiofiles
|
9 |
-
curl_cffi
|
|
|
|
6 |
asyncio
|
7 |
jinja2
|
8 |
aiofiles
|
9 |
+
curl_cffi
|
10 |
+
firebase_admin
|
service.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"type": "service_account",
|
3 |
+
"project_id": "chipling-ai",
|
4 |
+
"private_key_id": "6c56f07bba642ced936f7216c7717fcab58559f0",
|
5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDN1P+8NdngIjvz\nQ31rBRhbkQ3kvWIX2ZsrvaGiYekhH7bk/Rp4dTfBphNsVPvY5BSH+2dIZKimuQsw\nd0p6tAkmk6bgEd+bGPYU4imIw8l7LC2wZxBUuwoCE+Ml5iynweUE2ieQ+hWoDuyo\nqavW0CuIRvnIRAtK1iVAW4rQmoqrQQZlpdE7IcM9NFYWBxhoSLYfEg+j3USEH8ua\nBmqYhrw88FrMJ5dJOs/7/FJZV0H6YWq3P2fUOYRijWcDAJgyHIep98g4G/CbKkLC\n0M6+1aZDY3RnLHMTssi29sVCNk1zT9Leuf1XDfYxvumpgRh9SsOMlz5v61AFKRPZ\nUL4avgWLAgMBAAECggEAHfeMUhUPBvxE+SpSyLGBtdcdDDfsX6eNWWVu8mrJ28o3\nwQf+ghoix31L56JJ1m6CdLfL9jS9fySCtggwHkQ27thhW88OXJDaRvkUbfZ/T4ED\nl+KxdHyUvO+zSvHDf5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2MDRXfZHuPlrclUgyxNnw/hlBv\nt5uekXqtlSgVg62Wi5uHbM/p\n-----END PRIVATE KEY-----\n",
|
6 |
+
"client_email": "firebase-adminsdk-lriov@chipling-ai.iam.gserviceaccount.com",
|
7 |
+
"client_id": "109109130764194254680",
|
8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-lriov%40chipling-ai.iam.gserviceaccount.com",
|
12 |
+
"universe_domain": "googleapis.com"
|
13 |
+
}
|
test2.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
|
4 |
+
messages = [
|
5 |
+
{"role": "user", "content": "helo"},
|
6 |
+
{"role": "assistant", "content": "Hello! How can I assist you today?"},
|
7 |
+
{"role": "user", "content": "who are you and give me a breif description of who created you "}
|
8 |
+
]
|
9 |
+
|
10 |
+
model = "llama-4-scout-17b"
|
11 |
+
|
12 |
+
url = "http://127.0.0.1:8000/api/v1/text/generate"
|
13 |
+
|
14 |
+
payload = {
|
15 |
+
"messages": messages,
|
16 |
+
"model": model,
|
17 |
+
"api_key": ""
|
18 |
+
}
|
19 |
+
|
20 |
+
response = requests.post(url, json=payload, stream=True)
|
21 |
+
|
22 |
+
if response.status_code == 200:
|
23 |
+
for line in response.iter_lines():
|
24 |
+
if line:
|
25 |
+
print(line)
|
26 |
+
decoded_line = line.decode('utf-8')
|
27 |
+
if decoded_line.startswith('data: [DONE]'):
|
28 |
+
break
|
29 |
+
elif decoded_line.startswith('data: '):
|
30 |
+
try:
|
31 |
+
json_data = json.loads(decoded_line[6:])
|
32 |
+
if json_data["choices"] and "text" in json_data["choices"][0]:
|
33 |
+
print(json_data["choices"][0]["text"], end='')
|
34 |
+
except json.JSONDecodeError:
|
35 |
+
continue
|
36 |
+
else:
|
37 |
+
print(f"Request failed with status code {response.status_code}")
|