Refactored to flow Hub Packaging directory structures

This commit is contained in:
2025-05-27 18:24:39 -05:00
parent 93362b209b
commit 73294b19b4
24 changed files with 222 additions and 174 deletions

View File

@@ -0,0 +1,86 @@
# Basic Messenger
Built for PoCs with other Speech Services, this provides a simple text from a prompt interface for IVA Studio
## Prerequisits
1. Install and configure the _Core Messenger Webhook_ Package from the Resource Center -> Hub.
## Source Code
[basic_messenger](./_studio_dependencies/ProxyScript/basic_messenger.js) Proxy Script
## Example usage
```sh
curl --location 'https://router.ivastudio.verint.live/ProxyScript/run/67bca862210071627d32ef12/current/basic_messenger' \
--header 'Content-Type: application/json' \
--data '{
"input" : "What is the weather",
"model" : "main"
}'
```
```json
{
"id": "resp_c8191807-c478-41d0-a73c-68d361eae5a3",
"object": "response",
"created_at": 1745609535,
"status": "completed",
"model": "main",
"output": [
{
"type": "message",
"id": "msg_56594e02-ae08-47ce-8c7f-d5165b1fa9de",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "Could you please provide a city or a zip code to get the weather information?",
"annotations": []
}
]
}
]
}
```
Note the use of "previous_response_id" to manage conversation state.
```sh
curl --location 'https://router.ivastudio.verint.live/ProxyScript/run/67bca862210071627d32ef12/current/basic_messenger' \
--header 'Content-Type: application/json' \
--data '{
"input" : "Chicago",
"model" : "main",
"previous_response_id" : "resp_c8191807-c478-41d0-a73c-68d361eae5a3"
}'
```
```json
{
"id": "resp_c8191807-c478-41d0-a73c-68d361eae5a3",
"object": "response",
"created_at": 1745609627,
"status": "completed",
"model": "main",
"output": [
{
"type": "message",
"id": "msg_ef591b4c-b08b-49fe-85a5-306c94269bf6",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "Can you provide the zip code for Chicago?",
"annotations": []
}
]
}
]
}
```
#### CLI client for basic_messenger
You can find an example CLI client (using Node.js) [here](./application/)

View File

@@ -0,0 +1,119 @@
console.log(">>> basic_messenger >>>");
console.log({ query: req.query, body: req.body });
console.log(">>> basic_messenger >>>");
let sessionId = req.body.previous_response_id || `resp_${uuidv4()}`;
const input = req.body.input;
const modelName =
req.body.model || settings_667ef98d3ee8930a5debcbdb.nlu.modelName;
const metadata = {
...req.body.metadata,
userId: req.body.sentBy?.userId,
};
const postBack = req.body.postBack;
const configuration = req.body.event?.configuration;
(async () => {
try {
const smStr = `session-map-${sessionId}`;
const sessionMap = await redis.hGetAll(smStr);
console.log({ smStr: smStr, sessionMap: sessionMap });
const recognizedData = await axios
.post(
`${settings_667ef98d3ee8930a5debcbdb.nlu.apiBaseURL}Model/run/${req.params.workspaceId}/${req.params.branch}/${modelName}`,
{
input: input,
conversationId: sessionMap.conversationId,
settings: settings_667ef98d3ee8930a5debcbdb.nlu.settings,
metadata: metadata,
postBack: postBack,
configuration: configuration,
}
)
.then((response) => {
return response.data;
})
.catch((error) => {
let errorPayload = {
id: `resp_${uuidv4()}`,
object: "response",
status: "failed",
model: modelName,
created_at: Math.floor(Date.now() / 1000),
error: {
name: error.name,
message: error.message,
},
};
return errorPayload;
});
console.log({
rdCi: recognizedData.conversationId,
sessionMap: sessionMap,
});
if (recognizedData.conversationId) {
await redis.hSet(smStr, "conversationId", recognizedData.conversationId);
await redis.expire(smStr, 3600);
if (sessionMap.conversationId) {
} else {
db.analytics.addConversation({
id: recognizedData.conversationId,
});
}
}
// NOTE: Additonal logic could be used to provide answer from alternative sources
// recognizedData.answers = API_RESPONSE || ['Example'];
if (recognizedData.tag === "ERROR") {
} else if (
recognizedData.classificationResults.length === 0 &&
recognizedData.answers.length === 0
) {
recognizedData.answers = [
settings_667ef98d3ee8930a5debcbdb.responses.unrecognized,
];
} else if (recognizedData.answers.length === 0) {
recognizedData.answers = [
settings_667ef98d3ee8930a5debcbdb.responses.unanswered,
];
}
recognizedData._id = (
await db.analytics.addTransaction(recognizedData)
).insertedId;
// Concatenate the array of strings into a single string
const text = recognizedData.answers.join(" ");
const response = {
id: sessionId,
object: "response",
created_at: Math.floor(Date.now() / 1000),
status: "completed",
model: modelName,
output: [
{
type: "message",
id: `msg_${uuidv4()}`,
role: "assistant",
content: [
{
type: "output_text",
text: text,
annotations: [],
},
],
},
],
};
res.send(response);
} catch (error) {
console.log(error.message);
res.send({
answers: ["Something went wrong. Please try again."],
outputs: {},
});
}
})();

