|
| 1 | +ReEdgeGPT Chat Example |
| 2 | +---- |
| 3 | + |
| 4 | +.. code-block:: python |
| 5 | +
|
| 6 | + import asyncio |
| 7 | + import json |
| 8 | + from pathlib import Path |
| 9 | +
|
| 10 | + from re_edge_gpt import Chatbot |
| 11 | + from re_edge_gpt import ConversationStyle |
| 12 | +
|
| 13 | +
|
| 14 | + async def test_ask() -> None: |
| 15 | + # Read local bing_cookies.json (if you don't have this file please read README) |
| 16 | + cookies = json.loads(open( |
| 17 | + str(Path(str(Path.cwd()) + "/bing_cookies.json")), encoding="utf-8").read()) |
| 18 | + # init BOT |
| 19 | + bot = await Chatbot.create(cookies=cookies) |
| 20 | + # Start chat and get Bing response |
| 21 | + response = await bot.ask( |
| 22 | + prompt="Hello.", |
| 23 | + conversation_style=ConversationStyle.balanced, |
| 24 | + simplify_response=True, |
| 25 | + ) |
| 26 | + print(json.dumps(response, indent=2)) |
| 27 | + response = await bot.ask( |
| 28 | + prompt="How do I make a cake?", |
| 29 | + conversation_style=ConversationStyle.balanced, |
| 30 | + simplify_response=True, |
| 31 | + ) |
| 32 | + print(json.dumps(response, indent=2)) |
| 33 | + response = await bot.ask( |
| 34 | + prompt="Can you suggest me an easy recipe for beginners?", |
| 35 | + conversation_style=ConversationStyle.balanced, |
| 36 | + simplify_response=True, |
| 37 | + ) |
| 38 | + print(json.dumps(response, indent=2)) |
| 39 | + response = await bot.ask( |
| 40 | + prompt="Thanks", |
| 41 | + conversation_style=ConversationStyle.balanced, |
| 42 | + simplify_response=True, |
| 43 | + ) |
| 44 | + print(json.dumps(response, indent=2)) |
| 45 | + # Close bot |
| 46 | + await bot.close() |
| 47 | +
|
| 48 | + if __name__ == "__main__": |
| 49 | + loop = asyncio.get_event_loop() |
| 50 | + loop.run_until_complete(test_ask()) |
0 commit comments