Skip to content

Commit

Permalink
Fix can't use old conversation
Browse files Browse the repository at this point in the history
Fix can't use old conversation
  • Loading branch information
JE-Chen committed May 8, 2024
1 parent 6bf9678 commit f62e1ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
23 changes: 11 additions & 12 deletions re_edge_gpt/chat/chathub.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from re_edge_gpt.utils.utilities import guess_locale
from .conversation import Conversation
from .request import ChatHubRequest
from ..plugins.suno import generate_suno_music
from ..utils.exception.exceptions import NoResultsFound, ResponseError

ssl_context = ssl.create_default_context()
Expand Down Expand Up @@ -226,27 +225,27 @@ async def close(self) -> None:

async def get_conversation(self) -> dict:
return {
"conversation_id": self.conversation_id,
"client_id": self.request.client_id,
"encrypted_conversation_signature": self.encrypted_conversation_signature,
"conversation_signature": self.request.conversation_signature,
"conversationId": self.conversation.struct["conversationId"],
"clientId": self.conversation.struct["clientId"],
"encryptedConversationSignature": self.conversation.struct["encryptedConversationSignature"],
"conversationSignature": self.conversation.struct["conversationSignature"],
}

async def set_conversation(self, conversation_dict: dict) -> None:
self.conversation.struct["conversationId"] = conversation_dict.get("conversation_id")
self.conversation.struct["client_id"] = conversation_dict.get("client_id")
self.conversation.struct["conversationId"] = conversation_dict.get("conversationId")
self.conversation.struct["clientId"] = conversation_dict.get("clientId")
self.conversation.struct[
"encrypted_conversation_signature"] = conversation_dict.get("encrypted_conversation_signature")
self.conversation.struct["conversation_signature"] = conversation_dict.get("conversation_signature")
"encryptedConversationSignature"] = conversation_dict.get("encryptedConversationSignature")
self.conversation.struct["conversationSignature"] = conversation_dict.get("conversationSignature")

async def delete_conversation(self, conversation_id: str = None, client_id: str = None,
encrypted_conversation_signature: str = None, conversation_signature: str = None
) -> None:
self.conversation.struct["conversationId"] = conversation_id
self.conversation.struct["client_id"] = client_id
self.conversation.struct["clientId"] = client_id
self.conversation.struct[
"encrypted_conversation_signature"] = encrypted_conversation_signature
self.conversation.struct["conversation_signature"] = conversation_signature
"encryptedConversationSignature"] = encrypted_conversation_signature
self.conversation.struct["conversationSignature"] = conversation_signature
delete_conversation_url = "https://sydney.bing.com/sydney/DeleteSingleConversation"
await self.session.post(
delete_conversation_url,
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
aiohttp
certifi
httpx
prompt_toolkit
requests
rich
regex
Expand Down
7 changes: 5 additions & 2 deletions test/unit_test/back-end/manual_test/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ async def test_ask() -> None:
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies)
response = await bot.ask(
prompt="Translate next word what I say to english",
prompt="Hello there",
conversation_style=ConversationStyle.balanced,
simplify_response=True
)
# If you are using non ascii char you need set ensure_ascii=False
print(json.dumps(response, indent=2, ensure_ascii=False))
print(bot.chat_hub.conversation.struct)
print(await bot.chat_hub.get_conversation())
conversation_dict.update(await bot.chat_hub.get_conversation())
except Exception as error:
Expand All @@ -41,12 +42,14 @@ async def test_ask_conversation() -> None:
bot = await Chatbot.create(cookies=cookies)
await bot.chat_hub.set_conversation(conversation_dict=conversation_dict)
response = await bot.ask(
prompt="піца",
prompt="What did I say before?",
conversation_style=ConversationStyle.balanced,
simplify_response=True
)
# If you are using non ascii char you need set ensure_ascii=False
print(json.dumps(response, indent=2, ensure_ascii=False))
print(bot.chat_hub.conversation.struct)
print(await bot.chat_hub.get_conversation())
except Exception as error:
raise error
finally:
Expand Down

0 comments on commit f62e1ba

Please sign in to comment.