Antonio Cheong
commited on
Simplify reference code
Browse files
README.md
CHANGED
@@ -52,62 +52,15 @@ options:
|
|
52 |
## Developer
|
53 |
Use Async for the best experience
|
54 |
|
|
|
|
|
55 |
```python
|
56 |
import asyncio
|
57 |
from EdgeGPT import Chatbot
|
58 |
|
59 |
-
def get_input(prompt):
|
60 |
-
"""
|
61 |
-
Multi-line input function
|
62 |
-
"""
|
63 |
-
# Display the prompt
|
64 |
-
print(prompt, end="")
|
65 |
-
|
66 |
-
# Initialize an empty list to store the input lines
|
67 |
-
lines = []
|
68 |
-
|
69 |
-
# Read lines of input until the user enters an empty line
|
70 |
-
while True:
|
71 |
-
line = input()
|
72 |
-
if line == "":
|
73 |
-
break
|
74 |
-
lines.append(line)
|
75 |
-
|
76 |
-
# Join the lines, separated by newlines, and store the result
|
77 |
-
user_input = "\n".join(lines)
|
78 |
-
|
79 |
-
# Return the input
|
80 |
-
return user_input
|
81 |
-
|
82 |
-
|
83 |
async def main():
|
84 |
-
"""
|
85 |
-
Main function
|
86 |
-
"""
|
87 |
-
print("Initializing...")
|
88 |
bot = Chatbot()
|
89 |
-
|
90 |
-
prompt = get_input("\nYou:\n")
|
91 |
-
if prompt == "!exit":
|
92 |
-
break
|
93 |
-
elif prompt == "!help":
|
94 |
-
print(
|
95 |
-
"""
|
96 |
-
!help - Show this help message
|
97 |
-
!exit - Exit the program
|
98 |
-
!reset - Reset the conversation
|
99 |
-
""",
|
100 |
-
)
|
101 |
-
continue
|
102 |
-
elif prompt == "!reset":
|
103 |
-
await bot.reset()
|
104 |
-
continue
|
105 |
-
print("Bot:")
|
106 |
-
print(
|
107 |
-
(await bot.ask(prompt=prompt))["item"]["messages"][1]["adaptiveCards"][0][
|
108 |
-
"body"
|
109 |
-
][0]["text"],
|
110 |
-
)
|
111 |
await bot.close()
|
112 |
|
113 |
|
|
|
52 |
## Developer
|
53 |
Use Async for the best experience
|
54 |
|
55 |
+
[Reference code](https://github.com/acheong08/EdgeGPT/blob/master/src/EdgeGPT.py#L268-L328) for more advanced example of usage
|
56 |
+
|
57 |
```python
|
58 |
import asyncio
|
59 |
from EdgeGPT import Chatbot
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
async def main():
|
|
|
|
|
|
|
|
|
62 |
bot = Chatbot()
|
63 |
+
print((await bot.ask(prompt="Hello world"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
await bot.close()
|
65 |
|
66 |
|