Skip to main content

A Python package for creating simple AI Agents using the OpenAI API.

Project description

jAIms

My name is Bot, jAIMs Bot. 🕶️

jAIms is a lightweight Python framework built on top of the OpenAI library that lets you create powerful LLM agents. It is designed with simplicity and ease of use in mind and only depends on openai and tiktoken.

Installation

pip install jaims-py

👨‍💻 Usage

Building an agent is as simple as this:

from jaims import JAImsAgent

agent = JAImsAgent()

response = agent.run([
    {
        "role": "user",
        "content": "Hi!"
    }
])

print(response)

The parameters accepted by the run method are those specified in the official OpenAI docs.

⚙️ Functions

Of course, an agent is just a chatbot if it doesn't support functions. jAIms uses the built-in OpenAI function feature to call functions you pass to it. Here's an example where we create a simple sum function and make a simple agent that lets you sum two numbers:

import jaims


def sum(a: int, b: int):
    return a + b

# this is a class that wraps your function, it will 
# receive the actual function plus all the info required 
# by the llm to invoke it.
func_wrapper = JAImsFuncWrapper(
    function=sum, 
    name="sum", 
    description="use this function when the user wants to sum two numbers",
    params_descriptors=[
        JAImsParamDescriptor(
            name="a",
            description="first operand",
            json_type=JAImsJsonSchemaType.NUMBER,
        ),
        JAImsParamDescriptor(
            name="b",
            description="second operand",
            json_type=JAImsJsonSchemaType.NUMBER,
        ),
    ],
)

# instantiate the agent passing the functions
agent = JAImsAgent(
    functions=[func_wrapper],
    model=JAImsGPTModel.GPT_3_5_TURBO_16K,
)

# a simple loop that simulates a chatbot
while True:
    user_input = input("> ")
    if user_input == "exit":
        break
    response = agent.run(
        [{"role": "user", "content": user_input}],
        stream=True,
    )

    for chunk in response:
        print(chunk, end="", flush=True)
        
        print("\n")

✨ Other features

  • Complete control over openai call parameters (temperature, top_p, n, max_tokens, etc.)
  • Automatic chat history management
  • Configuration of the OpenAI model to use
  • Injectable prompt to shape agent behavior
  • Safety checks to prevent the agent from endlessly looping over function calls

I will routinely update the examples to demonstrate more advanced features. Also, I've made sure to document the code as best as I can; everything should be self-explanatory; I plan to add a proper documentation in the future if this project gets enough traction.

🤖 Supported models

Currently, jAIms supports the new OpenAI models with functions enabled, specifically:

  • gpt-3.5-turbo-0613
  • gpt-3.5-turbo-16k-0613
  • gpt-4-0613

I'm not planning to add support for non-OpenAI models at the moment, but contributions are always appreciated.

⚠️ Project status

This is a work in progress. I still need to write some tests and add many features, but the core functionality is there. I'm creating this framework because I need a lightweight and easy-to-use framework to create LLM agents. This project may not be as advanced as tools like langchain and others, but if you need a simple tool to create agents based on the OpenAI API, you might find jAIms useful.

TODOS:

  • Add tests
  • Add more examples
  • Add more chat history optimization strategies
  • Add function calling callbacks
  • Add history persistance

📝 License

The license will be MIT, but I need to add this properly.

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

jaims-py-1.0.0b4.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

jaims_py-1.0.0b4-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file jaims-py-1.0.0b4.tar.gz.

File metadata

  • Download URL: jaims-py-1.0.0b4.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for jaims-py-1.0.0b4.tar.gz
Algorithm Hash digest
SHA256 713a8afcf671ec80fe0b0f582665f68e6cf41a2e5d37e991ba2ac0c4bf0f10af
MD5 62aa801534fbc744a9999e654ca3e9fc
BLAKE2b-256 5eaecd39f58a2dd5b25bfa16d2c3439c250d9df53e45ad9b648b584e52a58b5a

See more details on using hashes here.

File details

Details for the file jaims_py-1.0.0b4-py3-none-any.whl.

File metadata

  • Download URL: jaims_py-1.0.0b4-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for jaims_py-1.0.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 70720064a118f8ba1d1c73dea9671fb34371f5987d6f664bc6df226e60bbd950
MD5 c6a99d67f7801a61b0c142de4bb59b69
BLAKE2b-256 85f523cab355c5675c95b1321c2de0f275a3bb21b5a702bcb0d5f48bf8618cd5

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