Getting started
This guide will instruct you through setting up Invsy in your project.
The Invsy SDK provides a predictable and intuitive interface for interacting with the Invsy API. This guide will instruct you through setting up Invsy, creating and storing a chat.
Installation
Install the SDK with npm, pnpm, yarn..
npm add invsy
Create client
To begin, import the Invsy class. You can create a reusable client by defining a const/function that takes environment variables as input and returns a new instance of the Invsy class. This approach encapsulates the client logic and makes it easy to reuse across your application.
Check out the guides on using environment variables for different frameworks.
import { Invsy } from "invsy"
export const invsy = new Invsy({
token: 'INVSY_API_KEY',
projectId: 'INVSY_PROJECT_ID',
userId: "user1"
})
Create a chat
To create a chat, you can use the create
method. This method takes optional chat meta as input and returns a promise that resolves to the created chat object.
const { id } = await invsy.create({
title: 'My first chat'
})
Save the chat
To save the chat, you can use the save
method. This method takes a chat object as input and returns a promise that resolves to the stored chat object.
const messages = [
{
role: 'user',
content: 'Hello!'
}, {
role: 'assistant',
content: 'Hello, welcome to Invsy!'
}
];
// Update meta title, use the first message as the chat title
const title = chat.messages[0].content.substring(0, 100);
const updatedChat = await invsy.save({
meta: {
title
},
messages
});
Get a chat
To get a chat, you can use the get
method. This method takes a chat ID as input and returns a promise that resolves to the chat object.
const chat = await invsy.get(id)