The Javascript SDK serves the purpose of sending explicit user actions and feedback to the Nebuly platform.
An example of these actions might be thumbs_up
, thumbs_down
, copy_input
, copy_output
.
You can only use the client-side SDK in conjunction with the server-side SDK. Please make sure to integrate a server-side SDK first and then complement it with a with a client-side one to track explicit user behavior.
Installation
npm i @nebuly-ai/javascript
Method 1: Automatic tracking
Some of the user actions can be automatically tracked from the UI elements.
User action | Description |
---|
Copy input | The user has copied either a portion or the entire input prompt |
Copy output | The user has copied either a portion or the entire answer of the LLM |
Paste to input | The user has pasted text into the input prompt |
Given this UI:
<div id="my-chat-box">
<input type="text" class="chatbox-input"/>
<div class="chatbox-user-prompt">
Hello, can you tell me how's the weather today ?
</div>
<div class="chatbox-response">
The weather is sunny today.
</div>
...
</div>
We can configure the sdk to attach listeners to the chatbox and automatically track actions
based on the event and the item it fired on.
import { NebulySdk } from '@nebuly-ai/javascript';
const sdk = new NebulySdk('nb-95xxxxxxxxxxxxxxxxxxxxxxxxxxx46c1', {
end_user: 'user-123',
});
const chatBox = document.getElementById('my-chat-box');
removeListeners = sdk.observeChat({
chatElement: chatBox,
userPromptSelector: '.chatbox-user-prompt',
responseSelector: '.chatbox-response',
inputSelector: '.chatbox-input'
});
removeListeners();
Method 2: Custom events
You can also create custom events to track to Nebuly. For example, if you have a button that generates a new response or thumbs up/down, you can track that action as follows:
import { NebulySdk } from '@nebuly-ai/javascript';
const nebuly = new NebulySdk('nb-95xxxxxxxxxxxxxxxxxxxxxxxxxxx46c1', {
end_user: 'user-123',
});
const interaction = {
input: "Hello, can you tell me how's the weather today ?",
output: "The weather is sunny today.",
}
nebuly.sendAction(
{
slug: 'thumbs_down',
text: 'user comment'
},
{
output: interaction.output,
input: interaction.input,
}
)
nebuly.sendAction({slug: 'regenerate'}, {
output: interaction.output,
input: interaction.input,
})
interaction.output = "The weather is rainy today."
nebuly.sendAction({slug: 'thumbs_up'}, {
output: interaction.output,
input: interaction.input,
})