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: 3.4.3

Installation

  1. Install the package:
python -m pip install justai
  1. Create an OpenAI acccount (for GPT3.5 / 4) here or an Anthropic account here
  2. Create an OpenAI api key (for Claude) here or an Anthropic api key here
  3. Create a .env file with the following content:
OPENAI_API_KEY=your-openai-api-key
OPENAI_ORGANIZATION=your-openai-organization-id
ANTHROPIC_API_KEY=your-anthropic-api-key

Usage

from justai import Agent

if __name__ == "__main__":
    agent = Agent('gpt-3.5-turbo')
    agent.system = "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.

Other models

Justai can use different types of models:

OpenAI models like GPT-3.5, GPT-4-turbo-preview
Anthropic models like claude-3-opus-20240229 and claude-3-sonnet-20240229
Open source models like Llama2-7b or Mixtral-8x7b-instruct as long as they are in the GGUF format.

The provider is chosen depending on the model name. E.g. if a model name starts with gpt, OpenAI is chosen as the provider. To use an open source model, just pass the full path to the .gguf file as the model name.

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-3.4.3.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

justai-3.4.3-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for justai-3.4.3.tar.gz
Algorithm Hash digest
SHA256 2943c63055bf0dc78578f9a51fa1314e1a259165e114b5fb12cf41643f75d72c
MD5 21363c219026a1489bb6df97d884c74f
BLAKE2b-256 e104d208df986253a8a61c9e2de372e36e4841f0fdafceb40c92b21f46d7c815

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for justai-3.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 160761c5bfb0e21f32c987ef197ecd17954f4a9007a486f5371171bb480c03a0
MD5 808d78f657a84647318708ff04cb31c1
BLAKE2b-256 9af48e7a8586facfb1b50cda513690a45c64779ecd089c3ff78b8c6f95f9ca51

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