diff options
author | kqlio67 <166700875+kqlio67@users.noreply.github.com> | 2024-07-28 18:24:48 +0200 |
---|---|---|
committer | kqlio67 <166700875+kqlio67@users.noreply.github.com> | 2024-07-28 18:24:48 +0200 |
commit | 15fdd2cb069f47f468f330d40f0d34c2cd18ebc8 (patch) | |
tree | be3d3a74a9c949b1fe74f83579462be77fecd843 /g4f/Provider/Marsyoo.py | |
parent | Fixed a bug in the Liaobots provider (diff) | |
download | gpt4free-15fdd2cb069f47f468f330d40f0d34c2cd18ebc8.tar gpt4free-15fdd2cb069f47f468f330d40f0d34c2cd18ebc8.tar.gz gpt4free-15fdd2cb069f47f468f330d40f0d34c2cd18ebc8.tar.bz2 gpt4free-15fdd2cb069f47f468f330d40f0d34c2cd18ebc8.tar.lz gpt4free-15fdd2cb069f47f468f330d40f0d34c2cd18ebc8.tar.xz gpt4free-15fdd2cb069f47f468f330d40f0d34c2cd18ebc8.tar.zst gpt4free-15fdd2cb069f47f468f330d40f0d34c2cd18ebc8.zip |
Diffstat (limited to 'g4f/Provider/Marsyoo.py')
-rw-r--r-- | g4f/Provider/Marsyoo.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/g4f/Provider/Marsyoo.py b/g4f/Provider/Marsyoo.py new file mode 100644 index 00000000..1c5fa9fd --- /dev/null +++ b/g4f/Provider/Marsyoo.py @@ -0,0 +1,64 @@ +from __future__ import annotations + +import json +from aiohttp import ClientSession, ClientResponseError + +from ..typing import AsyncResult, Messages +from .base_provider import AsyncGeneratorProvider, ProviderModelMixin +from .helper import format_prompt + + +class Marsyoo(AsyncGeneratorProvider, ProviderModelMixin): + url = "https://aiagent.marsyoo.com" + api_endpoint = "/api/chat-messages" + working = True + supports_gpt_4 = True + default_model = 'gpt-4o' + + @classmethod + async def create_async_generator( + cls, + model: str, + messages: Messages, + proxy: str = None, + **kwargs + ) -> AsyncResult: + headers = { + "Accept": "*/*", + "Accept-Language": "en-US,en;q=0.9", + "Connection": "keep-alive", + "DNT": "1", + "Origin": cls.url, + "Referer": f"{cls.url}/chat", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36", + "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI0MWNkOTE3MS1mNTg1LTRjMTktOTY0Ni01NzgxMTBjYWViNTciLCJzdWIiOiJXZWIgQVBJIFBhc3Nwb3J0IiwiYXBwX2lkIjoiNDFjZDkxNzEtZjU4NS00YzE5LTk2NDYtNTc4MTEwY2FlYjU3IiwiYXBwX2NvZGUiOiJMakhzdWJqNjhMTXZCT0JyIiwiZW5kX3VzZXJfaWQiOiI4YjE5YjY2Mi05M2E1LTRhYTktOGNjNS03MDhmNWE0YmQxNjEifQ.pOzdQ4wTrQjjRlEv1XY9TZitkW5KW1K-wbcUJAoBJ5I", + "content-type": "application/json", + "sec-ch-ua": '"Not/A)Brand";v="8", "Chromium";v="126"', + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "Linux", + } + async with ClientSession(headers=headers) as session: + prompt = format_prompt(messages) + data = { + "response_mode": "streaming", + "query": prompt, + "inputs": {}, + } + try: + async with session.post(f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy) as response: + response.raise_for_status() + async for line in response.content: + if line: + try: + json_data = json.loads(line.decode('utf-8').strip().lstrip('data: ')) + if json_data['event'] == 'message': + yield json_data['answer'] + elif json_data['event'] == 'message_end': + return + except json.JSONDecodeError: + continue + except ClientResponseError as e: + yield f"Error: HTTP {e.status}: {e.message}" |