Skip to main content

A simple GPT interface

Project description

ezgpt

ezgpt is a Python library designed to simplify the interaction with OpenAI's GPT (Generative Pre-trained Transformer) models. It provides a convenient interface for sending prompts to the model and receiving responses, with optional logging for debugging purposes.

Installation

You can install ezgpt via pip:

pip install ezgpt

Usage

To use ezgpt, you need to have an API key from OpenAI. This key must be set as an environment variable OpenAI_APIKey before using the library.

Initialization

First, import the ezgpt module and initialize the gpt class:

import ezgpt

gpt = ezgpt.gpt()

The gpt class constructor accepts the following parameters:

  • model: The identifier of the GPT model to use (default: 'gpt-3.5-turbo').
  • system: An optional system-level prompt that provides instructions or context for the GPT model.
  • temperature: Controls randomness in the response generation (default: 0).
  • top_p: Controls diversity of the response generation (default: 0).
  • max_tokens: The maximum number of tokens to generate in the response (default: 2048).
  • frequency_penalty: Decreases the likelihood of repetition in the response (default: 0).
  • presence_penalty: Encourages the model to talk about new topics (default: 0).
  • logs: Enables or disables logging of the interaction (default: False).

Sending Prompts

To send a prompt to the GPT model, use the get method of the gpt instance:

response = gpt.get(user="Your prompt here")

The get method accepts the following parameters:

  • system: Overrides the system-level prompt for this request.
  • user: The user-level prompt to send to the model.
  • messages: A list of previous message exchanges to maintain context.
  • temperature: Overrides the default temperature for this request.
  • top_p: Overrides the default top_p for this request.
  • max_tokens: Overrides the default max_tokens for this request.
  • frequency_penalty: Overrides the default frequency_penalty for this request.
  • presence_penalty: Overrides the default presence_penalty for this request.

Since your last request is stored under self.previous, you can append a message to your conversation like that:

response = gpt.get(messages=gpt.previous, user="Another message")

Logging

If logging is enabled, ezgpt will print the interaction with the GPT model to the console. This includes the prompts sent by the user and system, as well as the responses from the assistant.

Notes

  • The ezgpt library assumes that the OpenAI API key is set in the environment variable OpenAI_APIKey.
  • The gpt class maintains a history of the conversation in the previous attribute, which can be used to provide context for subsequent requests.

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

ezgpt-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

ezgpt-0.1.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file ezgpt-0.1.2.tar.gz.

File metadata

  • Download URL: ezgpt-0.1.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for ezgpt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 edac84d4c12c2b99b04c3bd58447aa0c589acb5e293c09cac52304d38aeb31f4
MD5 e30c45193c24259883b1ecc0ed2d2415
BLAKE2b-256 4f60e883788678d069965d6af95321cdd42292af439d326dab9ebec58650777e

See more details on using hashes here.

File details

Details for the file ezgpt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ezgpt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for ezgpt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8699782d9cc690db9bf8d8d43312736329606cb3c97d870d2a030cca618e1411
MD5 5d7a0721aab27917404e04c64b7a9bc5
BLAKE2b-256 d4e0e3e2e687d4595411c1a45069cb1de8deda8d2aa89ac7f9c1363ad65db1e6

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