From 08a87552013e230bc74af9fcf08f88ba984db9b9 Mon Sep 17 00:00:00 2001 From: nsde Date: Thu, 27 Jul 2023 02:44:56 +0200 Subject: [PATCH] Netclient rewrite coming soon (hopefully?) --- README.md | 28 ++++++++++-------- api/proxies.py | 2 +- proxy_exception.txt | 64 ---------------------------------------- requirements.txt | 9 ------ {cli => run}/__main__.py | 0 session_exception.txt | 44 --------------------------- 6 files changed, 17 insertions(+), 130 deletions(-) delete mode 100644 proxy_exception.txt delete mode 100644 requirements.txt rename {cli => run}/__main__.py (100%) delete mode 100644 session_exception.txt diff --git a/README.md b/README.md index 64ef158..01b8dfd 100644 --- a/README.md +++ b/README.md @@ -27,24 +27,28 @@ pip install . ## `.env` configuration +### Proxy +- `PROXY_TYPE` (optional, defaults to `socks.PROXY_TYPE_HTTP`): the type of proxy - can be `http`, `https`, `socks4`, `socks5`, `4` or `5`, etc... +- `PROXY_HOST`: the proxy host (host domain or IP address), without port! +- `PROXY_PORT` (optional) +- `PROXY_USER` (optional) +- `PROXY_PASS` (optional) + +### ClosedAI configuration +- `CLOSEDAI_KEY`: the API key used to access the ClosedAI API +- `CLOSEDAI_ENDPOINT` (defaults to `https://api.openai.com/v1`): the API endpoint which is used for the provider ClosedAI + ### `ACTUAL_IPS` (optional) 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.` to allow all IPs starting with `12.123.`. +### `DEMO_AUTH` +API key for demo purposes. You can give this to trusted team members. Never use it in production. + > To disable the warning if you don't have this feature enabled, set `ACTUAL_IPS` to any value. - -## Proxy -- `PROXY_TYPE` (optional, defaults to `socks.PROXY_TYPE_HTTP`): the type of proxy - can be `http`, `https`, `socks4`, `socks5`, `4` or `5`, etc... -- `PROXY_HOST`: the proxy host (host domain or IP address), without port! -- `PROXY_PORT` -- `PROXY_USER` (optional) -- `PROXY_PASS` (optional) - ## Run -`python cli` +`python run` -You can remove the `--reload` flag if you don't want to reload the server on file changes. - -## Test +## Test if it works `python tests` diff --git a/api/proxies.py b/api/proxies.py index f95b95d..dd96d73 100644 --- a/api/proxies.py +++ b/api/proxies.py @@ -83,7 +83,7 @@ if __name__ == '__main__': timeout=5, proxies={ 'https': default_proxy.url - } + } ).text.strip() print(received_ip) diff --git a/proxy_exception.txt b/proxy_exception.txt deleted file mode 100644 index 3ed221b..0000000 --- a/proxy_exception.txt +++ /dev/null @@ -1,64 +0,0 @@ -Traceback (most recent call last): - File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 429, in run_asgi - result = await app( # type: ignore[func-returns-value] - File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__ - return await self.app(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 284, in __call__ - await super().__call__(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__ - await self.middleware_stack(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__ - raise exc - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__ - await self.app(scope, receive, _send) - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 83, in __call__ - await self.app(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__ - raise exc - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__ - await self.app(scope, receive, sender) - File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__ - raise e - File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__ - await self.app(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__ - await route.handle(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle - await self.app(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 69, in app - await response(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/responses.py", line 270, in __call__ - async with anyio.create_task_group() as task_group: - File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 662, in __aexit__ - raise exceptions[0] - File "/usr/local/lib/python3.10/site-packages/starlette/responses.py", line 273, in wrap - await func() - File "/usr/local/lib/python3.10/site-packages/starlette/responses.py", line 262, in stream_response - async for chunk in self.body_iterator: - File "/home/nova-api/api/transfer.py", line 62, in receive_target_stream - async with session.request( - File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in __aenter__ - self._resp = await self._coro - File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request - conn = await self._connector.connect( - File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect - proto = await self._create_connection(req, traces, timeout) - File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection - _, proto = await self._create_direct_connection(req, traces, timeout) - File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection - transp, proto = await self._wrap_create_connection( - File "/usr/local/lib/python3.10/site-packages/aiohttp_socks/connector.py", line 72, in _wrap_create_connection - stream = await proxy.connect( - File "/usr/local/lib/python3.10/site-packages/python_socks/async_/asyncio/v2/_proxy.py", line 59, in connect - return await self._connect( - File "/usr/local/lib/python3.10/site-packages/python_socks/async_/asyncio/v2/_proxy.py", line 100, in _connect - await self._negotiate( - File "/usr/local/lib/python3.10/site-packages/python_socks/async_/asyncio/v2/_proxy.py", line 164, in _negotiate - await proto.negotiate() - File "/usr/local/lib/python3.10/site-packages/python_socks/_proto/socks5_async.py", line 42, in negotiate - await self._socks_auth() - File "/usr/local/lib/python3.10/site-packages/python_socks/_proto/socks5_async.py", line 55, in _socks_auth - res.validate() - File "/usr/local/lib/python3.10/site-packages/python_socks/_proto/socks5.py", line 134, in validate - raise ProxyError('Username and password ' # pragma: no cover -python_socks._errors.ProxyError: Username and password authentication failure diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index d737da3..0000000 --- a/requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -fastapi -httpx[socks] -openai -python-dotenv -rich -starlette -win_inet_pton -aiohttp-socks -aiohttp diff --git a/cli/__main__.py b/run/__main__.py similarity index 100% rename from cli/__main__.py rename to run/__main__.py diff --git a/session_exception.txt b/session_exception.txt deleted file mode 100644 index 5669224..0000000 --- a/session_exception.txt +++ /dev/null @@ -1,44 +0,0 @@ -Traceback (most recent call last): - File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 429, in run_asgi - result = await app( # type: ignore[func-returns-value] - File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__ - return await self.app(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 284, in __call__ - await super().__call__(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__ - await self.middleware_stack(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__ - raise exc - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__ - await self.app(scope, receive, _send) - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/cors.py", line 83, in __call__ - await self.app(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__ - raise exc - File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__ - await self.app(scope, receive, sender) - File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__ - raise e - File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__ - await self.app(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__ - await route.handle(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle - await self.app(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 69, in app - await response(scope, receive, send) - File "/usr/local/lib/python3.10/site-packages/starlette/responses.py", line 270, in __call__ - async with anyio.create_task_group() as task_group: - File "/usr/local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 662, in __aexit__ - raise exceptions[0] - File "/usr/local/lib/python3.10/site-packages/starlette/responses.py", line 273, in wrap - await func() - File "/usr/local/lib/python3.10/site-packages/starlette/responses.py", line 262, in stream_response - async for chunk in self.body_iterator: - File "/home/nova-api/api/transfer.py", line 60, in receive_target_stream - async with session.request( - File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in __aenter__ - self._resp = await self._coro - File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 399, in _request - raise RuntimeError("Session is closed") -RuntimeError: Session is closed \ No newline at end of file