From f6cd1f7aa2103200571b9ed6efaff51adb792b01 Mon Sep 17 00:00:00 2001 From: nsde Date: Wed, 16 Aug 2023 15:06:16 +0200 Subject: [PATCH] Some fixes? --- api/db/logs.py | 2 +- api/db/stats.py | 2 +- api/db/users.py | 4 ++-- api/streaming.py | 5 ++++- screen.sh | 12 ++++++++++++ tests/__main__.py | 5 ++++- 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/api/db/logs.py b/api/db/logs.py index 7ecee9f..a6a4adc 100644 --- a/api/db/logs.py +++ b/api/db/logs.py @@ -21,7 +21,7 @@ UA_SIMPLIFY = { conn = AsyncIOMotorClient(os.getenv('MONGO_URI')) async def _get_collection(collection_name: str): - return conn['nova-core'][collection_name] + return conn[os.getenv('MONGO_NAME', 'nova-test')][collection_name] async def replacer(text: str, dict_: dict) -> str: # This seems to exist for a very specific and dumb purpose :D diff --git a/api/db/stats.py b/api/db/stats.py index 8e5ac93..b2edeee 100644 --- a/api/db/stats.py +++ b/api/db/stats.py @@ -26,7 +26,7 @@ class StatsManager: self.conn = AsyncIOMotorClient(os.getenv('MONGO_URI')) async def _get_collection(self, collection_name: str): - return self.conn['nova-core'][collection_name] + return self.conn[os.getenv('MONGO_NAME', 'nova-test')][collection_name] async def add_date(self): date = datetime.datetime.now(pytz.timezone('GMT')).strftime('%Y.%m.%d') diff --git a/api/db/users.py b/api/db/users.py index 6f2b862..056c399 100644 --- a/api/db/users.py +++ b/api/db/users.py @@ -33,10 +33,10 @@ class UserManager: self.conn = AsyncIOMotorClient(os.getenv('MONGO_URI')) async def _get_collection(self, collection_name: str): - return self.conn['nova-core'][collection_name] + return self.conn[os.getenv('MONGO_NAME', 'nova-test')][collection_name] async def get_all_users(self): - return self.conn['nova-core']['users'] + return self.conn[os.getenv('MONGO_NAME', 'nova-test')]['users'] async def create(self, discord_id: str = '') -> dict: chars = string.ascii_letters + string.digits diff --git a/api/streaming.py b/api/streaming.py index 7c3e9ba..5ed64cf 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -169,7 +169,10 @@ async def stream( headers=target_request.get('headers', {}), cookies=target_request.get('cookies'), ssl=False, - timeout=aiohttp.ClientTimeout(total=float(os.getenv('TRANSFER_TIMEOUT', '120'))), + timeout=aiohttp.ClientTimeout( + connect=3.0, + total=float(os.getenv('TRANSFER_TIMEOUT', '120')) + ), ) as response: if response.content_type == 'application/json': data = await response.json() diff --git a/screen.sh b/screen.sh index 7cb5b12..5f4af30 100755 --- a/screen.sh +++ b/screen.sh @@ -1 +1,13 @@ +# Script to start the production server + +# Copy files to production +cp -r * /home/nova-prod + +# Copy env file to production +cp env/.prod.env /home/nova-prod/.env + +# Change directory +cd /home/nova-prod + +# Start screen screen -S nova-api python run prod diff --git a/tests/__main__.py b/tests/__main__.py index 544a681..500ae92 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -69,7 +69,10 @@ def test_library(): return completion['choices'][0]['message']['content'] def test_library_moderation(): - return closedai.Moderation.create('I wanna kill myself, I wanna kill myself; It\'s all I hear right now, it\'s all I hear right now') + try: + return closedai.Moderation.create('I wanna kill myself, I wanna kill myself; It\'s all I hear right now, it\'s all I hear right now') + except closedai.errors.InvalidRequestError as exc: + return True def test_models(): response = httpx.get(