diff options
author | Bagus Indrayana <bagusindrayanaindo@gmail.com> | 2023-08-17 15:30:52 +0200 |
---|---|---|
committer | Bagus Indrayana <bagusindrayanaindo@gmail.com> | 2023-08-17 15:30:52 +0200 |
commit | 74ecdee78466104e57eb7488e682b564988fcd88 (patch) | |
tree | bbc764ba3248e80f20dde55e5b382b3f3d382575 /g4f/Provider/Providers/GetGpt.py | |
parent | add proxy and remove stream (diff) | |
parent | ~ (diff) | |
download | gpt4free-74ecdee78466104e57eb7488e682b564988fcd88.tar gpt4free-74ecdee78466104e57eb7488e682b564988fcd88.tar.gz gpt4free-74ecdee78466104e57eb7488e682b564988fcd88.tar.bz2 gpt4free-74ecdee78466104e57eb7488e682b564988fcd88.tar.lz gpt4free-74ecdee78466104e57eb7488e682b564988fcd88.tar.xz gpt4free-74ecdee78466104e57eb7488e682b564988fcd88.tar.zst gpt4free-74ecdee78466104e57eb7488e682b564988fcd88.zip |
Diffstat (limited to 'g4f/Provider/Providers/GetGpt.py')
-rw-r--r-- | g4f/Provider/Providers/GetGpt.py | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/g4f/Provider/Providers/GetGpt.py b/g4f/Provider/Providers/GetGpt.py deleted file mode 100644 index bafc0ce8..00000000 --- a/g4f/Provider/Providers/GetGpt.py +++ /dev/null @@ -1,59 +0,0 @@ -import os -import json -import uuid -import requests -from Crypto.Cipher import AES -from ...typing import sha256, Dict, get_type_hints - -url = 'https://chat.getgpt.world/' -model = ['gpt-3.5-turbo'] -supports_stream = True -needs_auth = False -working = True - - -def _create_completion(model: str, messages: list, stream: bool, **kwargs): - def encrypt(e): - t = os.urandom(8).hex().encode('utf-8') - n = os.urandom(8).hex().encode('utf-8') - r = e.encode('utf-8') - cipher = AES.new(t, AES.MODE_CBC, n) - ciphertext = cipher.encrypt(pad_data(r)) - return ciphertext.hex() + t.decode('utf-8') + n.decode('utf-8') - - def pad_data(data: bytes) -> bytes: - block_size = AES.block_size - padding_size = block_size - len(data) % block_size - padding = bytes([padding_size] * padding_size) - return data + padding - - headers = { - 'Content-Type': 'application/json', - 'Referer': 'https://chat.getgpt.world/', - 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36' - } - - data = json.dumps({ - 'messages': messages, - 'frequency_penalty': kwargs.get('frequency_penalty', 0), - 'max_tokens': kwargs.get('max_tokens', 4000), - 'model': 'gpt-3.5-turbo', - 'presence_penalty': kwargs.get('presence_penalty', 0), - 'temperature': kwargs.get('temperature', 1), - 'top_p': kwargs.get('top_p', 1), - 'stream': True, - 'uuid': str(uuid.uuid4()) - }) - - res = requests.post('https://chat.getgpt.world/api/chat/stream', - headers=headers, json={'signature': encrypt(data)}, stream=True) - - for line in res.iter_lines(): - if b'content' in line: - line_json = json.loads(line.decode('utf-8').split('data: ')[1]) - yield (line_json['choices'][0]['delta']['content']) - - -params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \ - '(%s)' % ', '.join( - [f'{name}: {get_type_hints(_create_completion)[name].__name__}' for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]]) |