diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | g4f/Provider/VoiGpt.py | 93 | ||||
-rw-r--r-- | g4f/Provider/__init__.py | 1 | ||||
-rw-r--r-- | g4f/models.py | 4 | ||||
-rw-r--r-- | setup.py | 2 |
5 files changed, 100 insertions, 1 deletions
@@ -1,4 +1,5 @@ ![248433934-7886223b-c1d1-4260-82aa-da5741f303bb](https://github.com/xtekky/gpt4free/assets/98614666/ea012c87-76e0-496a-8ac4-e2de090cc6c9) +Written by [@xtekky](https://github.com/hlohaus) & maintained by [@hlohaus](https://github.com/hlohaus) <a href='https://ko-fi.com/xtekky' target='_blank'><img height='35' style='border:0px;height:46px;' src='https://az743702.vo.msecnd.net/cdn/kofi3.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /> <div id="top"></div> diff --git a/g4f/Provider/VoiGpt.py b/g4f/Provider/VoiGpt.py new file mode 100644 index 00000000..33d0d85e --- /dev/null +++ b/g4f/Provider/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 = True + 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}") + diff --git a/g4f/Provider/__init__.py b/g4f/Provider/__init__.py index efc94613..6ae3db7c 100644 --- a/g4f/Provider/__init__.py +++ b/g4f/Provider/__init__.py @@ -47,6 +47,7 @@ from .Phind import Phind from .Pi import Pi from .TalkAi import TalkAi from .Vercel import Vercel +from .VoiGpt import VoiGpt from .Ylokh import Ylokh from .You import You from .Yqcloud import Yqcloud diff --git a/g4f/models.py b/g4f/models.py index cf24ff52..810722e4 100644 --- a/g4f/models.py +++ b/g4f/models.py @@ -28,6 +28,7 @@ from .Provider import ( You, H2o, Pi, + VoiGpt, ) @dataclass(unsafe_hash=True) @@ -49,6 +50,7 @@ default = Model( You, Chatgpt4Online, ChatAnywhere, + VoiGpt ]) ) @@ -65,6 +67,7 @@ gpt_35_long = Model( ChatgptDemoAi, OnlineGpt, ChatgptNext, + VoiGpt ]) ) @@ -77,6 +80,7 @@ gpt_35_turbo = Model( GptForLove, ChatBase, Chatgpt4Online, ChatAnywhere, + VoiGpt, ]) ) @@ -11,7 +11,7 @@ with codecs.open(os.path.join(here, 'README.md'), encoding='utf-8') as fh: with open('requirements.txt') as f: required = f.read().splitlines() -VERSION = '0.1.9.2' +VERSION = '0.1.9.3' DESCRIPTION = ( 'The official gpt4free repository | various collection of powerful language models' ) |