summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Bestim.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-10 10:34:56 +0100
committerGitHub <noreply@github.com>2024-01-10 10:34:56 +0100
commitbee75be8e38d25c4568c641412a49b576d425b24 (patch)
tree63ea1505dbe2b84c3011164a7b2699e642d94c19 /g4f/Provider/Bestim.py
parentMerge pull request #1441 from w453y/patch-1 (diff)
downloadgpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.gz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.bz2
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.lz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.xz
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.tar.zst
gpt4free-bee75be8e38d25c4568c641412a49b576d425b24.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/Bestim.py43
1 files changed, 17 insertions, 26 deletions
diff --git a/g4f/Provider/Bestim.py b/g4f/Provider/Bestim.py
index 312655b8..be95b48a 100644
--- a/g4f/Provider/Bestim.py
+++ b/g4f/Provider/Bestim.py
@@ -1,42 +1,35 @@
from __future__ import annotations
-from ..typing import Messages, List, Dict
+from ..typing import Messages
from .base_provider import BaseProvider, CreateResult
+from ..requests import get_session_from_browser
from uuid import uuid4
import requests
-def format_prompt(messages) -> List[Dict[str, str]]:
-
- return [{"id": str(uuid4()), "content": '\n'.join(f'{m["role"]}: {m["content"]}' for m in messages), "from": "you"}]
-
class Bestim(BaseProvider):
url = "https://chatgpt.bestim.org"
supports_gpt_35_turbo = True
supports_message_history = True
- working = True
+ working = False
supports_stream = True
- @staticmethod
+ @classmethod
def create_completion(
+ cls,
model: str,
messages: Messages,
stream: bool,
proxy: str = None,
**kwargs
) -> CreateResult:
-
+ session = get_session_from_browser(cls.url, proxy=proxy)
headers = {
- 'POST': '/chat/send2/ HTTP/3',
- 'Host': 'chatgpt.bestim.org',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0',
'Accept': 'application/json, text/event-stream',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://chatgpt.bestim.org/chat/',
- 'Content-Type': 'application/json',
- 'Content-Length': '109',
'Origin': 'https://chatgpt.bestim.org',
- 'Cookie': 'NpZAER=qKkRHguMIOraVbJAWpoyzGLFjZwYlm; qKkRHguMIOraVbJAWpoyzGLFjZwYlm=8ebb5ae1561bde05354de5979b52c6e1-1704058188-1704058188; NpZAER_hits=2; _csrf-front=fcf20965823c0a152ae8f9cdf15b23022bb26cdc6bf32a9d4c8bfe78dcc6b807a%3A2%3A%7Bi%3A0%3Bs%3A11%3A%22_csrf-front%22%3Bi%3A1%3Bs%3A32%3A%22a5wP6azsc7dxV8rmwAXaNsl8XS1yvW5V%22%3B%7D',
'Alt-Used': 'chatgpt.bestim.org',
'Connection': 'keep-alive',
'Sec-Fetch-Dest': 'empty',
@@ -44,27 +37,25 @@ class Bestim(BaseProvider):
'Sec-Fetch-Site': 'same-origin',
'TE': 'trailers'
}
-
data = {
-
- "messagesHistory": format_prompt(messages),
+ "messagesHistory": [{
+ "id": str(uuid4()),
+ "content": m["content"],
+ "from": "you" if m["role"] == "user" else "bot"
+ } for m in messages],
"type": "chat",
}
-
- response = requests.post(
+ response = session.post(
url="https://chatgpt.bestim.org/chat/send2/",
headers=headers,
json=data,
- proxies={"https": proxy}
+ proxies={"https": proxy},
+ stream=True
)
-
response.raise_for_status()
-
- for chunk in response.iter_lines():
-
- if b"event: trylimit" not in chunk:
-
- yield chunk.decode().removeprefix("data: ")
+ for line in response.iter_lines():
+ if not line.startswith(b"event: trylimit"):
+ yield line.decode().removeprefix("data: ")