Skip to content

Commit

Permalink
Merge pull request #100 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Update docs and comments
  • Loading branch information
JE-Chen authored Jan 24, 2024
2 parents 33ace26 + 4e33a9f commit 20b423b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 71 deletions.
100 changes: 41 additions & 59 deletions docs/source/docs/API/api.rst
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
ReEdgeGPT API
----

.. code-block:: python
async def save_conversation(self, filename: str) -> None:
"""
Save the conversation to a file
"""
.. code-block:: python
async def load_conversation(self, filename: str) -> None:
"""
Load the conversation from a file
"""
.. code-block:: python
async def get_conversation(self) -> dict:
"""
Gets the conversation history from conversation_id (requires load_conversation)
"""
"""
Save the conversation to a dict
conversation_dict: use to save conversation
bot: ReEdgeGPT instance
cookies: cookie dict
example below:
"""
conversation_dict = {}
bot = None
cookies: list[dict] = json.loads(open(
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies)
conversation_dict.update(await bot.chat_hub.get_conversation())
.. code-block:: python
async def get_activity(self) -> dict:
"""
Gets the recent activity (requires cookies)
"""
async def set_conversation(self, conversation_dict: dict):
"""
Load the conversation from a dict
bot: ReEdgeGPT instance
cookies: cookie dict
example below:
"""
bot = None
cookies: list[dict] = json.loads(open(
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies)
await bot.chat_hub.set_conversation(conversation_dict=conversation_dict)
.. code-block:: python
Expand All @@ -40,35 +44,25 @@ ReEdgeGPT API
search_result: bool = False,
locale: str = guess_locale(),
simplify_response: bool = False,
attachment: dict[str, str] = None
):
"""
Ask a question to the bot
Response:
{
item (dict):
messages (list[dict]):
adaptiveCards (list[dict]):
body (list[dict]):
text (str): Response
}
To get the response, you can do:
response["item"]["messages"][1]["adaptiveCards"][0]["body"][0]["text"]
"""
.. code-block:: python
async def ask_stream(
self,
prompt: str,
wss_link: str = "wss://sydney.bing.com/sydney/ChatHub",
conversation_style: CONVERSATION_STYLE_TYPE = None,
raw: bool = False,
webpage_context: str | None = None,
search_result: bool = False,
locale: str = guess_locale(),
) -> Generator[bool, dict | str, None]:
"""
Ask a question to the bot
:param prompt: The prompt to ask Bing
:param wss_link: The link to the Bing web service
:param conversation_style: The style of the Bing chat
:param webpage_context: U don't need use this param in normal use
:param search_result: Search web True or False
:param locale: Bing service locale
:param simplify_response: Simplify response True or False
:param attachment: Send image
attachment example:
For url using
attachment={"image_url": r"<image_url>"})
For local file using
attachment={"filename": r"<file_path>"})
For base64 image using
attachment={"base64_image": r"<base64_image_str>"})
"""
.. code-block:: python
Expand All @@ -78,18 +72,6 @@ ReEdgeGPT API
Close the connection
"""
.. code-block:: python
async def delete_conversation(
self,
conversation_id: str = None,
conversation_signature: str = None,
client_id: str = None,
) -> None:
"""
Delete the chat in the server
"""
.. code-block:: python
async def reset(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions re_edge_gpt/chathub.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ async def ask_stream(
async def close(self) -> None:
await self.session.aclose()

async def get_conversation(self):
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,
}

async def set_conversation(self, conversation_dict: dict):
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[
Expand Down
25 changes: 15 additions & 10 deletions re_edge_gpt/re_edge_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,21 @@ async def ask(
):
"""
Ask a question to the bot
Response:
{
item (dict):
messages (list[dict]):
adaptiveCards (list[dict]):
body (list[dict]):
text (str): Response
}
To get the response, you can do:
response["item"]["messages"][1]["adaptiveCards"][0]["body"][0]["text"]
:param prompt: The prompt to ask Bing
:param wss_link: The link to the Bing web service
:param conversation_style: The style of the Bing chat
:param webpage_context: U don't need use this param in normal use
:param search_result: Search web True or False
:param locale: Bing service locale
:param simplify_response: Simplify response True or False
:param attachment: Send image
attachment example:
For url using
attachment={"image_url": r"<image_url>"})
For local file using
attachment={"filename": r"<file_path>"})
For base64 image using
attachment={"base64_image": r"<base64_image_str>"})
"""
async for final, response in self.chat_hub.ask_stream(
prompt=prompt,
Expand Down

0 comments on commit 20b423b

Please sign in to comment.