diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-12-13 15:28:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-13 15:28:07 +0100 |
commit | 1acd800cc30e323712169a6a6d8e6bdc5f81a2b1 (patch) | |
tree | eec15d0247c8e176e9c69731be179125ee5db789 /g4f/Provider/deprecated/VoiGpt.py | |
parent | Merge pull request #1331 from hlohaus/proxy (diff) | |
parent | Update and rename g4f/Provider/VoiGpt.py to g4f/Provider/deprecated/VoiGpt.py (diff) | |
download | gpt4free-1acd800cc30e323712169a6a6d8e6bdc5f81a2b1.tar gpt4free-1acd800cc30e323712169a6a6d8e6bdc5f81a2b1.tar.gz gpt4free-1acd800cc30e323712169a6a6d8e6bdc5f81a2b1.tar.bz2 gpt4free-1acd800cc30e323712169a6a6d8e6bdc5f81a2b1.tar.lz gpt4free-1acd800cc30e323712169a6a6d8e6bdc5f81a2b1.tar.xz gpt4free-1acd800cc30e323712169a6a6d8e6bdc5f81a2b1.tar.zst gpt4free-1acd800cc30e323712169a6a6d8e6bdc5f81a2b1.zip |
Diffstat (limited to 'g4f/Provider/deprecated/VoiGpt.py')
-rw-r--r-- | g4f/Provider/deprecated/VoiGpt.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/g4f/Provider/deprecated/VoiGpt.py b/g4f/Provider/deprecated/VoiGpt.py new file mode 100644 index 00000000..b312709f --- /dev/null +++ b/g4f/Provider/deprecated/VoiGpt.py @@ -0,0 +1,93 @@ +from __future__ import annotations + +import json +import requests +from .base_provider import BaseProvider +from ..typing import Messages, CreateResult +from .helper import get_cookies + + + +class VoiGpt(BaseProvider): + """ + VoiGpt - A provider for VoiGpt.com + + **Note** : to use this provider you have to get your csrf token/cookie from the voigpt.com website + + Args: + model: The model to use + messages: The messages to send + stream: Whether to stream the response + proxy: The proxy to use + access_token: The access token to use + **kwargs: Additional keyword arguments + + Returns: + A CreateResult object + """ + url = "https://voigpt.com" + working = False + supports_gpt_35_turbo = True + supports_message_history = True + supports_stream = False + _access_token: str = None + + @classmethod + def create_completion( + cls, + model: str, + messages: Messages, + stream: bool, + proxy: str = None, + access_token: str = None, + **kwargs + ) -> CreateResult: + + if not model: + model = "gpt-3.5-turbo" + if not access_token: + access_token = cls._access_token + if not access_token: + headers = { + "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", + "accept-language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US;q=0.6", + "sec-ch-ua": "\"Google Chrome\";v=\"119\", \"Chromium\";v=\"119\", \"Not?A_Brand\";v=\"24\"", + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "\"Linux\"", + "sec-fetch-dest": "document", + "sec-fetch-mode": "navigate", + "sec-fetch-site": "none", + "sec-fetch-user": "?1", + "upgrade-insecure-requests": "1", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", + } + req_response = requests.get(cls.url, headers=headers) + access_token = cls._access_token = req_response.cookies.get("csrftoken") + + headers = { + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US;q=0.6", + "Cookie": f"csrftoken={access_token};", + "Origin": "https://voigpt.com", + "Referer": "https://voigpt.com/", + "Sec-Ch-Ua": "'Google Chrome';v='119', 'Chromium';v='119', 'Not?A_Brand';v='24'", + "Sec-Ch-Ua-Mobile": "?0", + "Sec-Ch-Ua-Platform": "'Windows'", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", + "X-Csrftoken": access_token, + } + + payload = { + "messages": messages, + } + request_url = f"{cls.url}/generate_response/" + req_response = requests.post(request_url, headers=headers, json=payload) + try: + response = json.loads(req_response.text) + yield response["response"] + except: + raise RuntimeError(f"Response: {req_response.text}") + |