Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs #143

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions docs/source/docs/API/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ ReEdgeGPT API
search_result: bool = False,
locale: str = guess_locale(),
simplify_response: bool = False,
attachment: dict[str, str] = None
attachment: dict[str, str] = None,
remove_options: list = None,
add_options: list = None,
plugins: list = None,
message_type: str = "Chat"
):
"""
Ask a question to the bot
Expand All @@ -63,7 +67,10 @@ ReEdgeGPT API
attachment={"filename": r"<file_path>"})
For base64 image using
attachment={"base64_image": r"<base64_image_str>"})
"""
:param remove_options remove options from Style
:param add_options add options to Style
:param plugins: plugin name as list of strings
:param message_type: Bing chat's message type

.. code-block:: python

Expand Down
24 changes: 14 additions & 10 deletions docs/source/docs/Eng/chat_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@ ReEdgeGPT Chat Example

import asyncio
import json
# If you are using jupyter pls install this package
# from nest_asyncio import apply
from pathlib import Path

from re_edge_gpt import Chatbot
from re_edge_gpt import ConversationStyle


# If you are using jupyter pls install this package
# from nest_asyncio import apply


async def test_ask() -> None:
bot = None
try:
cookies: list[dict] = json.loads(open(
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies)
mode = "Bing"
if mode == "Bing":
cookies: list[dict] = json.loads(open(
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
else:
cookies: list[dict] = json.loads(open(
str(Path(str(Path.cwd()) + "/copilot_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies, mode=mode)
response = await bot.ask(
prompt="How do I know when my pizza is done?",
conversation_style=ConversationStyle.balanced,
simplify_response=True
prompt="What version u are using GPT-4 turbo?",
conversation_style=ConversationStyle.creative_classic, # ConversationStyle.creative
simplify_response=True,
search_result=True,
)
# If you are using non ascii char you need set ensure_ascii=False
print(json.dumps(response, indent=2, ensure_ascii=False))
Expand Down
5 changes: 2 additions & 3 deletions docs/source/docs/Eng/chat_with_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Example
prompt="What does this image show?",
conversation_style=ConversationStyle.balanced,
simplify_response=True,
attachment={"image_url": r"https://images.yourstory.com/cs/2/96eabe90392211eb93f18319e8c07a74/Image54nh-1683225460858.jpg"})
attachment={"filename": "test.jpg"})
# If you are using non ascii char you need set ensure_ascii=False
print(json.dumps(response, indent=2, ensure_ascii=False))
# Raw response
Expand All @@ -68,5 +68,4 @@ Example
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.get_event_loop()
loop.run_until_complete(test_ask())
```
loop.run_until_complete(test_ask())
3 changes: 2 additions & 1 deletion docs/source/docs/Eng/eng_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ ReEdgeGPT English Documentation
chat_example.rst
generate_image.rst
chat_with_file.rst
save_conversation.rst
save_conversation.rst
using_plugins.rst
8 changes: 6 additions & 2 deletions docs/source/docs/Eng/save_conversation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ ReEdgeGPT Save Conversation
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 @@ -46,12 +47,14 @@ ReEdgeGPT Save Conversation
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 All @@ -68,3 +71,4 @@ ReEdgeGPT Save Conversation
loop = asyncio.get_event_loop()
loop.run_until_complete(test_ask())
loop.run_until_complete(test_ask_conversation())

63 changes: 63 additions & 0 deletions docs/source/docs/Eng/using_plugins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
ReEdgeGPT Using plugins
----
Support plugins:
Notebook id: c310c353-b9f0-4d76-ab0d-1dd5e979cf68
Instacart id: 46664d33-1591-4ce8-b3fb-ba1022b66c11
Kayak id: d6be744c-2bd9-432f-95b7-76e103946e34
Klarna id: 5f143ea3-8c80-4efd-9515-185e83b7cf8a
Opentable id: 543a7b1b-ebc6-46f4-be76-00c202990a1b
Shop id: 39e3566a-d481-4d99-82b2-6d739b1e716e
Suno id: 22b7f79d-8ea4-437e-b5fd-3e21f09f7bc1
Use Suno example:

.. code-block:: python

import asyncio
import json
from pathlib import Path

from re_edge_gpt import Chatbot
from re_edge_gpt import ConversationStyle
from re_edge_gpt.plugins.suno import generate_suno_music


# If you are using jupyter pls install this package
# from nest_asyncio import apply


async def test_ask() -> None:
bot = None
try:
cookies: list[dict] = json.loads(open(
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies, mode="Bing", plugin_ids=["suno"])
prompt = """Can you create some epic music"""
response = await bot.ask(
prompt=prompt,
conversation_style=ConversationStyle.balanced,
simplify_response=True,
add_options=["014CB21D"],
plugins=[{"Id": "c310c353-b9f0-4d76-ab0d-1dd5e979cf68", "Category": 1}],
message_type="GenerateContentQuery"
)
# Notice! only simplify_response=True return messageId & requestId
# If you are using raw response you need self get it.
# If you are using non ascii char you need set ensure_ascii=False
print(json.dumps(response, indent=2, ensure_ascii=False))
print(await generate_suno_music(cookies, response.get("messageId"), response.get("requestId")))
except Exception as error:
raise error
finally:
if bot is not None:
await bot.close()


if __name__ == "__main__":
# If you are using jupyter pls use nest_asyncio apply()
# apply()
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.get_event_loop()
loop.run_until_complete(test_ask())

64 changes: 64 additions & 0 deletions docs/source/docs/Zh/using_plugins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
ReEdgeGPT 使用插件
----
支援的插件:
Notebook id: c310c353-b9f0-4d76-ab0d-1dd5e979cf68
Instacart id: 46664d33-1591-4ce8-b3fb-ba1022b66c11
Kayak id: d6be744c-2bd9-432f-95b7-76e103946e34
Klarna id: 5f143ea3-8c80-4efd-9515-185e83b7cf8a
Opentable id: 543a7b1b-ebc6-46f4-be76-00c202990a1b
Shop id: 39e3566a-d481-4d99-82b2-6d739b1e716e
Suno id: 22b7f79d-8ea4-437e-b5fd-3e21f09f7bc1

使用 Suno 的範例:

.. code-block:: python

import asyncio
import json
from pathlib import Path

from re_edge_gpt import Chatbot
from re_edge_gpt import ConversationStyle
from re_edge_gpt.plugins.suno import generate_suno_music


# If you are using jupyter pls install this package
# from nest_asyncio import apply


async def test_ask() -> None:
bot = None
try:
cookies: list[dict] = json.loads(open(
str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read())
bot = await Chatbot.create(cookies=cookies, mode="Bing", plugin_ids=["suno"])
prompt = """Can you create some epic music"""
response = await bot.ask(
prompt=prompt,
conversation_style=ConversationStyle.balanced,
simplify_response=True,
add_options=["014CB21D"],
plugins=[{"Id": "c310c353-b9f0-4d76-ab0d-1dd5e979cf68", "Category": 1}],
message_type="GenerateContentQuery"
)
# Notice! only simplify_response=True return messageId & requestId
# If you are using raw response you need self get it.
# If you are using non ascii char you need set ensure_ascii=False
print(json.dumps(response, indent=2, ensure_ascii=False))
print(await generate_suno_music(cookies, response.get("messageId"), response.get("requestId")))
except Exception as error:
raise error
finally:
if bot is not None:
await bot.close()


if __name__ == "__main__":
# If you are using jupyter pls use nest_asyncio apply()
# apply()
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.get_event_loop()
loop.run_until_complete(test_ask())

3 changes: 2 additions & 1 deletion docs/source/docs/Zh/zh_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ ReEdgeGPT 繁體中文 文件
chat_example.rst
generate_image.rst
chat_with_file.rst
save_conversation.rst
save_conversation.rst
using_plugins.rst
4 changes: 2 additions & 2 deletions re_edge_gpt/chat/re_edge_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ async def ask(
attachment={"base64_image": r"<base64_image_str>"})
:param remove_options remove options from Style
:param add_options add options to Style
:param plugins:
:param chat_mode:
:param plugins: plugin name as list of strings
:param message_type: Bing chat's message type
"""
async for final, response in self.chat_hub.ask_stream(
prompt=prompt,
Expand Down
Loading