Python SDK Documentation

Introduction

The JamAI Python SDK provides a convenient way to interact with the JamAI API, allowing you to leverage various AI capabilities in your Python applications.

Getting Started

The recommended way of using JamAI Base is via Cloud 🚀. Did we mention that you can get free LLM tokens?

Cloud 🚀

  1. Create a project and give it any name that you want.

  2. Create a Python (>= 3.12) environment and install jamaibase (here we use micromamba but you can use other tools such as conda, virtualenv, etc):

    $ micromamba create -n jam311 python=3.11 -y
    $ micromamba activate jam311
    $ pip install jamaibase
  3. In your script, import the JamAI class and create an instance.

    from jamaibase import JamAI, types as t
    
    jamai = JamAI(token="your_pat", project_id="your_project_id")

    Async is supported too:

    from jamaibase import JamAIAsync, types as t
    
    jamai = JamAIAsync(token="your_pat", project_id="your_project_id")

Tips

project_id, api_key and api_base can all be changed in 3 ways (from highest priority to least priority):

  • Passing it as str argument

  • Specifying it as environment variable named JAMAI_PROJECT_ID, JAMAI_API_KEY and JAMAI_API_BASE respectively.

  • Specifying it in .env file as JAMAI_PROJECT_ID, JAMAI_API_KEY and JAMAI_API_BASE respectively.

Generative Tables (Basics)

There are 3 types of Generative Tables:

  • Action: For chaining LLM reasoning steps

  • Knowledge: For embedding external knowledge and files to power Retrieval Augmented Generation (RAG)

  • Chat: For LLM agents with LLM chaining capabilities

We will guide you through the steps of leveraging Generative Tables to unleash the full potential of LLMs.

Creating tables

Let's start with creating simple tables. Create a table by defining a schema.

When it comes to table names, there are some restrictions:

  • Must have at least 1 character and up to 100 characters

  • Must start and end with an alphabet or number

  • Middle characters can contain alphabets, numbers, underscores _, dashes -, dots .

Column names have almost the same restrictions, except that:

  • Spaces are accepted

  • Dots . are not accepted

  • Cannot be called "ID" or "Updated at" (case-insensitive)

Adding rows

Now that we have our tables, we can start adding rows to them and receive the LLM responses.

First let's try adding to Action Table:

Next let's try adding to Chat Table:

Finally we can add rows to Knowledge Table too:

[!TIP] Uploading files is the main way to add data into a Knowledge Table. Having said so, adding rows works too!

Retrieving rows

We can retrieve table rows by listing the rows or by fetching a specific row.

Retrieving columns

We can retrieve columns by filtering them.

Retrieval Augmented Generation (RAG)

We can also upload files to Knowledge Table for Retrieval Augmented Generation (RAG). This allows LLM to generate answers that are grounded in the provided context and data.

Retrieving tables

We can retrieve tables by listing the tables or by fetching a specific tables.

Deleting rows

Now that you know how to add rows into tables, let's see how to delete them instead.

Deleting tables

Let's see how to delete tables.

[!TIP] Deletion will return "OK" even if the table does not exist.

We can combine this with the table list method to delete all tables without having to specify their names:

Full script

The full script is as follows:

Generative Tables (Advanced)

Duplicating tables

We can create copies of tables under the same project. By default, the method copies over both table schema and its data, but we can choose to exclude data when duplicating.

Full script

See "Generative Tables (Basics)" section above.

Chat Completions

Generate chat completions using various models. Supports streaming and non-streaming modes.

Embeddings

Generate embeddings for given input text.

Model Information

Get Model Info

Retrieve information about available models.

Get Model IDs / Names

Get a list of available model IDs / names.

Examples

Streamlit Chat App

Let's try to make a simple chat app using Streamlit.

Last updated

Was this helpful?