Quick Feedback
UX Enhancement
The UX of our application can be enhanced by letting the user know that the application is working after they execute a command. At the moment, it is processing, but it just doesn't let the user know. We'll use the Spinner functionality from the Rich library to make the application a little more user-friendly and visually appealing.
Spinner
The Console
class has a status
method which will allow us to display a Spinner
to the user while Griptape is waiting for the LLM response.
Abstract
There are lots of spinners available. You can check them out by running the following in your terminal:
Importing the Console
Importing the Console class from the rich
library is simple and straightforward, and should be familiar to you by this point in the lesson.
Modify Respond
We will add a spinner to our respond
method in the MyAgent
subclass. This will show an animated spinner in the console while our agent is processing the user's input. This makes the app feel more responsive.
Update the respond
method as follows:
class MyAgent(Agent):
def respond(self, user_input):
console = Console()
with console.status(spinner="simpleDotsScrolling", status=""):
agent_response = self.run(user_input)
# ...
In the code above, console.status(spinner="simpleDotsScrolling", status="")
starts an animated spinner in the console that will run until the block of code it is wrapping (the agent's processing of user input) completes.
Note
We've left status
blank - because we don't really need to send any text. However, feel free to add some text here if you desire.
Now when you run the chat, you'll notice the animated spinner right after you ask the chatbot a question!
Code Review
Double-check your code to make sure the spinner is working as expected.
app.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
All Done!
Success
You did it!
That's it! We've come a long way in this tutorial series and now you have a multi-persona chat application written with Griptape. Hopefully you've been able to see how using Rulesets can be used for both creative and structural control of your applications.
Congratulations on making it through! We're thrilled you decided to join us for this course and we hope you've enjoyed it as much as we have. We'd love to hear your feedback, so please don't hesitate to let us know what you thought.
More importantly, we wish you all the best as you continue your journey with Griptape and Python. Remember to have fun, experiment, and keep on learning. Happy coding! 🚀