SimpleBot Tutorial
Note
This tutorial was written by GPT4 and edited by a human.
In this tutorial, we will learn how to use the SimpleBot
class, a Python implementation of a chatbot that interacts with OpenAI's GPT-4 model. The SimpleBot
class is designed to be simple and easy to use, allowing you to create a chatbot that can respond to human messages based on a given system prompt.
Getting Started
First, let's import the SimpleBot
class:
from llamabot import SimpleBot
Initializing the SimpleBot
To create a new instance of SimpleBot
, you need to provide a system prompt. The system prompt is used to prime the GPT-4 model, giving it context for generating responses. You can also optionally set the temperature
and model_name
parameters.
system_prompt = "You are an AI assistant that helps users with their questions."
bot = SimpleBot(system_prompt)
Interacting with the SimpleBot
To interact with the SimpleBot
, simply call the instance with a human message as a parameter. The bot will return an AIMessage
object containing the generated response.
human_message = "What is the capital of France?"
response = bot(human_message)
print(response.content)
Using the Panel App
SimpleBot
also comes with a built-in Panel app that provides a graphical user interface for interacting with the chatbot. To create the app, call the panel()
method on your SimpleBot
instance:
app = bot.panel()
You can customize the appearance of the app by providing optional parameters such as input_text_label
, output_text_label
, submit_button_label
, site_name
, and title
.
To display the app in your browser, call the show()
method on the app:
app.show()
Example
Here's a complete example of how to create and interact with a SimpleBot
:
from simple_bot import SimpleBot
# Initialize the SimpleBot
system_prompt = "You are an AI assistant that helps users with their questions."
bot = SimpleBot(system_prompt)
# Interact with the SimpleBot
human_message = "What is the capital of France?"
response = bot(human_message)
print(response.content)
# Create and display the Panel app
app = bot.panel()
app.show()
Conclusion
In this tutorial, we learned how to use the SimpleBot
class to create a simple chatbot that interacts with OpenAI's GPT-4 model. We also learned how to create a Panel app for a more user-friendly interface. With this knowledge, you can now create your own chatbots and experiment with different system prompts and settings.