An OpenAI ChatGPT wrapper to simplify streaming of token responses to give the writing effect.
Project description
StreamBot
StreamBot is a Python package that allows you to create a chatbot that uses OpenAI's GPT-3 API to generate responses in real-time.
Installation
To install StreamBot, simply run:
pip install streambot
Usage
To create a StreamBot, you'll need to provide an OpenAI API key, a name for your bot, and a "genesis prompt" - the initial message that your bot will respond to.
from streambot import StreamBot
api_key = "YOUR_OPENAI_API_KEY"
bot_name = "MyBot"
genesis_prompt = "Hello, how can I help you today?"
bot = StreamBot(api_key, bot_name, genesis_prompt)
Once you have created your bot, you can start chatting with it using the chat method. The chat method takes a list of messages as input and returns a string containing the bot response.
response = bot.chat(["Hi there!", "What's your name?"])
print(response)
You can also add messages to your bot's message history using the add_message method.
bot.add_message("Hello, how can I help you today?", role="system")
bot.add_message("Hi there!", role="user")
bot.add_message("What's your name?", role="user")
Configuration
StreamBot also allows you to configure various settings for your bot, such as the temperature and maximum number of tokens used by the GPT-3 API. To do this, you can create a StreamBotConfig object and pass it to the StreamBot constructor.
from streambot import StreamBot, StreamBotConfig
api_key = "YOUR_OPENAI_API_KEY"
bot_name = "MyBot"
genesis_prompt = "Hello, how can I help you today?"
config = StreamBotConfig(temperature=0.5, max_tokens=50)
bot = StreamBot(api_key, bot_name, genesis_prompt, config=config)
Contributing
If you'd like to contribute to StreamBot, please feel free to submit a pull request or open an issue on the GitHub repository.
License
StreamBot is licensed under the MIT License. See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for streambot-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81b565dcb87ca0787f46ed452c759daad5045e8d8094c4863a635b4e11de24f1 |
|
MD5 | 98f9566e9c7718e01c7f1f281ce7190f |
|
BLAKE2b-256 | 71b50910efc4d19c4fb32e5f29a3c0747e6310241c20c3da23c7458ad2de46f3 |