This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
# Author: XiaoXinYo | ||
|
||
from typing import Union | ||
from module import auxiliary | ||
import Bard | ||
import EdgeGPT | ||
import revChatGPT.V3 | ||
import easy_ernie | ||
import config | ||
import asyncio | ||
import uuid | ||
|
||
CHAT_BOT = {} | ||
|
||
def generateChatBot(type_: str) -> Union[tuple, None]: | ||
global CHAT_BOT | ||
token = str(uuid.uuid4()) | ||
if type_ == 'Bard': | ||
chatBot = Bard.Chatbot(auxiliary.getCookie('./cookie/bard.json', ['__Secure-1PSID'])['__Secure-1PSID'], proxy=config.PROXY) | ||
elif type_ == 'Bing': | ||
chatBot = EdgeGPT.Chatbot(proxy=config.PROXY, cookie_path='./cookie/bing.json') | ||
elif type_ == 'ChatGPT': | ||
chatBot = revChatGPT.V3.Chatbot(config.CHATGPT_KEY, proxy=config.PROXY) | ||
elif type_ == 'Ernie': | ||
cookie = auxiliary.getCookie('./cookie/ernie.json', ['BAIDUID', 'BDUSS_BFESS']) | ||
chatBot = easy_ernie.FastErnie(cookie['BAIDUID'], cookie['BDUSS_BFESS']) | ||
else: | ||
return None | ||
CHAT_BOT[token] = {} | ||
CHAT_BOT[token]['type'] = type_ | ||
CHAT_BOT[token]['chatBot'] = chatBot | ||
CHAT_BOT[token]['useTimeStamp'] = auxiliary.getTimeStamp() | ||
return token, chatBot | ||
|
||
def getChatBot(token: str) -> Union[dict, None]: | ||
global CHAT_BOT | ||
if token in CHAT_BOT: | ||
CHAT_BOT[token]['useTimeStamp'] = auxiliary.getTimeStamp() | ||
return CHAT_BOT[token] | ||
return None | ||
|
||
async def checkChatBot() -> None: | ||
global CHAT_BOT | ||
while True: | ||
for token in CHAT_BOT.copy(): | ||
chatBot = CHAT_BOT[token] | ||
if auxiliary.getTimeStamp() - chatBot['useTimeStamp'] > config.TOKEN_USE_MAX_TIME_INTERVAL * 60: | ||
if chatBot['type'] == 'Bing': | ||
await chatBot['chatBot'].close() | ||
elif chatBot['type'] == 'Ernie': | ||
chatBot['chatBot'].close() | ||
del chatBot | ||
await asyncio.sleep(60) |
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