Skip to main content

A simple interface for using the GPT API.

Project description

gpt_interface

A simple interface for using the GPT API.

API Key

To use gpt_interface, you need an OpenAI API key (https://platform.openai.com/docs/api-reference/authentication).

I recommend creating a .env file and adding it to your .gitignore file. The file would contain the following:

OPENAI_API_KEY=sk-exampleKey

Simple Usage

from dotenv import load_dotenv
import os
from pathlib import Path

from gpt_interface import GptInterface


if __name__ == "__main__":
    load_dotenv()  # load the OpenAI API key from a .env file
    interface = GptInterface(  # create interface
        openai_api_key=os.getenv("OPENAI_API_KEY"),
        model="gpt-3.5-turbo",
    )
    interface.say("Hi! My name is Matt")  # talk to GPT
    response = interface.say("What's my name?")  # conversation log is stored in memory
    assert "Matt" in response
    print(interface.log)  # can print logs
    current_path = Path(__name__).parent.absolute()
    interface.log.save(current_path / "my_log.json")  # can save or load logs
    interface.log.load(current_path / "my_log.json")

The log from the example above would look something like this:

[
    {
        "role": "user",
        "content": "Hi! My name is Matt"
    },
    {
        "role": "assistant",
        "content": "Hello Matt! How can I assist you today?"
    },
    {
        "role": "user",
        "content": "What's my name?"
    },
    {
        "role": "assistant",
        "content": "Your name is Matt!"
    }
]

Advanced Examples

See the examples/ folder to see more details about how to use the interface.

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

py_gpt_interface-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

py_gpt_interface-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file py_gpt_interface-0.1.0.tar.gz.

File metadata

  • Download URL: py_gpt_interface-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for py_gpt_interface-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f36c19316d975a382982ebb99336311d537c1ebad5beccb49a456dd0702a2779
MD5 6b5feb2d16027a2aeb8d85f6e9bba25e
BLAKE2b-256 60a14710095788e3a6c79744aaa0f0ab13da11c08d49646e384cd78e36ca1ea3

See more details on using hashes here.

File details

Details for the file py_gpt_interface-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_gpt_interface-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2460412ad8d2aef4e76a8a22f0b3e5f63b346a344d836337356be223cb7ac819
MD5 0c8fab8ede9936f37c357043d0be29fe
BLAKE2b-256 0056949bd5ba9a2a8fa52aa9e6ab91bbd764e8a91022a1ec2a9a2d68a9be6f89

See more details on using hashes here.

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