forked from xtekky/gpt4free
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix version_check config
- Loading branch information
Showing
11 changed files
with
286 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from __future__ import annotations | ||
|
||
from urllib.parse import unquote | ||
|
||
from ...typing import AsyncResult, Messages | ||
from ..base_provider import BaseProvider | ||
from ...webdriver import WebDriver | ||
from ...requests import Session, get_session_from_browser | ||
|
||
class AiChatting(BaseProvider): | ||
url = "https://www.aichatting.net" | ||
supports_gpt_35_turbo = True | ||
_session: Session = None | ||
|
||
@classmethod | ||
def create_completion( | ||
cls, | ||
model: str, | ||
messages: Messages, | ||
stream: bool, | ||
proxy: str = None, | ||
timeout: int = 120, | ||
webdriver: WebDriver = None, | ||
**kwargs | ||
) -> AsyncResult: | ||
if not cls._session: | ||
cls._session = get_session_from_browser(cls.url, webdriver, proxy, timeout) | ||
visitorId = unquote(cls._session.cookies.get("aichatting.website.visitorId")) | ||
|
||
headers = { | ||
"accept": "application/json, text/plain, */*", | ||
"lang": "en", | ||
"source": "web" | ||
} | ||
data = { | ||
"roleId": 0, | ||
} | ||
try: | ||
response = cls._session.post("https://aga-api.aichatting.net/aigc/chat/record/conversation/create", json=data, headers=headers) | ||
response.raise_for_status() | ||
conversation_id = response.json()["data"]["conversationId"] | ||
except Exception as e: | ||
cls.reset() | ||
raise e | ||
headers = { | ||
"authority": "aga-api.aichatting.net", | ||
"accept": "text/event-stream,application/json, text/event-stream", | ||
"lang": "en", | ||
"source": "web", | ||
"vtoken": visitorId, | ||
} | ||
data = { | ||
"spaceHandle": True, | ||
"roleId": 0, | ||
"messages": messages, | ||
"conversationId": conversation_id, | ||
} | ||
response = cls._session.post("https://aga-api.aichatting.net/aigc/chat/v2/stream", json=data, headers=headers, stream=True) | ||
response.raise_for_status() | ||
for chunk in response.iter_lines(): | ||
if chunk.startswith(b"data:"): | ||
yield chunk[5:].decode().replace("-=- --", " ").replace("-=-n--", "\n").replace("--@DONE@--", "") | ||
|
||
@classmethod | ||
def reset(cls): | ||
cls._session = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .MikuChat import MikuChat | ||
from .Komo import Komo | ||
from .ChatAiGpt import ChatAiGpt | ||
from .ChatAiGpt import ChatAiGpt | ||
from .AiChatting import AiChatting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
logging = False | ||
logging = False | ||
version_check = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.