Compare commits

..

6 commits

Author SHA1 Message Date
Game_Time 15f98d8da8
let pip handle this shit 2023-08-13 06:48:13 +05:00
Game_Time 251be4f6e5
Create tests.yml 2023-08-13 06:23:59 +05:00
Game_Time 5f13f9b222
Merge pull request #10 from NovaOSS/dependabot/pip/setuptools-65.5.1
Bump setuptools from 49.2.1 to 65.5.1
2023-08-13 06:17:04 +05:00
dependabot[bot] 751ab940b9
Bump setuptools from 49.2.1 to 65.5.1
Bumps [setuptools](https://github.com/pypa/setuptools) from 49.2.1 to 65.5.1.
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](https://github.com/pypa/setuptools/compare/v49.2.1...v65.5.1)

---
updated-dependencies:
- dependency-name: setuptools
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-13 01:16:09 +00:00
Game_Time 4b02125574
add requirements.txt since it wasnt here idk 🤷 2023-08-13 06:15:46 +05:00
nsde a9f817b05e Removed unused proxy tests and fixed moderation proxy 2023-08-13 00:59:54 +02:00
5 changed files with 52 additions and 62 deletions

31
.github/workflows/tests.yml vendored Normal file
View file

@ -0,0 +1,31 @@
name: Python Tests
on: [pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Start API server
run: |
python run
- name: Wait for API server to start
run: sleep 10 # We can adjust this sleep duration as needed. idk how long the server takes to start
- name: Run tests
run: python tests

View file

@ -36,7 +36,7 @@ Returns True if the message violates the policy, False otherwise.
} }
) )
async with aiohttp.ClientSession(connector=proxies.default_proxy.connector) as session: async with aiohttp.ClientSession(connector=proxies.get_proxy().connector) as session:
try: try:
async with session.request( async with session.request(
method=req.get('method', 'POST'), method=req.get('method', 'POST'),

View file

@ -103,60 +103,6 @@ class ProxyLists:
self.get_random = Proxy(url=random_proxy) self.get_random = Proxy(url=random_proxy)
self.connector = aiohttp_socks.ChainProxyConnector.from_urls(proxies_in_files) self.connector = aiohttp_socks.ChainProxyConnector.from_urls(proxies_in_files)
# ================================================================================================================================ #
# Proxy tests
# Can be useful if you want to troubleshoot your proxies
def test_httpx_workaround():
import httpx
print(default_proxy.proxies)
# this workaround solves the RNDS issue, but fails for Cloudflare protected websites
with httpx.Client(proxies=default_proxy.proxies, headers={'Host': 'checkip.amazonaws.com'}) as client:
return client.get(
f'http://{socket.gethostbyname("checkip.amazonaws.com")}/',
).text.strip()
def test_requests():
import requests
print(default_proxy.proxies)
return requests.get(
timeout=5,
url='https://checkip.amazonaws.com/',
proxies=default_proxy.urls
).text.strip()
async def test_aiohttp_socks():
async with aiohttp.ClientSession(connector=default_proxy.connector) as session:
async with session.get('https://checkip.amazonaws.com/') as response:
html = await response.text()
return html.strip()
async def streaming_aiohttp_socks():
async with aiohttp.ClientSession(connector=default_proxy.connector) as session:
async with session.get('https://httpbin.org/get', headers={
'Authorization': 'x'
}) as response:
json = await response.json()
return json
async def text_httpx_socks():
import httpx
from httpx_socks import AsyncProxyTransport
print(default_proxy.url_ip)
transport = AsyncProxyTransport.from_url(default_proxy.url_ip)
async with httpx.AsyncClient(transport=transport) as client:
res = await client.get('https://checkip.amazonaws.com')
return res.text
# ================================================================================================================================ #
def get_proxy() -> Proxy: def get_proxy() -> Proxy:
"""Returns a Proxy object. The proxy is either from the proxy list or from the environment variables. """Returns a Proxy object. The proxy is either from the proxy list or from the environment variables.
""" """
@ -170,10 +116,3 @@ def get_proxy() -> Proxy:
username=os.getenv('PROXY_USER'), username=os.getenv('PROXY_USER'),
password=os.getenv('PROXY_PASS') password=os.getenv('PROXY_PASS')
) )
if __name__ == '__main__':
# print(test_httpx())
# print(test_requests())
# print(asyncio.run(test_aiohttp_socks()))
print(asyncio.run(streaming_aiohttp_socks()))
# print(asyncio.run(text_httpx_socks()))

18
requirements.txt Normal file
View file

@ -0,0 +1,18 @@
aiohttp==3.8.5
aiohttp_socks==0.8.0
dhooks==1.1.4
fastapi==0.101.0
httpx==0.24.1
motor==3.2.0
openai==0.27.8
providers==0.0.2
pydantic==2.1.1
pymongo==4.4.1
python-dotenv==1.0.0
python_socks==2.3.0
pytz==2023.3
PyYAML==6.0.1
rich==13.5.2
setuptools==65.5.1
starlette
tiktoken==0.4.0

View file

@ -64,6 +64,8 @@ def test_library():
messages=MESSAGES messages=MESSAGES
) )
print(completion)
return completion['choices'][0]['message']['content'] return completion['choices'][0]['message']['content']
def test_library_moderation(): def test_library_moderation():