Javascript SDK
Our Javascript SDK makes it straightforward to integrate with Context.ai.
Install the Context Javascript SDK with NPM:
npm install @contextco/context-node
The Javascript SDK needs to be authenticated with your Context.ai API Key. You can generate this key from the onboarding page (if you have not yet sent any transcripts to Context.ai), or from the settings page if you are already integrated.
Once you have your API key, you can start sending requests immediately using one of the example code snippets below. The SDK is usable in Javascript and Typescript applications.
import { ContextAPI, ContextAPIOptionalParams, KnownMessageRole, Credential } from "@contextco/context-node";
const options: ContextAPIOptionalParams = {
credential: new Credential(process.env.CONTEXT_TOKEN),
};
const c = new ContextAPI(options);
await c.log.conversation({
body: {
conversation: {
messages: [
{ message: "You are a helpful assistant.", role: KnownMessageRole.System, rating: 0 },
{ message: "Hi, how are you doing?", role: KnownMessageRole.User, rating: 0 },
{ message: "I'm doing super well, how are you?", role: KnownMessageRole.Assistant, rating: 1 }
],
}
}
})
await c.log.conversationUpsert({
body: {
conversation: {
messages: [
{ message: "You are a helpful assistant.", role: KnownMessageRole.System, rating: 0 },
{ message: "Hi, how are you doing?", role: KnownMessageRole.User, rating: 0 },
{ message: "I'm doing super well, how are you?", role: KnownMessageRole.Assistant, rating: 1 },
{ message: "Yeah, I'm doing well thanks.", role: KnownMessageRole.User, rating: 0 }
],
}
}
})
import { ContextAPI, KnownMessageRole, Credential } from "@contextco/context-node";
const options = {
credential: new Credential(process.env.CONTEXT_TOKEN),
};
const c = new ContextAPI(options);
await c.log.conversation({
body: {
conversation: {
messages: [
{ message: "You are a helpful assistant.", role: KnownMessageRole.System, rating: 0 },
{ message: "Hi, how are you doing?", role: KnownMessageRole.User, rating: 0 },
{ message: "I'm doing super well, how are you?", role: KnownMessageRole.Assistant, rating: 1 }
],
}
}
})
Last modified 12d ago