- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback
We provide a ready to use SDK library for the Platform API in NodeJS
Installation
npm install @unleash-tech/platform-sdk
Quickstart
The following sample code will perform a search and chat query on behalf of “myuser” using a specified assistant.
var unleash = require('@unleash-tech/platform-sdk')
var client =
new unleash.ApiClient({
token:'<api-key>',
// OPTIONAL: only needed for impersonating api keys
account:'myuser@acme.com'
// OPTIONAL: only needed for private/self hosted env
tenant: 'https://unleash.acme.com/'
});
var assistant = client.assistants.withId('<assistant-id>');
// SEARCH
var searchResponse = await assistant.search({
query:'my notion page',
filters:{appId:['notion']}
}}
console.log(`Found ${searchResponse.totalResults} results`);
for ( let r of searchResponse.result )
console.log(searchResponse.result.resource.name);
// CHAT blocking-mode
var chatResponse = await assistant.chat({
messages:[{role:'User',text:'how to use go links'}]
}).complete();
console.log(chatResponse.message);
// CHAT streaming-mode
var chatResponse = await assistant.chat({
messages:[{role:'User',text:'how to use go links'}]
}).stream();
for await ( let event of chatResponse)
console.log(event);
Was this article helpful?