Skip to main content

Makes working with OpenAI's GPT API and other LLM's super easy

Project description

JustAI

Package to make working with Large Language models in Python super easy.

Author: Hans-Peter Harmsen (hp@harmsen.nl)
Current version: 2.1.4

Installation

  1. Install the package:
python -m pip install justai
  1. Create an OpenAI acccount here
  2. Create OpenAI api keys here
  3. Create a .env file with the following content:
OPENAI_API_KEY=your-openai-api-key
OPENAI_ORGANIZATION=your-openai-organization-id

Usage

from justai import Agent

if __name__ == "__main__":
    agent = Agent('gpt-3.5-turbo')
    agent.system = lambda: "You are a movie critic. I feed you with movie titles and you give me a review in 50 words."

    message = agent.chat("Forrest Gump")
    print(message)

output

Forrest Gump is an American classic that tells the story of
a man with a kind heart and simple mind who experiences major
events in history. Tom Hanks gives an unforgettable performance, 
making us both laugh and cry. A heartwarming and nostalgic 
movie that still resonates with audiences today.

Using the examples

Install dependencies:

python -m pip install -r requirements.txt

Basic

python examples/basic.py

Starts an interactive session. In the session you dan chat with GPT-4 or another model.

Returning json

python examples/return_types.py

You can specify a specific return type (like a list of dicts) for the completion. This is useful when you want to extract structured data from the completion.

To define a return type, just pass return_json=True to agent.chat().

See the example code for more details.

Interactive

python examples/interactive.py

Starts an interactive session. In the session you dan chat with GPT-4 or another model.

Special commands

In the interactive mode you can use these special commands which each start with a colon:

Syntax Description
:reset resets the conversation
:load name loads the saved conversation with the specified name
:save name saves the conversation under the specified name
:input filename loads an input from the specified file
:model gpt-4 Sets the AI model
:max_tokens 800 The maximum number of tokens to generate in the completion
:temperature 0.9 What sampling temperature to use, between 0 and 2
:n 1 Specifies the number answers given
:stop ["\n", " Human:", " AI:"] Up to 4 sequences where the API will stop generating further tokens
:bye quits but saves the conversation first
:exit or :quit quits the program

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

justai-2.1.4.tar.gz (81.1 kB view details)

Uploaded Source

Built Distribution

justai-2.1.4-py3-none-any.whl (87.1 kB view details)

Uploaded Python 3

File details

Details for the file justai-2.1.4.tar.gz.

File metadata

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

File hashes

Hashes for justai-2.1.4.tar.gz
Algorithm Hash digest
SHA256 4f13c6c455ee051ce98966bb68e5512ca85e7ee51657c7dbbefad4b1607c18f6
MD5 fedb965c1413144c8237030b1ada3aad
BLAKE2b-256 8929544f6f51a1efd699458df70fc48428b6451253b63aa11282653f6f48b33d

See more details on using hashes here.

File details

Details for the file justai-2.1.4-py3-none-any.whl.

File metadata

  • Download URL: justai-2.1.4-py3-none-any.whl
  • Upload date:
  • Size: 87.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for justai-2.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 07de8be3d397ceb83da453dd69215573f1e554ac8f863b95532666e9e9e8851c
MD5 03ecb8f8718d17d1c1263ffeb23bbfbb
BLAKE2b-256 4a42bbbaee19af1be6e82fa6b3b36efba063cca0ce63766520bfb69f2882c678

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