superstorm-dev-sdk
v0.23.0
Published
This sdk is used to train and invoke AI models. Please visit [superstorm.dev](https://superstorm.dev) for more information.
Downloads
35
Readme
Super Storm SDK
This sdk is used to train and invoke AI models. Please visit superstorm.dev for more information.
Installation
Using npm:
npm install superstorm-dev-sdk
Using yarn:
yarn add superstorm-dev-sdk
Usage
import SuperStormSdk from 'superstorm-dev-sdk';
const superStormSdk = new SuperStormSdk('<Your API Key>');
1. Text to image
To train a text to image model you can use trainTextToImgModel
:
// File[]: Photos used to train a text to images model
const images = [];
const formData = new FormData();
formData.append('prompt', 'A photo of a cute cjw cat');
formData.append('name', 'default name');
formData.append('token', 'cjw');
formData.append('onTrainedWebhook', 'https://mywebsite.com/trained');
formData.append('onInvokedWebhook', 'https://mywebsite.com/invoked');
images.forEach((image) => formData.append('images', image));
const newProject = await superStormSdk.trainTextToImgModel(formData);
console.log(newProject)
// console.log
{
"data": {
"project": {
"deployMode": "ASYNC",
"id": "<Your project Id>",
"modelType": "TEXT_TO_IMG",
"name": "a project name",
"projectMetadata": {
"prompt": "A photo of xyz dog",
"token": "xyz",
"images": [
{
"url": "https://url-to-img-0",
"filename": "0.jpg"
},
{
"url": "https://url-to-img-1",
"filename": "1.jpg"
},
{
"url": "https://url-to-img-2",
"filename": "2.jpg"
},
{
"url": "https://url-to-img-3",
"filename": "3.jpg"
}
]
}
}
},
"status": 200,
"success": true
}
After receiving model trained status you can start invoking your project:
const request = await superStormSdk.invokeModel('<Your project Id>', {
prompt: 'A photo of xyz dog flying'
});
console.log(request)
// console.log
{
"data": {
"newRequest": {
"createdAt": "1683548162635",
"id": "d9bca1d5-e302-4046-8fba-4c420390664a-911416",
"requestPayload": {
"prompt": "A photo of xyz dog flying"
},
"rstatus": "pending"
}
},
"status": 200,
"success": true
}
After receiving a request success status you can view your project to get the generated image(s):
const project = await superStormSdk.getProject('<Your project Id>');
console.log(project);
// console.log
{
"data": {
"project": {
"deployMode": "ASYNC",
"id": "d9bca1d5-e302-4046-8fba-4c420390664a",
"modelType": "TEXT_TO_IMG",
"name": "a project name",
"projectMetadata": {
"images": [
{
"url": "https://url-to-img-0",
"filename": "0.jpg"
},
{
"url": "https://url-to-img-1",
"filename": "1.jpg"
},
{
"url": "https://url-to-img-2",
"filename": "2.jpg"
},
{
"url": "https://url-to-img-3",
"filename": "3.jpg"
}
],
"prompt": "A photo of xyz dog",
"token": "xyz"
},
"pstatus": "DEPLOYED",
"requests": [
{
"id":"9b10b4bb-5dc1-4bfe-b5ba-52b8c2565abc-255945",
"createdAt": "1683548162635",
"images": [
"https://url-to-generated-request-photo"
],
"requestPayload": {
"prompt": "A photo of xyz dog flying"
},
"rstatus": "success"
}
]
}
},
"status": 200,
"success": true
}
You can view all your projects:
const projects = await superStormSdk.getProjects();
console.log(projects)
// console.log
{
"data": {
"projects": [
{
"deployMode": "ASYNC",
"modelType": "TEXT_TO_IMG",
"name": "a project name",
"projectMetadata": {
"images": [
{
"url": "https://url-to-img-0",
"filename": "0.jpg"
},
{
"url": "https://url-to-img-1",
"filename": "1.jpg"
},
{
"url": "https://url-to-img-2",
"filename": "2.jpg"
},
{
"url": "https://url-to-img-3",
"filename": "3.jpg"
}
],
"prompt": "A photo of xyz dog",
"token": "xyz"
},
"pstatus": "DEPLOYED",
"requests": [
{
"createdAt": "1683548162635",
"images": [
"https://url-generated-img"
],
"requestPayload": {
"prompt": "A photo of xyz dog flying"
},
"rstatus": "success"
}
]
}
]
},
"status": 200,
"success": true
}
To get all requests by project:
const requests = await superStormSdk.getRequests('<Your project id>')
console.log(requests)
//console.log
{
"data": {
"requests": [
{
"id":"9b10b4bb-5dc1-4bfe-b5ba-52b8c2565abc-255945",
"createdAt": "1683548162635",
"images": [
"https://url-to-generated-request-photo"
],
"requestPayload": {
"prompt": "A photo of xyz dog flying"
},
"rstatus": "success"
}
]
},
"status": 200,
"success": true
}
To get request by id:
const request = await superStormSdk.getRequests('<Your project id>', '<Your request id>')
console.log(request)
// console.log
{
"data": {
"request": {
"id":"9b10b4bb-5dc1-4bfe-b5ba-52b8c2565abc-255945",
"createdAt": "1683548162635",
"images": [
"https://url-to-generated-request-photo"
],
"requestPayload": {
"prompt": "A photo of xyz dog flying"
},
"rstatus": "success"
}
},
"status": 200,
"success": true
}
2. Chatbot
To train a chatbot model you can use trainChatBotModel
:
const project = await superStormSdk.trainChatBotModel({
name: 'My cool chatbot'
companyName: 'WYZ Company',
botName: 'Alpha bot',
dontKnowMsg: "Sorry, i don't know",
temperature: 0.75, // Very creative
toneVoice: 'helpful',
onTrainedWebhook: 'https://mywebsite.com/trained'
articles: [
{
title: 'New to AI',
body: 'A very long article used to train the chatbot on a subject'
},
{
title: 'How to schedule a daily meet',
body: 'To schedule a daily meet you should connect via your portal etc.'
}
]
})
console.log(project)
//console.log
{
"data": {
"project": {
"deployMode": "SERVERLESS",
"id": "d9bca1d5-e302-4046-8fba-4c420390664a",
"modelType": "CHAT",
"name": "My cool chatbot",
"projectMetadata": {
"companyName":"WYZ Company",
"botName": "Alpha bot",
"dontKnowMsg": "Sorry, i don't know",
"temperature": 0.75,
"toneVoice": "helpful",
"articles": [
{
"title": "New to AI",
"body": "A very long article used to train the chatbot on a subject"
},
{
"title": "How to schedule a daily meet",
"body": "To schedule a daily meet you should connect via your portal etc."
}
]
},
"pstatus": "",
"requests": []
}
},
"status": 200,
"success": true
}
After receiving a model deployed status you can start invoking your chatbot:
const response = await superStormSdk.invokeModel('<Your project Id>', {
input:"How to schedule a daily"
}
);
console.log(response)
//console.log
{
"data":{
"predictions":[
"To schedule a meet you should connect via your portal ..."
]
},
"status": 200,
"success": true
}
3. Document Summarize
To train a document summarize model you can use trainDocSumModel
:
const project = await superStormSdk.trainDocSumModel({
name: "Doc summarize"
})
console.log(project)
//console.log
{
"data": {
"project": {
"deployMode": "ASYNC",
"id": "d9bca1d5-e302-4046-8fba-4c420390664a",
"modelType": "DOCUMENT_SUMMARIZE",
"name": "Doc summarize"
"pstatus": "",
"requests": []
}
},
"status": 200,
"success": true
}
After receiving a model deployed status you can start invoking your doc summarize model:
const form = new FormData()
// You can use text field
form.append("text", "A very long text to read...")
// Or a file
form.append("file", fileToUpload)
const response = await superStormSdk.invokeModel('<Your project Id>', form);
console.log(response)
//console.log
{
"data": {
"newRequest": {
"id": "bab77a9e-dd93-4f32-9091-cc828e514023-484584",
"createdAt": "1685005319788",
"rstatus": "pending",
"images": [],
"requestPayload": {
"file": "fileUploaded.pdf"
},
"discussionId": "",
"output": "",
"inputLocation": "s3://super-storm-app-requests-dev/bab77a9e-dd93-4f32-9091-cc828e514023/bab77a9e-dd93-4f32-9091-cc828e514023-484584"
}
},
"success": true,
"status": 200
}
4. Speech to text
To train a speech to text model you can use trainSpeechToTextModel
:
const project = await superStormSdk.trainDocSumModel({
name: "Speech to text"
})
console.log(project)
//console.log
{
"data": {
"project": {
"deployMode": "ASYNC",
"id": "d9bca1d5-e302-4046-8fba-4c420390664a",
"modelType": "SPEECH_TO_TEXT",
"name": "Speech to text",
"pstatus": "TRAINING",
"requests": []
}
},
"status": 200,
"success": true
}
After receiving a model deployed status you can start invoking your speech to text model:
const form = new FormData()
// You can use url field (audio file url)
form.append("url", "https://somewebsite.com/ausio.wav")
// Or a file
form.append("file", audioFileToUpload)
const response = await superStormSdk.invokeModel('<Your project Id>', form);
console.log(response)
//console.log
{
"data": {
"newRequest": {
"id": "bab77a9e-dd93-4f32-9091-cc828e514023-484584",
"createdAt": "1685005319788",
"rstatus": "pending",
"images": [],
"requestPayload": {
"file": "audioFileToUpload.wav"
},
"discussionId": "",
"output": "",
"inputLocation": "s3://super-storm-app-requests-dev/bab77a9e-dd93-4f32-9091-cc828e514023/bab77a9e-dd93-4f32-9091-cc828e514023-484584"
}
},
"success": true,
"status": 200
}
5. LLM with tools
To train a speech to text model you can use trainLLMWithToolsModel
:
const project = await superStormSdk.trainLLMWithToolsModel({
"name":"DB Connector",
"tools":[
{
"name":"DB_CONNECTOR",
"config":{
"postgresql_connect_url":"<db_connection_url>"
}
}
]
})
console.log(project)
{
"data": {
"project": {
"id": "06b13ec2-20eb-4afc-8547-dea7572722b9",
"createdAt": 1686931988731,
"deployMode": "SERVERLESS",
"endpointName": "",
"modelDataPath": "",
"modelType": "LLM_WITH_TOOLS",
"name": "DB Connector",
"projectMetadata": {
"tools": [
{
"name": "DB_CONNECTOR",
"config": {
"postgresql_connect_url": "<db_connection_url>"
}
}
]
},
"pstatus": "TRAINING",
"requests": [],
"trainingJobName": "",
"userId": "eu-west-3:891f57e2-bd25-4235-92e2-7c3fd1454644",
"onTrainedWebhook": "",
"onInvokedWebhook": ""
}
},
"success": true,
"status": 200
}
After receiving a model deployed status you can start invoking your llm with tools model:
const response = await superStormSdk.invokeModel('<Your project Id>', {
"input":"who is the user with most events"
}
);
console.log(response)
{
"data": {
"newRequest": {
"id": "c4b3dd5a-a07d-4468-ae91-4cb91ec63127",
"createdAt": "1687272273625",
"rstatus": "success",
"images": [],
"requestPayload": {
"input": "<input>",
"tools": [
{
"name": "DB_CONNECTOR",
"config": {
"postgresql_connect_url": "<db_url>"
}
}
],
"history": []
},
"discussionId": "0c3bcb12-66f7-4253-8c26-6674026665c8",
"flowExecId": "",
"output": "<output>",
"flowNodeId": "",
"inputLocation": ""
}
},
"success": true,
"status": 200
}
With history:
const response = await superStormSdk.invokeModel('<Your project Id>', {
"input": "who is the user with most events"
},
{
"discussionId": "<discussionId>"
}
);
console.log(response)
{
"data": {
"newRequest": {
"id": "845f687a-0084-4a01-9c00-c0d04ef0c7f4",
"createdAt": "1687272442457",
"rstatus": "success",
"images": [],
"requestPayload": {
"input": "can you give the name of the first event created in Jay?",
"tools": [
{
"name": "DB_CONNECTOR",
"config": {
"postgresql_connect_url": "<db_url>"
}
}
],
"history": [
"Human: hi",
"AI: Hello! How can I assist you today?"
]
},
"discussionId": "101c6e06-dba3-430e-8f36-fe2d602229eb",
"flowExecId": "",
"output": "The name of the first event created in Jay is \"Kate's birthday party 🥳\".",
"flowNodeId": "",
"inputLocation": ""
}
},
"success": true,
"status": 200
}
Webhooks(Optional)
When training a text to image or a chatbot model you can pass onTrainedWebhook
to register an HTTP callback that will be triggered in POST
mode with the trained project.
For text to image model, you can also send onInvokedWebhook
, it will be triggered in POST
mode witt the the completed request.