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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file streambot-1.1.9.tar.gz.

File metadata

  • Download URL: streambot-1.1.9.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.10.10 Windows/10

File hashes

Hashes for streambot-1.1.9.tar.gz
Algorithm Hash digest
SHA256 fe33fb118a69a910bcac5f0e44dfe21f9c3980a8395dad896e1eb20fba10c109
MD5 caea539c87ea9532653bee8693120e26
BLAKE2b-256 3a5ad6ac8bf934a9344e1059d71ccf00706732e1ac6496539a8f0c3a3fd58578

See more details on using hashes here.

File details

Details for the file streambot-1.1.9-py3-none-any.whl.

File metadata

  • Download URL: streambot-1.1.9-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.10.10 Windows/10

File hashes

Hashes for streambot-1.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5fe73144f1cbb4820efa53e3bb839e36d2fe5d31dc95ee6061f924f80d67d9cf
MD5 fd97deecbdd7dfd11cbd28e437e6500c
BLAKE2b-256 17fa31affecb922391e0695d520030ae0a26da1c5a6baf3c33bd54a3769b5d44

See more details on using hashes here.

Supported by

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