2024-01-02 01:42:21 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-01-10 09:34:56 +00:00
|
|
|
from ..typing import Messages
|
2024-01-02 01:42:21 +00:00
|
|
|
from .base_provider import BaseProvider, CreateResult
|
2024-01-10 09:34:56 +00:00
|
|
|
from ..requests import get_session_from_browser
|
2024-01-02 01:42:21 +00:00
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
class Bestim(BaseProvider):
|
|
|
|
url = "https://chatgpt.bestim.org"
|
|
|
|
supports_gpt_35_turbo = True
|
|
|
|
supports_message_history = True
|
2024-01-10 09:34:56 +00:00
|
|
|
working = False
|
2024-01-02 01:42:21 +00:00
|
|
|
supports_stream = True
|
|
|
|
|
2024-01-10 09:34:56 +00:00
|
|
|
@classmethod
|
2024-01-02 01:42:21 +00:00
|
|
|
def create_completion(
|
2024-01-10 09:34:56 +00:00
|
|
|
cls,
|
2024-01-02 01:42:21 +00:00
|
|
|
model: str,
|
|
|
|
messages: Messages,
|
|
|
|
stream: bool,
|
|
|
|
proxy: str = None,
|
|
|
|
**kwargs
|
|
|
|
) -> CreateResult:
|
2024-01-10 09:34:56 +00:00
|
|
|
session = get_session_from_browser(cls.url, proxy=proxy)
|
2024-01-02 01:42:21 +00:00
|
|
|
headers = {
|
|
|
|
'Accept': 'application/json, text/event-stream',
|
|
|
|
}
|
|
|
|
data = {
|
2024-01-10 09:34:56 +00:00
|
|
|
"messagesHistory": [{
|
|
|
|
"id": str(uuid4()),
|
|
|
|
"content": m["content"],
|
|
|
|
"from": "you" if m["role"] == "user" else "bot"
|
|
|
|
} for m in messages],
|
2024-01-02 01:42:21 +00:00
|
|
|
"type": "chat",
|
|
|
|
}
|
2024-01-10 09:34:56 +00:00
|
|
|
response = session.post(
|
2024-01-02 01:42:21 +00:00
|
|
|
url="https://chatgpt.bestim.org/chat/send2/",
|
|
|
|
json=data,
|
2024-01-27 01:00:44 +00:00
|
|
|
headers=headers,
|
2024-01-10 09:34:56 +00:00
|
|
|
stream=True
|
2024-01-02 01:42:21 +00:00
|
|
|
)
|
|
|
|
response.raise_for_status()
|
2024-01-10 09:34:56 +00:00
|
|
|
for line in response.iter_lines():
|
|
|
|
if not line.startswith(b"event: trylimit"):
|
|
|
|
yield line.decode().removeprefix("data: ")
|
2024-01-02 01:42:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|