Skip to content

Commit

Permalink
feat: auto delete conversation for revChatGPT
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Oct 6, 2023
1 parent 599a857 commit 66e0c6d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion free_one_api/impls/adapter/revChatGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ def __init__(self, config: dict):
async def test(self) -> (bool, str):
try:
prev_text = ""
conversation_id = ""
self.chatbot.conversation_id = None
async for data in self.chatbot.ask(
"Hi, respond 'Hello, world!' please.",
):
message = data["message"][len(prev_text):]
prev_text = data["message"]
conversation_id = data["conversation_id"]

await self.chatbot.delete_conversation(conversation_id)
return True, ""
except Exception as e:
traceback.print_exc()
Expand All @@ -109,12 +114,14 @@ async def query(self, req: request.Request) -> typing.AsyncGenerator[response.Re
prev_text = ""

try:

conversation_id = ""
self.chatbot.conversation_id = None
async for data in self.chatbot.post_messages(
messages=new_messages,
):
message = data["message"][len(prev_text):]
prev_text = data["message"]
conversation_id = data["conversation_id"]

yield response.Response(
id=random_int,
Expand All @@ -130,6 +137,8 @@ async def query(self, req: request.Request) -> typing.AsyncGenerator[response.Re
normal_message="",
function_call=None
)

await self.chatbot.delete_conversation(conversation_id)
except chatgpt.t.Error as e:
assert isinstance(e, chatgpt.t.ErrorType)
code = e.code.name.lower()
Expand Down

0 comments on commit 66e0c6d

Please sign in to comment.