Skip to main content

A base client for interacting with the OpenAI API and custom clients/mixins to make developing things like chatbots super quick!

Project description

OpenAI API Python Client

A (very rough WIP) base Python Client for OpenAI APIs and some concrete "stateful" clients for common operations like running a chatbot with context

Overview

Right now this just provides a base client that allows a reusable way to do common things (like loading the API key) plus some easy overrides (like which model to use) and some mixins for when state dependence is important.

Now this also includes some pre-built "recipe" clients:

Example

All I've got in lieu of real docs for now :). Run a local chatbot from your command line:

  1. Install this library as a PyPi package
pip install OpenAI-API-Python-Client
  1. Export your OpenAI API key in your shell environment
export OPENAI_API_KEY=AKIAIOSFODNN7EXAMPLE
  1. Use a recipe class to create apps!
# Import this library :)
from openai_client import Chat_Bot_Client

# Simple D&D chatbot app :)
if __name__ == "__main__":
    # API Key is read from OPENAI_API_KEY environmental variable
    client = Chat_Bot_Client()

    # Add a high level directives to guide the model
    client.add_directive("You are a Dungeons and Dragons Dungeon Master. Use the 5th edition of the Dungeons and Dragons Player Handbook, Dungeon Master Guide, and Monster Manual")
    client.add_directive("At the beginning of your chat with the user you will assist them in creating a character. This character will have a description and stats as outlined in the 5th edition of the Dungeons and Dragons Player Handbook.")
    client.add_directive("Let the user choose race and class before assigning a personality, stats, and starting inventory. Provide the user with a list of races and classes they can be. Tell the user they can ask for more details about a class or race")
    client.add_directive("Once you introduce the character, give the player the start of an adventure campaign and ask the player what they would like to do")
    client.add_directive("As outlined in the handbook, if a roll is necessary based on the situation, roll for the user")
    client.add_directive("Finish by asking the player what they'd like to do next")

    # Simple loop to run a chat session
    while True:
        # Send it to the chatbot and get the response
        response = client.run_prompt()
        # Print the response
        print("\n" + response + "\n")
        # Get question from the user
        client.get_user_input()
  1. Use Mixins and the base class to create new "stateful" clients on top of the base client. See the implementation of Chat_Bot_Client for an example

Contributing

Contributions are welcome! Please not the following when contributing:

  • Unittests must be added under the tests/ directory for the PR to be approved. You can run unittests from the root project directory with the following command:

    python setup.py test
    
  • PRs cannot be merged without all unittests passing (they will execute automatically)

  • Merges to main will automatically create a new release on PyPi unless it is from a forked Repo

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

OpenAI API Python Client-1.0.3.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

OpenAI_API_Python_Client-1.0.3-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file OpenAI API Python Client-1.0.3.tar.gz.

File metadata

File hashes

Hashes for OpenAI API Python Client-1.0.3.tar.gz
Algorithm Hash digest
SHA256 dcde3851325e2975afb5764dda891b7e130769f34abf586e4b73dda6819417cb
MD5 ee29464bdf5d07cc28e2455393381e5a
BLAKE2b-256 80ba66ac8257921e1c0e4d0d8bc0925f82991b902ad5baa0e9192a0bf14abab5

See more details on using hashes here.

File details

Details for the file OpenAI_API_Python_Client-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for OpenAI_API_Python_Client-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eb360d453f037327cc6dce111ea160603ec0f8584fde93a1dde80568351c9b52
MD5 4fb3b5594b5ee9aaeb885d29534170de
BLAKE2b-256 5ff9391138c4baec4ffb88451a0213d97ed9da1b8ced06ab09a52ab550d2ff27

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