Skip to main content

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 system message that your bot will act like.

from streambot import StreamBot

api_key = "YOUR_OPENAI_API_KEY"
bot_name = "MyBot"
genesis_prompt = "You are a helpful English to Spanish translator"

bot = StreamBot(api_key, bot_name, genesis_prompt)

Once you have created your bot, you can initiate output with the chat method. The chat method takes a list of messages managed within the StreamBot class as input and prints the stream of tokens as well as optionally returning a string containing the bot response into a variable.

The StreamBot constructor takes in an optional OpenAI URL (in case they change it) and an override for the Model value as they may change that in the near future as well. Also see below for additional configuration overrides as part of the StreamBotConfig you can pass in.

prompt = input("Me: ")
bot.add_message(prompt)
bot.chat()

You can also add messages to your bot's message history using the add_message method. The add_message method defaults the role to "user" if none is provided.

bot.add_message("Hello, how can I help you today?", role="assistant")
bot.add_message("Hi there!")
bot.add_message("What's your name?", role="assistant")

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=500)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streambot-1.1.9.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

streambot-1.1.9-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page