JamAI Base Docs
  • GETTING STARTED
    • Welcome to JamAI Base
      • Why Choose JamAI Base?
      • Key Features
      • Architecture
    • Use Case
      • Chatbot (Frontend Only)
      • Chatbot
      • Create a simple food recommender with JamAI and Flutter
      • Create a simple fitness planner app with JamAI and Next.js with streaming text.
      • Customer Service Chatbot
      • Women Clothing Reviews Analysis Dashboard
      • Geological Survey Investigation Report Generation
      • Medical Insurance Underwriting Automation
      • Medical Records Extraction
    • Frequently Asked Questions (FAQ)
    • Quick Start
      • Quick Start with Chat Table
      • Quick Start: Action Table (Multimodal)
      • ReactJS
      • Next JS
      • SvelteKit
      • Nuxt
      • NLUX (Frontend Only)
      • NLUX + Express.js
  • Using The Platform
    • Action Table
    • Chat Table
    • Knowledge Table
    • Supported Models
      • Which LLM Should You Choose?
      • Comparative Analysis of Large Language Models in Vision Tasks
    • Roadmap
  • 🦉API
    • OpenAPI
    • TS/JS SDK
  • 🦅SDK
    • Flutter
    • TS/JS
    • Python SDK Documentation
      • Quick Start with Chat Table
      • Quick Start: Action Table (Mutimodal)
        • Action Table - Image
        • Action Table - Audio
      • Quick Start: Knowledge Table File Upload
Powered by GitBook
On this page
  • Installation
  • Usage
  • Create API Client
  • Types
  • Using the Client
  • Constructor Parameters for APIClient Configuration
  • Quick Start Guide
  • SDK

Was this helpful?

  1. SDK

TS/JS

PreviousFlutterNextPython SDK Documentation

Last updated 11 months ago

Was this helpful?

Installation

$ npm install jamaibase@latest

Usage

Create API Client

Create an API client with baseURL:

import JamAI from "jamaibase";

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

Create an API client with API key and project id:

import JamAI from "jamaibase";

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

The default base URL is set to

Create an API client with custom HTTP client:

import axios from "axios";
import JamAI from "jamaibase";

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

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

Create an API client with max-retry and timeout:

import JamAI from "jamaibase";

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

Configure httpAgent / httpsAgent

import JamAI from "jamaibase";

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

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

Imports

Can be imported from different modules depending on the need:

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

Types

Types can be imported from resources:

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

let response: ChatRequest;

Using the Client

Example of adding a row to an action table:

try {
        let data = await jamai.addRow({
            table_type: "action",
            data: [
                {
                    age: 22,
                    height: 178,
                    weight: 66.5,
                    sex: male,
                    preferred_body_type: lean,
                },
            ],
            table_id: "fitness_planner",
            reindex: null,
        });

        console.log(data)
    } catch (error: any) {
        console.error("Error fetching data:", error?.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

Parameter
Type
Description
Default Value
Required

baseURL

string

Base URL for the API request.

false

maxRetries

number

Maximum number of retries for failed requests.

0

false

httpClient

AxiosInstance

Axios instance for making HTTP requests.

AxiosInstance

false

timeout

number | undefined

Timeout for the requests.

undefined

false

apiKey

string | undefined

apiKey.

undefined

required if accessing cloud

projectId

string | undefined

projectId.

undefined

required if accessing cloud

dangerouslyAllowBrowser

boolean

Allowing the insecure usage of JamAI API Key on client side.

false

false

Quick Start Guide

SDK

Go to our section to integrate JamAI into your favorite framework.

The complete SDK Documentation link can be found at TS/JS

🦅
http://api.jamaibase.com/
quick start
https://embeddedllm.github.io/jamaibase-ts-docs/
http://api.jamaibase.com/