mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-26 00:13:57 +01:00
Compare commits
No commits in common. "15f98d8da84da58a1caa2652a61b8decbd1d1056" and "bea0cecdd338dfd2370d412c6ccb791139a56fe9" have entirely different histories.
15f98d8da8
...
bea0cecdd3
31
.github/workflows/tests.yml
vendored
31
.github/workflows/tests.yml
vendored
|
@ -1,31 +0,0 @@
|
||||||
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
|
|
|
@ -36,7 +36,7 @@ Returns True if the message violates the policy, False otherwise.
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
async with aiohttp.ClientSession(connector=proxies.get_proxy().connector) as session:
|
async with aiohttp.ClientSession(connector=proxies.default_proxy.connector) as session:
|
||||||
try:
|
try:
|
||||||
async with session.request(
|
async with session.request(
|
||||||
method=req.get('method', 'POST'),
|
method=req.get('method', 'POST'),
|
||||||
|
|
|
@ -103,6 +103,60 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
@ -116,3 +170,10 @@ 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()))
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
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
|
|
|
@ -64,8 +64,6 @@ 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():
|
||||||
|
|
Loading…
Reference in a new issue