diff --git a/.gitignore b/.gitignore index 5d3ade6..1084296 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,20 @@ -*.zip +# Environments +# !!! KEEP THESE ENTRIES AT THE TOP OF THIS FILE BECAUSE THEY CONTAIN THE MOST SENSITIVE DATA !!! +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +env.old/ +.prod.env +# !!! KEEP THESE ENTRIES AT THE TOP OF THIS FILE BECAUSE THEY CONTAIN THE MOST SENSITIVE DATA !!! +rate_limited_keys.json last_update.txt +*.zip *.log.json /logs /log @@ -142,15 +155,6 @@ celerybeat.pid # SageMath parsed files *.sage.py -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - # Spyder project settings .spyderproject .spyproject @@ -183,4 +187,5 @@ cython_debug/ .idea/ backups/ -cache/ \ No newline at end of file +cache/ +api/cache/rate_limited_keys.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 30a4f57..bfdaf09 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "**/.DS_Store": true, "**/Thumbs.db": true, "**/__pycache__": true, + "**/*.css.map": true, "**/.vscode": true, "**/*.map": true, "tests/__pycache__": true diff --git a/PUSH_TO_PRODUCTION.sh b/PUSH_TO_PRODUCTION.sh index e0f699c..249faaf 100755 --- a/PUSH_TO_PRODUCTION.sh +++ b/PUSH_TO_PRODUCTION.sh @@ -22,4 +22,4 @@ cp env/.prod.env /home/nova-prod/.env cd /home/nova-prod # Start screen -screen -S nova-api python run prod && sleep 5 +screen -L -S nova-api python run prod && sleep 5 diff --git a/README.md b/README.md index a4fa4b5..fb68bd5 100644 --- a/README.md +++ b/README.md @@ -125,14 +125,45 @@ Set up a MongoDB database and set `MONGO_URI` to the MongoDB database connection Want to use a proxy list? See the according section! Keep in mind to set `USE_PROXY_LIST` to `True`! Otherwise, the proxy list won't be used. -### `ACTUAL_IPS` (optional) +### Proxy Lists +To use proxy lists, navigate to `api/secret/proxies/` and create the following files: +- `http.txt` +- `socks4.txt` +- `socks5.txt` + +Then, paste your proxies in the following format: + +``` +[username:password@]host:port +``` +Whereas anything inside of `[]` is optional and the host can be an IP address or a hostname. Always specify the port. + +If you're using [iproyal.com](https://iproyal.com?r=307932)affiliate link, follow the following steps: +- Order any type of proxy or proxies +- In the *Product Info* tab: + - set *Select port* to `SOCKS5` + - and *Select format* to `USER:PASS@IP:PORT` + +#### Proxy List Examples +``` +1.2.3.4:8080 +user:pass@127.0.0.1:1337 +aaaaaaaaaaaaa:bbbbbbbbbb@1.2.3.4:5555 +``` + +In the proxy credential files, can use comments just like in Python. + +**Important:** to activate the proxy lists, you need to change the `USE_PROXY_LIST` environment variable to `True`! + + +### ~~`ACTUAL_IPS` (optional)~~ (deprecated, might come back in the future) This is a security measure to make sure a proxy, VPN, Tor or any other IP hiding service is used by the host when accessing "Closed"AI's API. It is a space separated list of IP addresses that are allowed to access the API. You can also just add the *beginning* of an API address, like `12.123.` (without an asterisk!) to allow all IPs starting with `12.123.`. > To disable the warning if you don't have this feature enabled, set `ACTUAL_IPS` to `None`. ### Timeout -`TRANSFER_TIMEOUT` seconds to wait until the program throws an exception for if the request takes too long. We recommend rather long times like `120` for two minutes. +`TRANSFER_TIMEOUT` seconds to wait until the program throws an exception for if the request takes too long. We recommend rather long times like `500` for 500 seconds. ### Core Keys `CORE_API_KEY` specifies the **very secret key** for which need to access the entire user database etc. @@ -145,29 +176,6 @@ You can also just add the *beginning* of an API address, like `12.123.` (without ### Other `KEYGEN_INFIX` can be almost any string (avoid spaces or special characters) - this string will be put in the middle of every NovaAI API key which is generated. This is useful for identifying the source of the key using e.g. RegEx. -## Proxy Lists -To use proxy lists, navigate to `api/secret/proxies/` and create the following files: -- `http.txt` -- `socks4.txt` -- `socks5.txt` - -Then, paste your proxies in the following format: - -``` -[username:password@]host:port -``` - -e.g. - -``` -1.2.3.4:8080 -user:pass@127.0.0.1:1337 -``` - -You can use comments just like in Python. - -**Important:** to use the proxy lists, you need to change the `USE_PROXY_LIST` environment variable to `True`! - ## Run > **Warning:** read the according section for production usage! @@ -186,17 +194,20 @@ python run 1337 ``` ## Adding a provider +To be documented!] -## Test if it works +## Run tests +Make sure the API server is running on the port you specified and run: `python checks` -## Ports +## Default Ports ```yml -2332: Developement (default) +2332: Developement 2333: Production ``` ## Production + Make sure your server is secure and up to date. Check everything. diff --git a/api/cache/crypto_prices.json b/api/cache/crypto_prices.json deleted file mode 100644 index dc837a9..0000000 --- a/api/cache/crypto_prices.json +++ /dev/null @@ -1 +0,0 @@ -{"LTC": 64.665, "_last_updated": 1695334741.4905503, "BTC": 26583.485, "MATIC": 0.52075, "XMR": 146.46058828041404, "ADA": 0.2455, "USDT": 1.000005, "ETH": 1586.115, "USD": 1.0, "EUR": 1.0662838016640013} \ No newline at end of file diff --git a/api/cache/models.json b/api/cache/models.json deleted file mode 100644 index a68878c..0000000 --- a/api/cache/models.json +++ /dev/null @@ -1,1709 +0,0 @@ -{ - "object": "list", - "data": [ - { - "id": "text-davinci-001", - "object": "model", - "created": 1649364042, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-CDlahk1RbkghXDjtxqzXoPNo", - "object": "model_permission", - "created": 1690913868, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-davinci-001", - "parent": null - }, - { - "id": "text-search-curie-query-001", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-fNgpMH6ZEQulSq1CjzlfQuIe", - "object": "model_permission", - "created": 1690864192, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-search-curie-query-001", - "parent": null - }, - { - "id": "gpt-3.5-turbo", - "object": "model", - "created": 1677610602, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-aRL68Vu37kh2Z0wi2tmPhGZT", - "object": "model_permission", - "created": 1692458060, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-3.5-turbo", - "parent": null - }, - { - "id": "davinci", - "object": "model", - "created": 1649359874, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-8s5tCuiXSr3zT00nLwZGyMpS", - "object": "model_permission", - "created": 1690930152, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "davinci", - "parent": null - }, - { - "id": "gpt-3.5-turbo-0613", - "object": "model", - "created": 1686587434, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-pgz6Bp5e90wX6lXRwF6SaqeZ", - "object": "model_permission", - "created": 1692458062, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-3.5-turbo-0613", - "parent": null - }, - { - "id": "babbage", - "object": "model", - "created": 1649358449, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-h574xGeqWyBeFDDKaoVTC4CO", - "object": "model_permission", - "created": 1692394129, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "babbage", - "parent": null - }, - { - "id": "text-babbage-001", - "object": "model", - "created": 1649364043, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-YABzYWjC1kS6M2BnI6Fr9vuS", - "object": "model_permission", - "created": 1690913878, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-babbage-001", - "parent": null - }, - { - "id": "curie-instruct-beta", - "object": "model", - "created": 1649364042, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-4GYfzAdSMcJmQvF7bsw01UWw", - "object": "model_permission", - "created": 1690863785, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "curie-instruct-beta", - "parent": null - }, - { - "id": "text-davinci-003", - "object": "model", - "created": 1669599635, - "owned_by": "openai-internal", - "permission": [ - { - "id": "modelperm-fTR6rjcTAYYKKqzDu6U8ht6h", - "object": "model_permission", - "created": 1692374815, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-davinci-003", - "parent": null - }, - { - "id": "davinci-similarity", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-XHJ9P2cvfDAl6Q6NABs6wD7G", - "object": "model_permission", - "created": 1690864520, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "davinci-similarity", - "parent": null - }, - { - "id": "code-davinci-edit-001", - "object": "model", - "created": 1649880484, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-T8Ie7SvlPyvtsDvPlfC8DftZ", - "object": "model_permission", - "created": 1690915089, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "code-davinci-edit-001", - "parent": null - }, - { - "id": "text-similarity-curie-001", - "object": "model", - "created": 1651172507, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-ZQZGhVQCQSN4WC1wRJsFZfRL", - "object": "model_permission", - "created": 1690864230, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-similarity-curie-001", - "parent": null - }, - { - "id": "ada-code-search-text", - "object": "model", - "created": 1651172510, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-jWFKGhnNYXhMIJuYYBe8zKoH", - "object": "model_permission", - "created": 1690864242, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "ada-code-search-text", - "parent": null - }, - { - "id": "text-search-ada-query-001", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-YO36k119sJYqPB8yHh737z8l", - "object": "model_permission", - "created": 1690864529, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-search-ada-query-001", - "parent": null - }, - { - "id": "gpt-3.5-turbo-16k-0613", - "object": "model", - "created": 1685474247, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-hb67ObpoaFIKTieIMs9CqZPq", - "object": "model_permission", - "created": 1692458644, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-3.5-turbo-16k-0613", - "parent": null - }, - { - "id": "gpt-4-0314", - "object": "model", - "created": 1687882410, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-q9tcAQ9XhBjWdyxhWgFDYPaj", - "object": "model_permission", - "created": 1691139822, - "allow_create_engine": false, - "allow_sampling": false, - "allow_logprobs": false, - "allow_search_indices": false, - "allow_view": false, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-4-0314", - "parent": null - }, - { - "id": "babbage-search-query", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-o5hcKERXLlTSB0nfq8fPkAzK", - "object": "model_permission", - "created": 1690864257, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "babbage-search-query", - "parent": null - }, - { - "id": "ada-similarity", - "object": "model", - "created": 1651172507, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-Tz8CgePTpeDdl0q0mDxAseS4", - "object": "model_permission", - "created": 1690864543, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "ada-similarity", - "parent": null - }, - { - "id": "text-curie-001", - "object": "model", - "created": 1649364043, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-epkpKCMZ4ezExtQH69gwuIVE", - "object": "model_permission", - "created": 1692389420, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-curie-001", - "parent": null - }, - { - "id": "gpt-3.5-turbo-16k", - "object": "model", - "created": 1683758102, - "owned_by": "openai-internal", - "permission": [ - { - "id": "modelperm-BPjHua9GyiXIbj7F0M6c4j0A", - "object": "model_permission", - "created": 1692458652, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-3.5-turbo-16k", - "parent": null - }, - { - "id": "text-search-ada-doc-001", - "object": "model", - "created": 1651172507, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-WQoo7GOoaleCrrerQ8ROIejy", - "object": "model_permission", - "created": 1690864068, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-search-ada-doc-001", - "parent": null - }, - { - "id": "text-search-babbage-query-001", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-PHk5XyJIMEk88v14M2eEcJfE", - "object": "model_permission", - "created": 1690864079, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-search-babbage-query-001", - "parent": null - }, - { - "id": "code-search-ada-code-001", - "object": "model", - "created": 1651172507, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-lPJ8tQWzTuRpZpOjtRN4CjlP", - "object": "model_permission", - "created": 1690864269, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "code-search-ada-code-001", - "parent": null - }, - { - "id": "curie-search-document", - "object": "model", - "created": 1651172508, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-o3nt5yDhE7FpA8PtMlzGuW3k", - "object": "model_permission", - "created": 1690864552, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "curie-search-document", - "parent": null - }, - { - "id": "text-search-davinci-query-001", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-X2U9yi1RKudh1hGQ9CnPth2A", - "object": "model_permission", - "created": 1690864090, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-search-davinci-query-001", - "parent": null - }, - { - "id": "text-search-curie-doc-001", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-7mOkCIwOIehlltLDPM1oSKN7", - "object": "model_permission", - "created": 1690864279, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-search-curie-doc-001", - "parent": null - }, - { - "id": "babbage-search-document", - "object": "model", - "created": 1651172510, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-FQiAIZXWHZ4yJl6b4X0JWpfw", - "object": "model_permission", - "created": 1690864561, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "babbage-search-document", - "parent": null - }, - { - "id": "gpt-4-32k-0314", - "object": "model", - "created": 1687979321, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-lLwi9dsP7ZoboO1MHIJrIUSq", - "object": "model_permission", - "created": 1692399181, - "allow_create_engine": false, - "allow_sampling": false, - "allow_logprobs": false, - "allow_search_indices": false, - "allow_view": false, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-4-32k-0314", - "parent": null - }, - { - "id": "babbage-code-search-text", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-9AyTgRlbDLetEnvXKDgJvSvR", - "object": "model_permission", - "created": 1690864101, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "babbage-code-search-text", - "parent": null - }, - { - "id": "text-embedding-ada-002", - "object": "model", - "created": 1671217299, - "owned_by": "openai-internal", - "permission": [ - { - "id": "modelperm-6xIVIGILGxg9gTVWY0SpzkFn", - "object": "model_permission", - "created": 1692313508, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-embedding-ada-002", - "parent": null - }, - { - "id": "davinci-instruct-beta", - "object": "model", - "created": 1649364042, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-ZNpXjNy0lDniBWzpvi6w6wSU", - "object": "model_permission", - "created": 1690842588, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "davinci-instruct-beta", - "parent": null - }, - { - "id": "davinci-search-query", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-w5yjX7u1Hgz0jJFhPRB93n6I", - "object": "model_permission", - "created": 1690864112, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "davinci-search-query", - "parent": null - }, - { - "id": "text-similarity-babbage-001", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-8p0vOyyD6xVDYv6XOC4EYIin", - "object": "model_permission", - "created": 1690864583, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-similarity-babbage-001", - "parent": null - }, - { - "id": "text-davinci-002", - "object": "model", - "created": 1649880484, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-Ao62Dd2uu76ec6Koq1ksR2rj", - "object": "model_permission", - "created": 1690864376, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-davinci-002", - "parent": null - }, - { - "id": "code-search-babbage-text-001", - "object": "model", - "created": 1651172507, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-uH251hsudZq0DqxtTcSYFTcD", - "object": "model_permission", - "created": 1690864593, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "code-search-babbage-text-001", - "parent": null - }, - { - "id": "gpt-4-32k", - "object": "model", - "created": 1687979321, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-isyZq5njWHQyHLCf26WtwCTY", - "object": "model_permission", - "created": 1692377623, - "allow_create_engine": false, - "allow_sampling": false, - "allow_logprobs": false, - "allow_search_indices": false, - "allow_view": false, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-4-32k", - "parent": null - }, - { - "id": "text-search-davinci-doc-001", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-sqcSr7AYu6WYtzWgysHg1zO4", - "object": "model_permission", - "created": 1690864126, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-search-davinci-doc-001", - "parent": null - }, - { - "id": "code-search-ada-text-001", - "object": "model", - "created": 1651172507, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-1JbI0GFKw9luPgTJQut1uJNe", - "object": "model_permission", - "created": 1690864601, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "code-search-ada-text-001", - "parent": null - }, - { - "id": "ada-search-query", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-cBtmsjrTZIJUKgjS8G6uALKM", - "object": "model_permission", - "created": 1690864138, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "ada-search-query", - "parent": null - }, - { - "id": "text-similarity-ada-001", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-fSDlSniO72T5MvD6ieDRue0a", - "object": "model_permission", - "created": 1690864457, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-similarity-ada-001", - "parent": null - }, - { - "id": "gpt-4-32k-0613", - "object": "model", - "created": 1686614047, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-dwq8JoR7RqfTJHDVCxUe8GUB", - "object": "model_permission", - "created": 1692377639, - "allow_create_engine": false, - "allow_sampling": false, - "allow_logprobs": false, - "allow_search_indices": false, - "allow_view": false, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-4-32k-0613", - "parent": null - }, - { - "id": "ada-code-search-code", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-469coJJMBDffmGlbftht9QR7", - "object": "model_permission", - "created": 1690864147, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "ada-code-search-code", - "parent": null - }, - { - "id": "whisper-1", - "object": "model", - "created": 1677532384, - "owned_by": "openai-internal", - "permission": [ - { - "id": "modelperm-Qbzvr0DnIyt2HdaFiLj0P5h4", - "object": "model_permission", - "created": 1692314508, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "whisper-1", - "parent": null - }, - { - "id": "gpt-4", - "object": "model", - "created": 1687882411, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-cOSx57rPrEzolEUD2QSSACPS", - "object": "model_permission", - "created": 1692411452, - "allow_create_engine": false, - "allow_sampling": false, - "allow_logprobs": false, - "allow_search_indices": false, - "allow_view": false, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-4", - "parent": null - }, - { - "id": "text-davinci-edit-001", - "object": "model", - "created": 1649809179, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-bwEWUtGiBcdX0p1D1ayafH8w", - "object": "model_permission", - "created": 1690915020, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-davinci-edit-001", - "parent": null - }, - { - "id": "davinci-search-document", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-1jEFSTL1yLUnTyI8TekKPGQF", - "object": "model_permission", - "created": 1690864158, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "davinci-search-document", - "parent": null - }, - { - "id": "gpt-4-0613", - "object": "model", - "created": 1686588896, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-kZWPVNfDP5WlVYNfcopBABZB", - "object": "model_permission", - "created": 1692411496, - "allow_create_engine": false, - "allow_sampling": false, - "allow_logprobs": false, - "allow_search_indices": false, - "allow_view": false, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-4-0613", - "parent": null - }, - { - "id": "curie-search-query", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-fvYLh7mrZBoEXRa9teCq7ZsK", - "object": "model_permission", - "created": 1690864488, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "curie-search-query", - "parent": null - }, - { - "id": "babbage-similarity", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-XBmFjRKu34Qvm9Y8Vjg6si3V", - "object": "model_permission", - "created": 1690864610, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "babbage-similarity", - "parent": null - }, - { - "id": "ada", - "object": "model", - "created": 1649357491, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-gUTBN2NFYvvG3UwNeDnY6EEe", - "object": "model_permission", - "created": 1692393802, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "ada", - "parent": null - }, - { - "id": "ada-search-document", - "object": "model", - "created": 1651172507, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-jEtYYVTVutQ4BLh2DnGd9tJt", - "object": "model_permission", - "created": 1690864171, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "ada-search-document", - "parent": null - }, - { - "id": "text-ada-001", - "object": "model", - "created": 1649364042, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-jRuB7xBCdj159SqaDmpPgeWO", - "object": "model_permission", - "created": 1690915029, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-ada-001", - "parent": null - }, - { - "id": "text-similarity-davinci-001", - "object": "model", - "created": 1651172505, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-CoAjJ7mSHeO28X7KowOnwvj9", - "object": "model_permission", - "created": 1690864500, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-similarity-davinci-001", - "parent": null - }, - { - "id": "curie-similarity", - "object": "model", - "created": 1651172510, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-gSmuEPu9Q8KjQhJ5myLNKIIV", - "object": "model_permission", - "created": 1690864620, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "curie-similarity", - "parent": null - }, - { - "id": "babbage-code-search-code", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-UdNutuGVhzb5EBzlkaztBdMH", - "object": "model_permission", - "created": 1690864182, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "babbage-code-search-code", - "parent": null - }, - { - "id": "code-search-babbage-code-001", - "object": "model", - "created": 1651172507, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-0mO5qmzzKUVVVZ9MIHTnwjwK", - "object": "model_permission", - "created": 1690864510, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "code-search-babbage-code-001", - "parent": null - }, - { - "id": "text-search-babbage-doc-001", - "object": "model", - "created": 1651172509, - "owned_by": "openai-dev", - "permission": [ - { - "id": "modelperm-dvJNsLdOcnLbIYlRZRnfQAfX", - "object": "model_permission", - "created": 1690864628, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": true, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "text-search-babbage-doc-001", - "parent": null - }, - { - "id": "gpt-3.5-turbo-0301", - "object": "model", - "created": 1677649963, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-I4IcSJFYZl2fIK0DPSBkgK3d", - "object": "model_permission", - "created": 1691712139, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "gpt-3.5-turbo-0301", - "parent": null - }, - { - "id": "curie", - "object": "model", - "created": 1649359874, - "owned_by": "openai", - "permission": [ - { - "id": "modelperm-cXKYjZ0dQvxFHt2rqkdTWYCz", - "object": "model_permission", - "created": 1692392433, - "allow_create_engine": false, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": false, - "organization": "*", - "group": null, - "is_blocking": false - } - ], - "root": "curie", - "parent": null - }, - { - "id": "davinci:ft-fixie-ai:industruous-facts-2022-10-13-01-17-15", - "object": "model", - "created": 1665623835, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-qmCpjvRypiW6x5MZx8kYs6O4", - "object": "model_permission", - "created": 1665623835, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:industruous-facts-2022-10-12-23-26-28", - "object": "model", - "created": 1665617188, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-kBM7YxDdBx7y0JtMpZZnTnCY", - "object": "model_permission", - "created": 1665617188, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai-2022-09-16-18-23-16", - "object": "model", - "created": 1663352597, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-SeuOQWbIya3BNKelkdDAi4Qq", - "object": "model_permission", - "created": 1663352597, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:promptrunner-2022-11-24-01-53-01", - "object": "model", - "created": 1669254781, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-UlqCtflESCgu6wuml4ybiBTM", - "object": "model_permission", - "created": 1669254781, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:industruous-facts-2022-10-12-21-43-54", - "object": "model", - "created": 1665611034, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-U6mB4aXW3ArdSIrElC4YFqtp", - "object": "model_permission", - "created": 1665611034, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:industruous-facts-fill-tokenlength-2022-10-13-23-33-54", - "object": "model", - "created": 1665704034, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-viRUnGSfaVnkJVXamTPOrnmS", - "object": "model_permission", - "created": 1665704034, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:industruous-facts-fill-tokenlength-2022-10-14-00-23-52", - "object": "model", - "created": 1665707032, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-BD65SMak4b2EmvLXL1whg4qB", - "object": "model_permission", - "created": 1665707032, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai-2022-10-05-17-53-03", - "object": "model", - "created": 1664992384, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-PdsJulMafesbkJH2UIEyxovh", - "object": "model_permission", - "created": 1664992384, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:industruous-facts-fill-no-sample-qa-2022-10-14-01-25-25", - "object": "model", - "created": 1665710725, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-NFC2u7j45p63DTpoC9zM8R4X", - "object": "model_permission", - "created": 1665710725, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:industruous-facts-no-sample-qa-2022-10-14-03-14-08", - "object": "model", - "created": 1665717249, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-5y121LGwoIr87Xl3qYh31JSa", - "object": "model_permission", - "created": 1665717249, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:industruous-facts-no-sample-qa-2022-10-14-22-14-09", - "object": "model", - "created": 1665785649, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-mWTPRq0Qo0N1G3PDU7EZZRfU", - "object": "model_permission", - "created": 1665785649, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - }, - { - "id": "davinci:ft-fixie-ai:picard-2022-10-06-05-10-37", - "object": "model", - "created": 1665033038, - "owned_by": "fixie-ai", - "permission": [ - { - "id": "snapperm-mrAAsZbq6EKuaEcjGMIqQDzw", - "object": "model_permission", - "created": 1665033038, - "allow_create_engine": true, - "allow_sampling": true, - "allow_logprobs": true, - "allow_search_indices": false, - "allow_view": true, - "allow_fine_tuning": true, - "organization": "org-om1NsPYwZBBiNRoN36vWDTrC", - "group": null, - "is_blocking": false - } - ], - "root": "davinci:2020-05-03", - "parent": "davinci:2020-05-03" - } - ] -} \ No newline at end of file diff --git a/api/cache/rate_limited_keys.json b/api/cache/rate_limited_keys.json deleted file mode 100644 index 0637a08..0000000 --- a/api/cache/rate_limited_keys.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/api/db/key_validation.py b/api/db/key_validation.py index c1fcebf..1a7f85d 100644 --- a/api/db/key_validation.py +++ b/api/db/key_validation.py @@ -7,8 +7,8 @@ from dotenv import load_dotenv from motor.motor_asyncio import AsyncIOMotorClient load_dotenv() -MONGO_URI = os.getenv("MONGO_URI") +MONGO_URI = os.getenv('MONGO_URI') async def log_rated_key(key: str) -> None: """Logs a key that has been rate limited to the database.""" @@ -16,8 +16,8 @@ async def log_rated_key(key: str) -> None: client = AsyncIOMotorClient(MONGO_URI) scheme = { - "key": key, - "timestamp_added": int(time.time()) + 'key': key, + 'timestamp_added': int(time.time()) } collection = client['Liabilities']['rate-limited-keys'] @@ -31,7 +31,7 @@ async def key_is_rated(key: str) -> bool: collection = client['Liabilities']['rate-limited-keys'] query = { - "key": key + 'key': key } result = await collection.find_one(query) @@ -39,9 +39,9 @@ async def key_is_rated(key: str) -> bool: async def cached_key_is_rated(key: str) -> bool: - path = os.path.join(os.getcwd(), "cache", "rate_limited_keys.json") + path = os.path.join(os.getcwd(), 'cache', 'rate_limited_keys.json') - with open(path, "r") as file: + with open(path, 'r') as file: keys = json.load(file) return key in keys @@ -62,14 +62,13 @@ async def remove_rated_keys() -> None: marked_for_removal.append(key['_id']) query = { - "_id": { - "$in": marked_for_removal + '_id': { + '$in': marked_for_removal } } await collection.delete_many(query) - async def cache_all_keys() -> None: """Clones all keys from the database to the cache.""" @@ -79,8 +78,8 @@ async def cache_all_keys() -> None: keys = await collection.find().to_list(length=None) keys = [key['key'] for key in keys] - path = os.path.join(os.getcwd(), "cache", "rate_limited_keys.json") - with open(path, "w") as file: + path = os.path.join(os.getcwd(), 'cache', 'rate_limited_keys.json') + with open(path, 'w') as file: json.dump(keys, file) if __name__ == "__main__": diff --git a/api/main.py b/api/main.py index a3ed7e3..a672335 100644 --- a/api/main.py +++ b/api/main.py @@ -16,6 +16,8 @@ from slowapi import Limiter, _rate_limit_exceeded_handler from helpers import network +# + import core import handler @@ -37,7 +39,7 @@ limiter = Limiter( swallow_errors=True, key_func=get_remote_address, default_limits=[ - '2/second', + '1/second', '20/minute', '300/hour' ]) @@ -71,8 +73,8 @@ async def v1_handler(request: fastapi.Request): res = await handler.handle(incoming_request=request) return res -@limiter.limit('100/second') -@app.route('/enterprise/{path:path}', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH']) +@limiter.limit('100/minute', '1000/hour') +@app.route('/enterprise/v1/{path:path}', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH']) async def enterprise_handler(request: fastapi.Request): res = await handler.handle(incoming_request=request) return res diff --git a/api/proxies.py b/api/proxies.py index bca633f..a8aad69 100644 --- a/api/proxies.py +++ b/api/proxies.py @@ -45,7 +45,10 @@ class Proxy: self.proxy_type = proxy_type self.host_or_ip = host_or_ip - self.ip_address = socket.gethostbyname(self.host_or_ip) # get ip address from host + try: + self.ip_address = socket.gethostbyname(self.host_or_ip) # get ip address from host + except socket.gaierror: + self.ip_address = self.host_or_ip self.host = self.host_or_ip self.port = port self.username = username @@ -61,6 +64,17 @@ class Proxy: self.urls_httpx = {k + '://' :v for k, v in self.urls.items()} self.proxies = self.url + print({ + 'proxy_type': self.proxy_type, + 'host_or_ip': self.host_or_ip, + 'ip_address': self.ip_address, + 'host': self.host, + 'port': self.port, + 'username': self.username, + 'password': self.password, + 'url': self.url + }) + @property def connector(self): """ @@ -78,7 +92,7 @@ class Proxy: return aiohttp_socks.ProxyConnector( proxy_type=proxy_types[self.proxy_type], - host=self.ip_address, + host=self.host, port=self.port, rdns=False, username=self.username, @@ -89,16 +103,15 @@ class Proxy: proxies_in_files = [] -try: - for proxy_type in ['http', 'socks4', 'socks5']: +for proxy_type in ['http', 'socks4', 'socks5']: + try: with open(f'secret/proxies/{proxy_type}.txt') as f: for line in f: clean_line = line.split('#', 1)[0].strip() if clean_line: proxies_in_files.append(f'{proxy_type}://{clean_line}') - -except FileNotFoundError: - pass + except FileNotFoundError: + pass ## Manages the proxy list @@ -114,7 +127,9 @@ def get_proxy() -> Proxy: ### Returns a Proxy object The proxy is either from the proxy list or from the environment variables. """ - + + print('URL:\t' + ProxyLists().get_random.url) + if USE_PROXY_LIST: return ProxyLists().get_random diff --git a/api/responder.py b/api/responder.py index f0eb6dc..02cb980 100644 --- a/api/responder.py +++ b/api/responder.py @@ -46,7 +46,7 @@ async def respond( 'Content-Type': 'application/json' } - for i in range(20): + for _ in range(20): # Load balancing: randomly selecting a suitable provider # If the request is a chat completion, then we need to load balance between chat providers # If the request is an organic request, then we need to load balance between organic providers @@ -86,7 +86,7 @@ async def respond( cookies=target_request.get('cookies'), ssl=False, timeout=aiohttp.ClientTimeout( - connect=0.5, + connect=0.3, total=float(os.getenv('TRANSFER_TIMEOUT', '500')) ), ) as response: @@ -104,14 +104,16 @@ async def respond( pass case _: + key = target_request.get('provider_auth') + match error.get('code'): - case "insufficient_quota": - key = target_request.get('provider_auth') + case 'invalid_api_key': await key_validation.log_rated_key(key) - continue + print('[!] invalid key', key) + pass case _: - pass + print('[!] unknown error with key: ', key, error) if 'method_not_supported' in str(data): await errors.error(500, 'Sorry, this endpoint does not support this method.', data['error']['message']) @@ -124,6 +126,10 @@ async def respond( if response.ok: json_response = data + else: + continue + + if is_stream: try: response.raise_for_status() @@ -139,6 +145,7 @@ async def respond( break except Exception as exc: + print('[!] exception', exc) continue if (not json_response) and is_chat: @@ -146,7 +153,7 @@ async def respond( continue else: print('[!] no response') - yield await errors.yield_error(500, 'Sorry, the provider is not responding.', 'Please try again later.') + yield await errors.yield_error(500, 'Sorry, our API seems to have issues connecting to our provider(s).', 'This most likely isn\'t your fault. Please try again later.') return if (not is_stream) and json_response: