Spaces:
Running
Running
Upload 3 files
Browse files- main.py +42 -29
- models.py +3 -1
- requirements.txt +2 -1
main.py
CHANGED
@@ -69,9 +69,8 @@ from RyuzakiLib.mental import BadWordsList
|
|
69 |
from RyuzakiLib.system import OpenReadSystem
|
70 |
|
71 |
from bardapi import Bard
|
72 |
-
|
73 |
from models import *
|
74 |
-
|
75 |
from gpytranslate import SyncTranslator
|
76 |
|
77 |
import logging
|
@@ -117,6 +116,8 @@ collection = db["users"]
|
|
117 |
|
118 |
trans = SyncTranslator()
|
119 |
|
|
|
|
|
120 |
app = FastAPI(docs_url=None, redoc_url="/")
|
121 |
|
122 |
def get_all_api_keys():
|
@@ -177,7 +178,7 @@ def get_sibyl_system_banned(user_id):
|
|
177 |
sibyl_user_id = user.get("sibyl_userid")
|
178 |
return sibyl_name, reason, is_banned, date_joined, sibyl_user_id
|
179 |
else:
|
180 |
-
return None
|
181 |
|
182 |
def get_all_banned():
|
183 |
banned_users = []
|
@@ -764,38 +765,50 @@ def gemini_pro(
|
|
764 |
item: GeminiPro,
|
765 |
api_key: None = Depends(validate_api_key)
|
766 |
):
|
767 |
-
|
768 |
-
token = item.bard_api_key
|
769 |
-
else:
|
770 |
-
token = COOKIE_BARD_TOKEN
|
771 |
owner_base = f"""
|
772 |
Your name is Randy Dev. A kind and friendly AI assistant that answers in
|
773 |
a short and concise answer. Give short step-by-step reasoning if required.
|
774 |
|
775 |
Today is {dt.now():%A %d %B %Y %H:%M}
|
776 |
"""
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
"
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
795 |
}
|
796 |
-
|
797 |
-
|
798 |
-
|
|
|
|
|
|
|
|
|
799 |
|
800 |
@app.post("/ryuzaki/v1beta2-google-ai", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
801 |
def v1beta2_google_ai(
|
@@ -1340,7 +1353,7 @@ def custom_openapi():
|
|
1340 |
return app.openapi_schema
|
1341 |
openapi_schema = get_openapi(
|
1342 |
title="RyuzakiLib API",
|
1343 |
-
version="2.
|
1344 |
summary="Use It Only For Personal Project Else I Need To Delete The Api",
|
1345 |
description=description,
|
1346 |
routes=app.routes,
|
|
|
69 |
from RyuzakiLib.system import OpenReadSystem
|
70 |
|
71 |
from bardapi import Bard
|
72 |
+
import google.generativeai as genai
|
73 |
from models import *
|
|
|
74 |
from gpytranslate import SyncTranslator
|
75 |
|
76 |
import logging
|
|
|
116 |
|
117 |
trans = SyncTranslator()
|
118 |
|
119 |
+
genai.configure(api_key=ASSISTANT_GOOGLE_API_KEYS)
|
120 |
+
|
121 |
app = FastAPI(docs_url=None, redoc_url="/")
|
122 |
|
123 |
def get_all_api_keys():
|
|
|
178 |
sibyl_user_id = user.get("sibyl_userid")
|
179 |
return sibyl_name, reason, is_banned, date_joined, sibyl_user_id
|
180 |
else:
|
181 |
+
return None
|
182 |
|
183 |
def get_all_banned():
|
184 |
banned_users = []
|
|
|
765 |
item: GeminiPro,
|
766 |
api_key: None = Depends(validate_api_key)
|
767 |
):
|
768 |
+
global item.multi_chat_messages
|
|
|
|
|
|
|
769 |
owner_base = f"""
|
770 |
Your name is Randy Dev. A kind and friendly AI assistant that answers in
|
771 |
a short and concise answer. Give short step-by-step reasoning if required.
|
772 |
|
773 |
Today is {dt.now():%A %d %B %Y %H:%M}
|
774 |
"""
|
775 |
+
if item.is_multi_chat:
|
776 |
+
try:
|
777 |
+
item.multi_chat_messages.append({"role": "user", "parts": [item.query]})
|
778 |
+
model = genai.GenerativeModel("gemini-pro")
|
779 |
+
response_genai = model.generate_content(item.multi_chat_messages)
|
780 |
+
item.multi_chat_messages.append({"role": "model", "parts": [response_genai.text]})
|
781 |
+
return SuccessResponse(
|
782 |
+
status="True",
|
783 |
+
randydev={
|
784 |
+
"message": response_genai.text,
|
785 |
+
"chat_history": item.multi_chat_messages
|
786 |
+
}
|
787 |
+
)
|
788 |
+
except:
|
789 |
+
return SuccessResponse(status="False", randydev={"message": "Error not responding"})
|
790 |
+
else:
|
791 |
+
if item.is_login:
|
792 |
+
token = item.bard_api_key
|
793 |
+
else:
|
794 |
+
token = COOKIE_BARD_TOKEN
|
795 |
+
try:
|
796 |
+
session = requests.Session()
|
797 |
+
session.headers = {
|
798 |
+
"Host": "bard.google.com",
|
799 |
+
"X-Same-Domain": "1",
|
800 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
|
801 |
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
802 |
+
"Origin": "https://bard.google.com",
|
803 |
+
"Referer": "https://bard.google.com/"
|
804 |
}
|
805 |
+
session.cookies.set("__Secure-1PSID", token)
|
806 |
+
bard = Bard(token=token, session=session, timeout=30)
|
807 |
+
bard.get_answer(owner_base)["content"]
|
808 |
+
message = bard.get_answer(item.query)["content"]
|
809 |
+
return SuccessResponse(status="True", randydev={"message": message})
|
810 |
+
except:
|
811 |
+
return SuccessResponse(status="False", randydev={"message": "Error not responding"})
|
812 |
|
813 |
@app.post("/ryuzaki/v1beta2-google-ai", response_model=SuccessResponse, responses={422: {"model": ErrorStatus}})
|
814 |
def v1beta2_google_ai(
|
|
|
1353 |
return app.openapi_schema
|
1354 |
openapi_schema = get_openapi(
|
1355 |
title="RyuzakiLib API",
|
1356 |
+
version="2.3.0",
|
1357 |
summary="Use It Only For Personal Project Else I Need To Delete The Api",
|
1358 |
description=description,
|
1359 |
routes=app.routes,
|
models.py
CHANGED
@@ -71,8 +71,10 @@ class ChatgptCustom(BaseModel):
|
|
71 |
|
72 |
class GeminiPro(BaseModel):
|
73 |
query: str
|
|
|
74 |
bard_api_key: Optional[str] = None
|
75 |
-
is_login: bool=False
|
|
|
76 |
|
77 |
class WaifuPics(BaseModel):
|
78 |
types: str="sfw"
|
|
|
71 |
|
72 |
class GeminiPro(BaseModel):
|
73 |
query: str
|
74 |
+
multi_chat_messages: Optional[list] = []
|
75 |
bard_api_key: Optional[str] = None
|
76 |
+
is_login: Optional[bool] = False
|
77 |
+
is_multi_chat: Optional[bool] = False
|
78 |
|
79 |
class WaifuPics(BaseModel):
|
80 |
types: str="sfw"
|
requirements.txt
CHANGED
@@ -26,4 +26,5 @@ uvloop
|
|
26 |
stripe
|
27 |
bardapi
|
28 |
transformers
|
29 |
-
g4f
|
|
|
|
26 |
stripe
|
27 |
bardapi
|
28 |
transformers
|
29 |
+
g4f
|
30 |
+
google-generativeai
|