0.1.6 • Published 1 year ago
jamai v0.1.6
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
Parameter | Type | Description | Default Value | Required / Optional |
---|---|---|---|---|
baseURL | string | Base URL for the API requests. | https://app.jamaibase.com | optional |
maxRetries | number | Maximum number of retries for failed requests. | 0 | Optional |
httpClient | AxiosInstance | Axios instance for making HTTP requests. | AxiosInstance | Optional |
timeout | number \| undefined | Timeout for the requests. | undefined | Optional |
apiKey | string \| undefined | apiKey. | undefined | Rqruired if accessing cloud |
projectId | string \| undefined | projectId. | undefined | Optional if accessing cloud |