View File

@@ -0,0 +1,2 @@
END_POINT=https://router.ivastudio.verint.live/ProxyScript/run/67bca862210071627d32ef12/current/basic_messenger
MODEL=main

View File

@@ -0,0 +1,31 @@
# Basic Messenger CLI
## Overview
Basic Messenger CLI is a command line chat program that allows users to interact with IVA Studio's basic-messenger API.
## Installation
1. Install the dependencies:
```
npm install
```
2. Create a `.env` file in the root directory and add your END_POINT and MODEL:
```
END_POINT=https://router.ivastudio.verint.live/ProxyScript/run/67bca862210071627d32ef12/current/basic_messenger
MODEL=main
```
## Usage
To start the application, run:
```
node start
```
## License
This project is licensed under the MIT License.

View File

@@ -0,0 +1,307 @@
{
"name": "node-chat-cli",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "node-chat-cli",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"axios": "^1.9.0",
"dotenv": "^16.5.0"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"license": "MIT"
},
"node_modules/axios": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz",
"integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"license": "MIT",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"license": "MIT",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/dotenv": {
"version": "16.5.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz",
"integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-set-tostringtag": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.6",
"has-tostringtag": "^1.0.2",
"hasown": "^2.0.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"license": "MIT",
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz",
"integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==",
"license": "MIT",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"es-set-tostringtag": "^2.1.0",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-tostringtag": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
"license": "MIT",
"dependencies": {
"has-symbols": "^1.0.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
}
}
}

View File

@@ -0,0 +1,15 @@
{
"name": "node-chat-cli",
"version": "1.0.0",
"description": "A command line chat program that interacts IVA Studio's basic_messenger API.",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js"
},
"dependencies": {
"axios": "^1.9.0",
"dotenv": "^16.5.0"
},
"author": "",
"license": "MIT"
}

View File

@@ -0,0 +1,48 @@
const axios = require("axios");
module.exports = class Client {
constructor(endpoint, model) {
this.endpoint = endpoint;
this.model = model;
}
async send(input) {
return new Promise((resolve, reject) => {
let data = JSON.stringify({
input: input,
model: this.model,
previous_response_id: this.previous_response_id,
metadata: { channel: "text" },
});
let config = {
method: "post",
maxBodyLength: Infinity,
url: this.endpoint,
headers: {
"Content-Type": "application/json",
},
data: data,
};
axios
.request(config)
.then((response) => {
if (response.data && response.data.output) {
if (
response.data.output.length > 0 &&
response.data.output[0].content.length > 0
) {
this.previous_response_id = response.data.id;
resolve(response.data.output[0].content[0].text);
}
} else {
resolve("No output received from server.");
}
})
.catch((error) => {
reject(error);
});
});
}
};

View File

@@ -0,0 +1,30 @@
const readline = require("readline");
const Client = require("./client/client");
const dotenv = require("dotenv");
// dot env config
dotenv.config();
const END_POINT = process.env.END_POINT;
const MODEL = process.env.MODEL;
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.setPrompt("You: ");
const client = new Client(END_POINT, MODEL);
const init = async () => {
rl.prompt();
// Reads user input to send messages in a prompt
rl.on("line", async (input) => {
if (input.trim().length > 0) {
output = await client.send(input);
console.log(`Assistant: ${output}`);
}
rl.prompt();
});
};
init();