diff --git a/api/main.py b/api/main.py index a672335..f224550 100644 --- a/api/main.py +++ b/api/main.py @@ -14,10 +14,6 @@ from fastapi.middleware.cors import CORSMiddleware from slowapi.util import get_remote_address from slowapi import Limiter, _rate_limit_exceeded_handler -from helpers import network - -# - import core import handler diff --git a/api/proxies.py b/api/proxies.py index a8aad69..6b9568a 100644 --- a/api/proxies.py +++ b/api/proxies.py @@ -37,18 +37,20 @@ class Proxy: url = url.split('://')[1] if '@' in url: - username = url.split('@')[1].split(':')[0] - password = url.split('@')[1].split(':')[1] + username = url.split('@')[0].split(':')[0] + password = url.split('@')[0].split(':')[1] - host_or_ip = url.split(':')[0] - port = url.split(':')[1] + host_or_ip = url.split('@')[-1].split(':')[0] + port = int(url.split('@')[-1].split(':')[1]) self.proxy_type = proxy_type self.host_or_ip = host_or_ip + 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 @@ -64,17 +66,6 @@ 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): """ @@ -128,8 +119,6 @@ def get_proxy() -> Proxy: 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 @@ -143,4 +132,3 @@ def get_proxy() -> Proxy: if __name__ == '__main__': print(get_proxy().url) - print(get_proxy().connector) diff --git a/api/responder.py b/api/responder.py index 02cb980..3933afe 100644 --- a/api/responder.py +++ b/api/responder.py @@ -46,7 +46,7 @@ async def respond( 'Content-Type': 'application/json' } - for _ in range(20): + for _ in range(10): # 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.3, + connect=1.0, total=float(os.getenv('TRANSFER_TIMEOUT', '500')) ), ) as response: @@ -110,7 +110,6 @@ async def respond( case 'invalid_api_key': await key_validation.log_rated_key(key) print('[!] invalid key', key) - pass case _: print('[!] unknown error with key: ', key, error) @@ -127,6 +126,7 @@ async def respond( json_response = data else: + print('[!] error', data) continue @@ -140,6 +140,7 @@ async def respond( async for chunk in response.content.iter_any(): chunk = chunk.decode('utf8').strip() + print(1) yield chunk + '\n\n' break @@ -148,11 +149,7 @@ async def respond( print('[!] exception', exc) continue - if (not json_response) and is_chat: - print('[!] chat response is empty') - continue else: - print('[!] no response') 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