diff options
author | AndPim4912 <52836885+AndPim4912@users.noreply.github.com> | 2023-10-23 14:10:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-23 14:10:28 +0200 |
commit | 8d7ad98fcb314453c01f6dcd4bfe59016efd78ce (patch) | |
tree | 4d39804e1aa1724560e1688f0b6d4c124b9771c7 /g4f/Provider/Vercel.py | |
parent | Refactor API initialization to accept a list of ignored providers. (diff) | |
parent | Debug config in api (diff) | |
download | gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.gz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.bz2 gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.lz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.xz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.zst gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.zip |
Diffstat (limited to 'g4f/Provider/Vercel.py')
-rw-r--r-- | g4f/Provider/Vercel.py | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/g4f/Provider/Vercel.py b/g4f/Provider/Vercel.py index 7c3b8c55..eb5aa20a 100644 --- a/g4f/Provider/Vercel.py +++ b/g4f/Provider/Vercel.py @@ -24,30 +24,27 @@ class Vercel(BaseProvider): if not model: model = "gpt-3.5-turbo" - + elif model not in model_info: raise ValueError(f"Vercel does not support {model}") - + headers = { - 'authority' : 'sdk.vercel.ai', - 'accept' : '*/*', - 'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', - 'cache-control' : 'no-cache', - 'content-type' : 'application/json', - 'custom-encoding' : get_anti_bot_token(), - 'origin' : 'https://sdk.vercel.ai', - 'pragma' : 'no-cache', - 'referer' : 'https://sdk.vercel.ai/', - 'sec-ch-ua' : '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', - 'sec-ch-ua-mobile' : '?0', + 'authority': 'sdk.vercel.ai', + 'accept': '*/*', + 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', + 'cache-control': 'no-cache', + 'content-type': 'application/json', + 'custom-encoding': get_anti_bot_token(), + 'origin': 'https://sdk.vercel.ai', + 'pragma': 'no-cache', + 'referer': 'https://sdk.vercel.ai/', + 'sec-ch-ua': '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', + 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', - 'sec-fetch-dest' : 'empty', - 'sec-fetch-mode' : 'cors', - 'sec-fetch-site' : 'same-origin', - 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.%s.%s Safari/537.36' % ( - random.randint(99, 999), - random.randint(99, 999) - ) + 'sec-fetch-dest': 'empty', + 'sec-fetch-mode': 'cors', + 'sec-fetch-site': 'same-origin', + 'user-agent': f'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.{random.randint(99, 999)}.{random.randint(99, 999)} Safari/537.36', } json_data = { @@ -60,7 +57,7 @@ class Vercel(BaseProvider): } max_retries = kwargs.get('max_retries', 20) - for i in range(max_retries): + for _ in range(max_retries): response = requests.post('https://sdk.vercel.ai/api/generate', headers=headers, json=json_data, stream=True, proxies={"https": proxy}) try: @@ -74,22 +71,19 @@ class Vercel(BaseProvider): def get_anti_bot_token() -> str: headers = { - 'authority' : 'sdk.vercel.ai', - 'accept' : '*/*', - 'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', - 'cache-control' : 'no-cache', - 'pragma' : 'no-cache', - 'referer' : 'https://sdk.vercel.ai/', - 'sec-ch-ua' : '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', - 'sec-ch-ua-mobile' : '?0', + 'authority': 'sdk.vercel.ai', + 'accept': '*/*', + 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', + 'cache-control': 'no-cache', + 'pragma': 'no-cache', + 'referer': 'https://sdk.vercel.ai/', + 'sec-ch-ua': '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', + 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', - 'sec-fetch-dest' : 'empty', - 'sec-fetch-mode' : 'cors', - 'sec-fetch-site' : 'same-origin', - 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.%s.%s Safari/537.36' % ( - random.randint(99, 999), - random.randint(99, 999) - ) + 'sec-fetch-dest': 'empty', + 'sec-fetch-mode': 'cors', + 'sec-fetch-site': 'same-origin', + 'user-agent': f'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.{random.randint(99, 999)}.{random.randint(99, 999)} Safari/537.36', } response = requests.get('https://sdk.vercel.ai/openai.jpeg', |