0.1.6 • Published 1 year ago

jamai v0.1.6

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

Introduction

This is a TS/JS Client Library for JamAIBase.

There are three types of LLM powered database tables (GenTable):

  • Action Table
  • Chat Table
  • Knowledge Table

Installation

npm install jamai@latest

Usage

Create API Client

Create an API client with baseURL:

import JamAI from "jamai";

const jamai = new JamAI({ baseURL: "http://localhost:5173/" });

Create an API client with api key and project id:

import JamAI from "jamai";

const jamai = new JamAI({ apiKey: "jamai_apikey", projectId: "proj_id" });

Create an API client with custom HTTP client:

import axios from "axios";
import JamAI from "jamai";

const username = "user";
const password = "password";

const credentials = Buffer.from(`${username}:${password}`).toString("base64");

const httpClient = axios.create({
    headers: {
        Authorization: `Basic ${credentials}`,
        "Content-Type": "application/json",
    },
});

const jamai = new JamAI({
    baseURL: "https://app.jamaibase.com",
    httpClient: httpClient,
});

Create an API client with basic authorization credentials:

import JamAI from "jamai";

const jamai = new JamAI({
    baseURL: "https://app.jamaibase.com",
    credentials: {
        username: "your-username",
        password: "your-password",
    },
});

Create an API client with maxretry and timeout:

import JamAI from "jamai";

const jamai = new JamAI({
    baseURL: "https://app.jamaibase.com",
    maxRetries: 3,
    timeout: 500,
});

Configure httpAgent/ httpsAgent:

import JamAI from "jamai";

const jamai = new JamAI({
    baseURL: "https://app.jamaibase.com",
});

jamai.setHttpagentConfig({
    maxSockets: 100,
    maxFreeSockets: 10,
    freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
});

Can be imported from different modules depending on the need:

import JamAI from "jamai/index.umd.js";

Types

Types can be imported from resources:

import { ChatRequest } from "jamai/resources/llm/chat";

let response: ChatRequest;

Use client object to call the methods

Example of adding a row to action table:

try {
    const response = await jamai.addRow({
        table_type: "action",
        table_id: "workout-suggestion",
        data: {
            age: 30,
            height_in_centimeters: 170,
            weight_in_kg: 60,
        },
    });
    console.log("response: ", response);
} catch (err) {
    console.error(err.message);
}

Example of adding row with streaming output

try {
    const stream = await jamai.addRowStream({
        table_type: "action",
        table_id: "action-table-example-1",
        data: {
            Name: "Albert Eistein",
        },
    });

    const reader = stream.getReader();

    while (true) {
        const { done, value } = await reader.read();
        if (done) {
            console.log("Done");
            break;
        }
        console.log(value);
        if (value) {
            console.log(value?.choices[0]?.message.content);
        }
    }
} catch (err) {}

Constructor Parameters for APIClient Configuration

ParameterTypeDescriptionDefault ValueRequired / Optional
baseURLstringBase URL for the API requests.https://app.jamaibase.comoptional
maxRetriesnumberMaximum number of retries for failed requests.0Optional
httpClientAxiosInstanceAxios instance for making HTTP requests.AxiosInstanceOptional
timeoutnumber \| undefinedTimeout for the requests.undefinedOptional
apiKeystring \| undefinedapiKey.undefinedRqruired if accessing cloud
projectIdstring \| undefinedprojectId.undefinedOptional if accessing cloud
0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago