{"_id":"@sassoftware/viya-assistantjs","_rev":"80-f568dfb0a87ce58c5b1ba5e9bee985f8","name":"@sassoftware/viya-assistantjs","dist-tags":{"latest":"0.19.0","dev":"0.21.0"},"versions":{"0.1.0":{"name":"@sassoftware/viya-assistantjs","version":"0.1.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.1.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"dae9b1e84ad14375f46ece9d536ee062079939fb","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.1.0.tgz","fileCount":8,"integrity":"sha512-5hfiSzVjhDZf9j6A0En3Xv9gnHexF1QnINnZ/SME3Eo5NbBuYEYCd9wO+w8/c0mwN0Z+GBNys36vOTYwWid7Yw==","signatures":[{"sig":"MEUCIDa5kMESLI5NhylPsHpZZFUS4qUwAL0R/T8MKWvVDnKpAiEAhBU0US8gIegwXRz1a4yzfRsdJW04LPx64sMP2lwUwBM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":627949},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.js","module":"./dist/index.esm.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.esm.js","require":"./dist/index.js"},"gitHead":"9484bc36075ce1d6da765bcf298d41722e72ed8e","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && npm run umd && npm run esm","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","buildmicro":"rimraf dist && microbundle --name viyaAssistantjs"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.1.0_1710259468265_0.047803386968352735","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@sassoftware/viya-assistantjs","version":"0.2.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.2.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"1f5aff74cd956ca94e7d705ddf84ec8e9e9c15c2","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.2.0.tgz","fileCount":10,"integrity":"sha512-Iu0XPHy4mYZWxebCRYYp2jXEW9wCzSrkX+KQFL+WPWSZyKnZEvXj1gt2/pCJTICR5pkuxH85XABNqwnlzhz1aw==","signatures":[{"sig":"MEUCIAUHAfB8G2Gyo4oPBWLx89+4jG6/IijFmumKn6DmDPXLAiEA85Tlw/SA+xkHA2VBo7+EXMwSGRaVYUHHHn3Fug1Xxnw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":373495},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"f31112be8ddb796e9a84b798e728463f460d8927","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.2.0_1710260671624_0.4258763408557933","host":"s3://npm-registry-packages"}},"0.2.1":{"name":"@sassoftware/viya-assistantjs","version":"0.2.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.2.1","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"eacb78d42a64081f2152598aeaf8c296dc3debf1","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.2.1.tgz","fileCount":10,"integrity":"sha512-Fvra5I96uxHYQ5s2XT+eyMsG0tHZKLwuBnh140w0Ff74qpT9uS4RGDvT88ftH2/YWMJqOB+w8u+JqmU0eMYPpQ==","signatures":[{"sig":"MEYCIQCqJiPQuyCM8e53VcC+YnubB4K9pgpZXD7d9u47gLiKIgIhAKF4dxDftBo1CswkMrxmKnK0YlvU+ZE4lZR2K+rt79Qd","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":374281},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"22b8a8dfa1839ee2766b6afa1165a35395b56321","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.2.1_1710265337737_0.4964550628640785","host":"s3://npm-registry-packages"}},"0.2.2":{"name":"@sassoftware/viya-assistantjs","version":"0.2.2","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.2.2","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"331aee44ed09242b2929157d6c75a33936df12a4","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.2.2.tgz","fileCount":10,"integrity":"sha512-Exx7VHmoI09rsTauQo3ifSa2ifFPdGcXf4pKFbvVx4L7YLMucXcrU95atKfEoHsTRaetCMXO6xPdSmLW2czcpw==","signatures":[{"sig":"MEQCIBwArEM8x96GVbCMIs/ah21JBwD+fXn6Dajas87eo1kNAiBwQ1ZzNWOBDnN87GTVUmE2rYt1JkYiAlRYyxjWibpygw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":374281},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"db0d181b53520d975f3afb9c43a6837b2820c5a4","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.2.2_1710271332883_0.15335756083883045","host":"s3://npm-registry-packages"}},"0.2.3":{"name":"@sassoftware/viya-assistantjs","version":"0.2.3","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.2.3","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"e9d30f9ff4574505e4d3fd503158715f3eaaccfa","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.2.3.tgz","fileCount":10,"integrity":"sha512-Lu/3ht/dzoEbLr7mzRBT7n4Z/MvPrV86gM+v2JMNB9TWqel67kCSQi0UdNV4BbvWQ6MpXbhWFgcVnb/mw5wsUQ==","signatures":[{"sig":"MEQCICdV9X5dIrwiUa1S+/mqLo/WF7LQSTgtZ4UTB8hCozhzAiAO+KX2vWMcodvJtCnmR3VEYXZBpJzDVdYpvI8B7ZiIXw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":374613},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"51b102449446078fb1c53e137f74b4f3742f218a","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.2.3_1710360198547_0.046332619228739436","host":"s3://npm-registry-packages"}},"0.3.0":{"name":"@sassoftware/viya-assistantjs","version":"0.3.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.3.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"16789b18a8314e948c3343170fa5ee662b00e3bb","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.3.0.tgz","fileCount":10,"integrity":"sha512-O8JQpgUZV0oczaBoBUja1ov9ZTUfAVfc/sz7S/hPKY+oSaDXnFWKhpQOGko7lWCdvZ8NptP6jLtqgf6Pv3zwlw==","signatures":[{"sig":"MEUCIQDjGjJbzBeMBLHTGQhx/XYzNeEL73jqQ6k4RTDl1/jSQAIgRGMis+de8tzgipg6ox4UQMjlEBa6skssEAyXDtPMLVM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":391108},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"a35dafd1c3c12d54e805a79a2ce1b8c66b8944c7","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.3.0_1710425008577_0.6242130405196544","host":"s3://npm-registry-packages"}},"0.3.3":{"name":"@sassoftware/viya-assistantjs","version":"0.3.3","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.3.3","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"535039e3069de6ae2997c076806481ccf6f9d75d","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.3.3.tgz","fileCount":10,"integrity":"sha512-Or7Kw3XlOqC9T5tTwBSjGJkRiwk5YH8ha/6CPf957jUKW14PoyHm/nTaUV/8j/qDfzZ3yPX5WbdZuSRkKmPRaw==","signatures":[{"sig":"MEUCIQDuDRVgqvMmyGxEo5N0qoY1Tq6Sx3Jibi85UJSdx2OzVgIgRxL4MWeWNd4JKdlr4ZbTqf1zZoH1xKKPYGO93IUSVBU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":391926},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"21a86658d49124409b170587cc86d170e8f0bb0c","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.3.3_1710431921348_0.134713948000589","host":"s3://npm-registry-packages"}},"0.4.0":{"name":"@sassoftware/viya-assistantjs","version":"0.4.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.4.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"d8adc73213a1352a9cdfa0fcda790e9bf9c81f25","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.4.0.tgz","fileCount":10,"integrity":"sha512-KPHglRXfGdIKxQwBIxzk9iatETcV8oWGtJg/5Olcb8jhENwzKer5MR2jkhxwSfS+Jd7Jo4e/eITuRcem/sNE/Q==","signatures":[{"sig":"MEUCIQDkmYoBpEWvfXEkLngnfvetG6THgUVxovwzVt4sUe50NgIgI4+E+LEgdUb9g7KnBEC65xkv/zwZ5x3yhRXWGX71pOg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":397416},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"75101483663d310ec3374fcab6c415b573252f8a","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.4.0_1710512240280_0.77338809584009","host":"s3://npm-registry-packages"}},"0.5.0":{"name":"@sassoftware/viya-assistantjs","version":"0.5.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.5.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"0a94c4a399354e81ac87a3498c3071bea65fcc48","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.5.0.tgz","fileCount":10,"integrity":"sha512-V5QZxyOokrEClB/Q/Z9Nq4baPR+zJRPcjkmr+xeQ2ep0J11ObDorAbNWfEAMvIdLvN+zr65/CNTbXfQwo44IHg==","signatures":[{"sig":"MEQCIA2yjdfpNdeh+sYw6dZL+Jx9+BmSH1Dx0LNfM5+03KZSAiAKeRNmyi+yRwKGLeM07sBZuCRIRroltao2rv7IF/D0iA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":416723},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThere are many resources available. This site from Microsoft is a good place to start\r\n<a href=\"https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/assistants?source=recommendations\">Getting started with Azure OpenAI Assistants (Preview)</a>\r\n---\r\n\r\n## gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n\r\n## @sassoftware/viya-assistantjs\r\n\r\nThe document is available [here](https://sassoftware.github.io/restaf-demos/)\r\n@sassoftware/viya-assistantjs is a JavaScript library with the following\r\nkey features\r\n\r\n1. Write your first assistant in a few minutes\r\n\r\n2. The tools supported OOB are:\r\n   - code interpreter -- from the providers openai and azureai\r\n   - retrieval - Only openai supports this the time of this writing\r\n   - SAS Viya related custom tools\r\n      - List available reports and libraries\r\n      - Fetch data from Viya with filters\r\n\r\n3. Extend or replace the tools with your own\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaulst](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: '0', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: '-1', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n\r\n> Add a function to handle the prompts \r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant to support running SAS Code]<a name=\"extend\"></a>\r\n\r\nWe will extend the Assistant from the last section to run SAS programs.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: \"processSASProgram\",\r\n      description: \"process named SAS program. The program extension must be .sas or .casl\",\r\n      parameters: {\r\n        properties: {\r\n          resource: {\r\n            type: \"string\",\r\n            description: \"the name of the program to run\",\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"resource\"],\r\n      },\r\n    }\r\n  }\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n// import fs from 'fs/promises';\r\n\r\nasync function processSASProgram(params, appEnv) {\r\n  let { resource} = params;\r\n  let { store, session } = appEnv;\r\n  let src;\r\n  try {\r\n    src = await fs.readFile(resource, \"utf8\");\r\n  } catch (err) {\r\n    console.log(err);\r\n    return \"Error reading program \" + resource;\r\n  }\r\n  try {\r\n    if (appEnv.source === \"cas\") {\r\n      let r = await restaflib.caslRun(store, session, src, {}, true);\r\n      return JSON.stringify(r.results);\r\n    } else if (appEnv) {\r\n      let computeSummary = await computeRun(store, session, src);\r\n      let log = await restaflib.computeResults(store, computeSummary, \"log\");\r\n      return  log;\r\n    } else {\r\n      return \"Cannot run program without a session\";\r\n    }\r\n  } catch (err) {\r\n    console.log(err);\r\n    return \"Error running program \" + program;\r\n  }\r\n}\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\nconfig.domainTools = {\r\n  tools: tools, \r\n  functionList: {processSASProgram: processSASProgram},\r\n  instructions: 'Additionally use this tool to run the specified .',\r\n  replace: false // use true if you want to get rid of previous tool definition;\r\n};\r\n\r\n\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\nThe sample program(datastep.casl) is a simple casl program\r\n\r\n```text\r\n\r\naction datastep.runcode r= result/ single='YES' code = 'data casuser.a; x=1; run;';\r\nsend_response({casResults={result=result}});\r\n\r\n```\r\n\r\n> Here is a sample prompt\r\n\r\nprocess datastep.casl\r\n\r\n>If the run is successful you can query the table that was created.","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"55851e89d802706d635fcc23122b46b9efca5172","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.5.0_1710696348591_0.47449918189877716","host":"s3://npm-registry-packages"}},"0.5.1":{"name":"@sassoftware/viya-assistantjs","version":"0.5.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.5.1","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"19f21cf54a6eab947beee895ed987ae61caa400c","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.5.1.tgz","fileCount":10,"integrity":"sha512-JkOCcq7wu1LP+2hp8zF63WK82FgHrjqBrSgT7kDv9g/knbzSWLs7UTukUh/Kw2rbIcsks/8yAE7s6DrOGWfQiw==","signatures":[{"sig":"MEUCIQDBr1SZhYQjFp9DM6Ds7YUaeRtm7yVPGHqKbWIjGhjtdgIgBImWneN6+LDftGuUA8IFrtgWjIbuVn8WKgcCyCxurTs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":418007},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"18c058b8ca4ba6acbbde46bdab5c6d1ca0054c2b","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.5.1_1710705882585_0.867906639525629","host":"s3://npm-registry-packages"}},"0.6.0":{"name":"@sassoftware/viya-assistantjs","version":"0.6.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.6.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"7ce61af512f05dc92800fad44d06b9c68e6e69ce","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.6.0.tgz","fileCount":10,"integrity":"sha512-zpwfv3xFPouJ4rYXLHoVRbBN1DGDbGoMK6+ubxRy3+h7Vg1zEwnGVb6qJYZi7BBxIhgnozgXi1dYpnMrVsuT2A==","signatures":[{"sig":"MEQCIB4NPjEZ9EtylbuaImG5YIhVpQEIKoQCeqjcHlbmLH0iAiAnzCWN7tb5jyXWxj5jN/vFUZLAYV8jL4eQalKYuYgL5w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":422370},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThere are many resources available. This site from Microsoft is a good place to start\r\n<a href=\"https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/assistants?source=recommendations\">Getting started with Azure OpenAI Assistants (Preview)</a>\r\n---\r\n\r\n## gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n\r\n## @sassoftware/viya-assistantjs\r\n\r\nThe document is available [here](https://sassoftware.github.io/restaf-demos/)\r\n@sassoftware/viya-assistantjs is a JavaScript library with the following\r\nkey features\r\n\r\n1. Write your first assistant in a few minutes\r\n\r\n2. The tools supported OOB are:\r\n   - code interpreter -- from the providers openai and azureai\r\n   - retrieval - Only openai supports this the time of this writing\r\n   - SAS Viya related custom tools\r\n      - List available reports and libraries\r\n      - Fetch data from Viya with filters\r\n\r\n3. Extend or replace the tools with your own\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaulst](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: '0', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: '-1', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n\r\n> Add a function to handle the prompts \r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant to support running SAS Code]<a name=\"extend\"></a>\r\n\r\nWe will extend the Assistant from the last section to run SAS programs.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: \"processSASProgram\",\r\n      description: \"process named SAS program. The program extension must be .sas or .casl\",\r\n      parameters: {\r\n        properties: {\r\n          resource: {\r\n            type: \"string\",\r\n            description: \"the name of the program to run\",\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"resource\"],\r\n      },\r\n    }\r\n  }\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n// import fs from 'fs/promises';\r\n\r\nasync function processSASProgram(params, appEnv) {\r\n  let { resource} = params;\r\n  let { store, session } = appEnv;\r\n  let src;\r\n  try {\r\n    src = await fs.readFile(resource, \"utf8\");\r\n  } catch (err) {\r\n    console.log(err);\r\n    return \"Error reading program \" + resource;\r\n  }\r\n  try {\r\n    if (appEnv.source === \"cas\") {\r\n      let r = await restaflib.caslRun(store, session, src, {}, true);\r\n      return JSON.stringify(r.results);\r\n    } else if (appEnv) {\r\n      let computeSummary = await computeRun(store, session, src);\r\n      let log = await restaflib.computeResults(store, computeSummary, \"log\");\r\n      return  log;\r\n    } else {\r\n      return \"Cannot run program without a session\";\r\n    }\r\n  } catch (err) {\r\n    console.log(err);\r\n    return \"Error running program \" + program;\r\n  }\r\n}\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\nconfig.domainTools = {\r\n  tools: tools, \r\n  functionList: {processSASProgram: processSASProgram},\r\n  instructions: 'Additionally use this tool to run the specified .',\r\n  replace: false // use true if you want to get rid of previous tool definition;\r\n};\r\n\r\n\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\nThe sample program(datastep.casl) is a simple casl program\r\n\r\n```text\r\n\r\naction datastep.runcode r= result/ single='YES' code = 'data casuser.a; x=1; run;';\r\nsend_response({casResults={result=result}});\r\n\r\n```\r\n\r\n> Here is a sample prompt\r\n\r\nprocess datastep.casl\r\n\r\n>If the run is successful you can query the table that was created.","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"2b8ba8de120a943b4cf35a08d23b332d8ab486e6","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.6.0_1710759537377_0.15792444891013857","host":"s3://npm-registry-packages"}},"0.6.2":{"name":"@sassoftware/viya-assistantjs","version":"0.6.2","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.6.2","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"c15e3a74ba1beb9d4feba2d0cec0bc73a2ec7e53","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.6.2.tgz","fileCount":10,"integrity":"sha512-VO70KYEk3GM9wki/SFJ+kVXoJmJgiWB8Yc2P8iMTBHGs6RL9GaC6ZrzsfQahUaG//pn3P56D5Vxx9vKu4YlreA==","signatures":[{"sig":"MEUCIQDEZ1dr5qbnWgnCkzoBlobIPWKo0i6M++KoGx7l109tJwIgR4wLiZ2GE6Q9Li81nHGQLgUtyiGnYU9xj8eNQO363NE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":421457},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"8d60b1ff57eabfa17695eae08cd7f3297ef2ed72","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.6.2_1710791180944_0.8769700092738122","host":"s3://npm-registry-packages"}},"0.6.4":{"name":"@sassoftware/viya-assistantjs","version":"0.6.4","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.6.4","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"d7b15ea3b4653428108e6295ea8592f31820b87e","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.6.4.tgz","fileCount":10,"integrity":"sha512-5CNqUiCWVFSSqAiuhOgKTXBh3+6R5fSVIWYTt+yxt6AWGy2Ufy3h2aO6/XIIy5GnxrnPt86zQUonLzmAqtK2+A==","signatures":[{"sig":"MEUCIQDnFSZ02glY5jJ6UYaGxW/RY6udZ4dPnlwA8JhlGenPnQIgRh1J1fD2lhKJ8nJdnj4B2HQhrn55m2kTidK+70Ah6Aw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":429509},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.\r\nA clear explanation of what it is at\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">How Assistants works</a>\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Basic steps\r\n\r\n1. As a developer, you can add to  the builtin Viya tools or replace them.\r\n    - create tool specifications and functions to implement these tools\r\n    - The  builtin tool to run SAS code is very basic since it is unclear\r\nwhere the code will come from(and whether it even makes sense in this scenario).\r\nRecommend developer override the implementation\r\n via the configuration object for setupAssistant by creating a _runSAS tool.\r\n\r\n2. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n3. Submit user prompt using the *runAssistant* method which will return the final\r\n answer. This answer might have been created by gpt or by one of your tools/functions.\r\n4. Process this response and repeat step 3.\r\n5. Additionally you can use the uploadFile method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nThe library handles all the calls to the Assistant API.\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"e1f63668dabdc39252db42724c261e24f1cf4aa5","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.6.4_1710846381369_0.2290534155014219","host":"s3://npm-registry-packages"}},"0.6.5":{"name":"@sassoftware/viya-assistantjs","version":"0.6.5","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.6.5","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"15c3ebf88c204051d96ee2df7efa435613003635","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.6.5.tgz","fileCount":10,"integrity":"sha512-67KA1qLTbZFVm4jFIFWs5Jij3GVshba9Y+M9QdK/f5X+kgRaoUqs9/x51upSpLOmzdNJlK5MvDZJCBnzsYMnyQ==","signatures":[{"sig":"MEQCIHLfDs0HtXJiVQqcGPZQgVK8lYKmm/WNnB46U46x8XXLAiB1QHeSGy3RmEidTmfGTq4wIv9G3DKjJYUcXOosParb3Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":427161},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.\r\nA clear explanation of what it is at\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">How Assistants works</a>\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Basic steps\r\n\r\n1. As a developer, you can add to  the builtin Viya tools or replace them.\r\n    - create tool specifications and functions to implement these tools\r\n    - The  builtin tool to run SAS code is very basic since it is unclear\r\nwhere the code will come from(and whether it even makes sense in this scenario).\r\nRecommend developer override the implementation\r\n via the configuration object for setupAssistant by creating a _runSAS tool.\r\n\r\n2. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n3. Submit user prompt using the *runAssistant* method which will return the final\r\n answer. This answer might have been created by gpt or by one of your tools/functions.\r\n4. Process this response and repeat step 3.\r\n5. Additionally you can use the uploadFile method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nThe library handles all the calls to the Assistant API.\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"f00455a0446ef30a9ddd31aee51d0b70292e2a82","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.6.5_1710851205210_0.6955679633047671","host":"s3://npm-registry-packages"}},"0.6.6":{"name":"@sassoftware/viya-assistantjs","version":"0.6.6","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.6.6","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"f4e9ac0694b53015281c57ce5821939d07666e0a","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.6.6.tgz","fileCount":10,"integrity":"sha512-1k2WFA2Zn35YkTltwEWJ4mpXboN082lg9utVdiWrHBhgN+Tqw+dnN9YagPL/D131dff/N0bsscBVHi1UY3f6Vw==","signatures":[{"sig":"MEQCICsYDOOGiIcDdKQ7Dk1WN4NJPfXwi9OcjSF7TQ0XScwWAiAdCModym4sYqCab2gzIkbdc6Hd/4XUUt+eNTGNgkdLfA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":440528},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.\r\nA clear explanation of what it is at\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">How Assistants works</a>\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Basic steps\r\n\r\n1. As a developer, you can add to  the builtin Viya tools or replace them.\r\n    - create tool specifications and functions to implement these tools\r\n    - The  builtin tool to run SAS code is very basic since it is unclear\r\nwhere the code will come from(and whether it even makes sense in this scenario).\r\nRecommend developer override the implementation\r\n via the configuration object for setupAssistant by creating a _runSAS tool.\r\n\r\n2. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n3. Submit user prompt using the *runAssistant* method which will return the final\r\n answer. This answer might have been created by gpt or by one of your tools/functions.\r\n4. Process this response and repeat step 3.\r\n5. Additionally you can use the uploadFile method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nThe library handles all the calls to the Assistant API.\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"3e6008b7d695f55834be942c18142aa41bb4712e","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.6.6_1710853444013_0.5033003001912488","host":"s3://npm-registry-packages"}},"0.6.7":{"name":"@sassoftware/viya-assistantjs","version":"0.6.7","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.6.7","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"ed4471278a8b570870309b9e179bcabeb282c8ba","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.6.7.tgz","fileCount":10,"integrity":"sha512-1uHCqYH0AL3ynyhI8v6GsJourOSgmI89BEaLmnPEQrUyvX0TzKO40Jw32MKhe9OUEmjy16qv/O02PknIbIKIdQ==","signatures":[{"sig":"MEYCIQDB0UEyZ6DT2do3RmtaPROdT5ct4a1gw5vlQ8V//DCrcQIhAOSOr1Wnylg4/tLgC2rl+GRkVuvZrSIumbPj22b4rysl","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":441319},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.\r\nA clear explanation of what it is at\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">How Assistants works</a>\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Basic steps\r\n\r\n1. As a developer, you can add to  the builtin Viya tools or replace them.\r\n    - create tool specifications and functions to implement these tools\r\n    - The  builtin tool to run SAS code is very basic since it is unclear\r\nwhere the code will come from(and whether it even makes sense in this scenario).\r\nRecommend developer override the implementation\r\n via the configuration object for setupAssistant by creating a _runSAS tool.\r\n\r\n2. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n3. Submit user prompt using the *runAssistant* method which will return the final\r\n answer. This answer might have been created by gpt or by one of your tools/functions.\r\n4. Process this response and repeat step 3.\r\n5. Additionally you can use the uploadFile method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nThe library handles all the calls to the Assistant API.\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"bb92e01930245c38a6642266663e28951c9af81f","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.6.7_1710855560829_0.24559962467268903","host":"s3://npm-registry-packages"}},"0.6.8":{"name":"@sassoftware/viya-assistantjs","version":"0.6.8","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.6.8","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"42df4a40ded4898375bfe74b5c5442295f2ec182","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.6.8.tgz","fileCount":10,"integrity":"sha512-2N/vk5wjn9/CZbKF5AZz9lHUCGV4WJ6w/FoQRA8DXla16xZWtzKHo36Hu0KKqCFUWIIdW1pRTP/8bEWMelGNGw==","signatures":[{"sig":"MEUCIQCuuoigPAWmZPHjZZpdxfu9MG3Wh5fQrbO6c1fjyQfW1QIgQvmx09pXDonahJ5XlfL+uCamrqWxbWzRmOrDOe0n+5Q=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":441311},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.\r\nA clear explanation of what it is at\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">How Assistants works</a>\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Basic steps\r\n\r\n1. As a developer, you can add to  the builtin Viya tools or replace them.\r\n    - create tool specifications and functions to implement these tools\r\n    - The  builtin tool to run SAS code is very basic since it is unclear\r\nwhere the code will come from(and whether it even makes sense in this scenario).\r\nRecommend developer override the implementation\r\n via the configuration object for setupAssistant by creating a _runSAS tool.\r\n\r\n2. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n3. Submit user prompt using the *runAssistant* method which will return the final\r\n answer. This answer might have been created by gpt or by one of your tools/functions.\r\n4. Process this response and repeat step 3.\r\n5. Additionally you can use the uploadFile method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nThe library handles all the calls to the Assistant API.\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"642bf2c0a75c253fad4d975f23f9553427a0db95","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.6.8_1710857180441_0.7651669356378639","host":"s3://npm-registry-packages"}},"0.7.0":{"name":"@sassoftware/viya-assistantjs","version":"0.7.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.7.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"04d94d55303aa399ef0a7311f07da0f08fd25c71","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.7.0.tgz","fileCount":10,"integrity":"sha512-9y1OOyexFcugg6ONoRfhqbkFQtx7rEWNjntAo/x6W/lKZlrM9B2aOwUs73Z6n6ohqErrdu8Um7FNKBbXmVX7dw==","signatures":[{"sig":"MEUCIQCNwHP6Vx4TF85bIOE4JqCnvI0ohUtTJRvJzFY3FdobuAIgSDm2dvyPYaLWFZi7OExiK0ze62XOFA3Cl2HxeeH3TiY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":441311},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.\r\nA clear explanation of what it is at\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">How Assistants works</a>\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Basic steps\r\n\r\n1. As a developer, you can add to  the builtin Viya tools or replace them.\r\n    - create tool specifications and functions to implement these tools\r\n    - The  builtin tool to run SAS code is very basic since it is unclear\r\nwhere the code will come from(and whether it even makes sense in this scenario).\r\nRecommend developer override the implementation\r\n via the configuration object for setupAssistant by creating a _runSAS tool.\r\n\r\n2. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n3. Submit user prompt using the *runAssistant* method which will return the final\r\n answer. This answer might have been created by gpt or by one of your tools/functions.\r\n4. Process this response and repeat step 3.\r\n5. Additionally you can use the uploadFile method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nThe library handles all the calls to the Assistant API.\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"b9657530e22c59340c7547ead4314355d46382b0","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.7.0_1710876714943_0.26051499481356677","host":"s3://npm-registry-packages"}},"0.7.1":{"name":"@sassoftware/viya-assistantjs","version":"0.7.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.7.1","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"dd8c25d0560179408793843c92dbea6cf644a0ed","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.7.1.tgz","fileCount":10,"integrity":"sha512-4978Eus+IgMe44RwPJuCWcKzo7kK1KN0dXYkOg1Z2zAO1sIpDCD7nhxU/5oF6jbk4WWshi3WW4ULmPGpJlMcZQ==","signatures":[{"sig":"MEYCIQDY7HXvpD5p2J1g1zjloU2io70YTP/5ULzI+MSaHIGKuwIhAKT9Zmc5oY/Ps3Y0JmJBCX2JCaPZjv5hPwh91gL0ebAb","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":440744},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.\r\nA clear explanation of what it is at\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">How Assistants works</a>\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Basic steps\r\n\r\n1. As a developer, you can add to  the builtin Viya tools or replace them.\r\n    - create tool specifications and functions to implement these tools\r\n    - The  builtin tool to run SAS code is very basic since it is unclear\r\nwhere the code will come from(and whether it even makes sense in this scenario).\r\nRecommend developer override the implementation\r\n via the configuration object for setupAssistant by creating a _runSAS tool.\r\n\r\n2. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n3. Submit user prompt using the *runAssistant* method which will return the final\r\n answer. This answer might have been created by gpt or by one of your tools/functions.\r\n4. Process this response and repeat step 3.\r\n5. Additionally you can use the uploadFile method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nThe library handles all the calls to the Assistant API.\r\n\r\n## Getting Started\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support running SAS Code](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"c06afb646f527dc26994a1e4db22f8a112d4cbf5","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.7.1_1710878573350_0.9125471368023896","host":"s3://npm-registry-packages"}},"0.9.0":{"name":"@sassoftware/viya-assistantjs","version":"0.9.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"39f1edd8fda77381c81ed44cfe20648df3737988","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.0.tgz","fileCount":10,"integrity":"sha512-fRA7qzLqArWMbhksjGwd/XpOY1KGU1kJhUhm4Z020j+4hhDD3+mrF27euZ1ENkv8jNnfOFZQFMJSFFyOaRPl5g==","signatures":[{"sig":"MEUCIEyrjT9FR4Oajs49lWy9E4zweJdiTuFZyBL53ElQZ0wHAiEA7P6z1wVIhKUJnbJSWKlQlp+eZ/9bwmYqb/IVaQJ8LRY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":451528},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"52ddccc3499eb35096132b59e9e5892896b07c3c","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.0_1710944357481_0.5314296270249894","host":"s3://npm-registry-packages"}},"0.9.1":{"name":"@sassoftware/viya-assistantjs","version":"0.9.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.1","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"dd7dd35c49446a15a6976115c31918a163125a5d","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.1.tgz","fileCount":10,"integrity":"sha512-b2DyrHMB77gkjZLRCx8ld9l/PhWKqSK/KRykR6owxktkdPI9lNAPlXpt+///iqbhDxZxlhO7I8nXjTnh/4U3kA==","signatures":[{"sig":"MEUCIQCvy2q3byPGDfE0fSL3CNBj2DsEaijNRw6BkTV5af1BEAIgW0Jb41TnfNW2Q3mi3uLuCf+hZ8YfWKIGf0QQUk/0798=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":456683},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"0442815684b3250866cdbc41279f316bff7d00e4","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.1_1711047349532_0.7125331878853811","host":"s3://npm-registry-packages"}},"0.9.2":{"name":"@sassoftware/viya-assistantjs","version":"0.9.2","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.2","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"2e6ea9439584a2dc1c740c34cdfbfad0988e06c7","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.2.tgz","fileCount":10,"integrity":"sha512-TZAtTeRh7CWEdUfZ6IoLNqDwq4aVKHBrfym57a4AM03WGCE9FRY6mrDO+sZG4OPD3vk3AwZx9nBG5QUklChYDg==","signatures":[{"sig":"MEUCIQCMRClYHXYT5dz99KvsE7gAthqNnxkuO/tlBeWOdJHJrgIgLSjhnLUx7O2B5qAXZqL8hmu8cz2LPAxCigiUOm9I3Ko=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":457067},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"0cffda4ac1e43e565eeadd06c3c53979cb664d78","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.2_1711049129374_0.059561389860302905","host":"s3://npm-registry-packages"}},"0.9.3":{"name":"@sassoftware/viya-assistantjs","version":"0.9.3","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.3","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"7fafbfab7391b75887c0f96c4ed560cfcc48a421","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.3.tgz","fileCount":10,"integrity":"sha512-UD0pN+i6NzmN2bDdVWB7DGV9+YZ5ANJhW8Y1ChIXLiLr/JUuoNs8a8+f39EL+GrIaqMyGh57ZL7x+IuDn3gkSA==","signatures":[{"sig":"MEQCIGfaN+aZIOge++CdUjSL6FW6IXYgzxRW05UUuoDxhl5HAiBl3Vv7ZN3Qq0llTFusayar01mxZkyRuFpHesys05yuBw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":462090},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"a731fee2a9be5cf08b709ec35156ef3585d6a752","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.3_1711110415757_0.7002304291362866","host":"s3://npm-registry-packages"}},"0.9.4":{"name":"@sassoftware/viya-assistantjs","version":"0.9.4","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.4","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"15f25a23c0bf0392c17b65b08f5fb419a0b118f3","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.4.tgz","fileCount":10,"integrity":"sha512-8hFlJsVDEVtShYh0Hw/EH9aFI/TWNreVJlygsmCOXnxZdYb2bJC6Afw5TjZxxwlsq17gq1Cu2G1YijorpE3bEQ==","signatures":[{"sig":"MEUCIQCIc1AgQ3Q51K0xfFZa8UuSIzHmOx4PWdHJs3CqH1kUeAIgXOU409TDcz9n3ImQqC3TLxl+SE4NeAIB3J1Fs44BsYk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":465068},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"3bc2882e3183a4ff715eeefc91a2198d65d2718f","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.4_1711119079980_0.08149938666944156","host":"s3://npm-registry-packages"}},"0.9.5":{"name":"@sassoftware/viya-assistantjs","version":"0.9.5","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.5","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"decf5954fdb99eee908960252745d056c4b7fce6","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.5.tgz","fileCount":10,"integrity":"sha512-94ZsrrMeIFHMe6fLxJljuRxf50/SwcRMZrOynT8bocN5C0KP2/exPYQ0i0QyTmw/RrFjbWNFflkHpQY4iLpk8w==","signatures":[{"sig":"MEUCIQCEnnaJBTG1my0xPqttrbGbVUX7waaUjC+rgKMbil2flwIgTGvUn0LnhLimCmH6WkOm6XcDeMuS55LxXU6/VPsH5eM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":466018},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"1d44ac9e51ec1def1da0128dccd889ef00aa33bb","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.5_1711126439286_0.5040549712102629","host":"s3://npm-registry-packages"}},"0.9.6":{"name":"@sassoftware/viya-assistantjs","version":"0.9.6","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.6","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"85fd5b66177a92eed37dae1d7f663c92a6fb39d5","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.6.tgz","fileCount":10,"integrity":"sha512-Csk+rHAltfWnJboYifl9PueDQrqrPm18cfibp0ephrzY1sB3Uq2jgTo+m+9EPSKcq4402dbybtNuXS7VeSCISA==","signatures":[{"sig":"MEUCIQDT3mT5M4nYBXEQ2oPENdQP5kLQ4HCooGjilMjdqlWg1gIgG4nSR5fPBNxoicENjxoEW7Zqb8to4Jig+jmLE4JLnNA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":467993},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"ac6ce51e15621fc56487d368f88a1f5fd70d3c87","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.6_1711130097891_0.7633764762123245","host":"s3://npm-registry-packages"}},"0.9.7":{"name":"@sassoftware/viya-assistantjs","version":"0.9.7","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.7","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"f79ce6ef7a27ffac62975cd10eff97b6164239aa","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.7.tgz","fileCount":10,"integrity":"sha512-33MhIwCmb8b6wHD4Rhy9CLZYnRs2HaFoUF9EPrZJs9UXZ3E1W7Bigxk5YLjyGv1feOIDNYsWIlsIvWkJuuDknQ==","signatures":[{"sig":"MEQCIGZDpVNgBXMCNP6wWw7EFzWRDVWL6gc5QejrvFPW8UiZAiBGKBrWvKlR4uUpdOXwm/iSzv6zEQyMXTN0sqU9vw4nhA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":479508},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"8999601d1cd560dfa1f511ae87451131021f942e","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.7_1711372922377_0.6724154796347674","host":"s3://npm-registry-packages"}},"0.9.8":{"name":"@sassoftware/viya-assistantjs","version":"0.9.8","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.8","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"79a2a388cd5401afbeb834b516d93d68a96f0cd3","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.8.tgz","fileCount":10,"integrity":"sha512-jr1LrKDiw0reikwfAKEwdni89JAaAiatN8tN2CSZN5T+882mQEYNOvGHMnHgB7y0s/B4pVSX09/S8CGuhU4FIw==","signatures":[{"sig":"MEYCIQCyQ4IKYeqWy2YW0Wd7xiWa+njCDBwQRU37LBrQIZUYGAIhAPNHish8p2lfeAKINIaAwyxy3HuO1rLZYpfazpIb6Ugf","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":481504},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"1a27b55bdb67468f9d59e76815d0693cad04c57f","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.8_1711376698838_0.16958610101966243","host":"s3://npm-registry-packages"}},"0.9.9":{"name":"@sassoftware/viya-assistantjs","version":"0.9.9","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.9","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"d06fdcf48dbeed7d3322f56ef120d80fd13bf958","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.9.tgz","fileCount":10,"integrity":"sha512-INuwhlQYpm2gb5vFPlifA8ioScBpyXBw36DtPhkm9WzjCudbxqofFj6dnr+SxM8VV5/1qtZNxv7aO7VC0m0TgA==","signatures":[{"sig":"MEQCIDXm/JEoLRV3hdk6uNKfZtixhseQU2gQ/U7n3rT+PyyIAiBXxeGKhBM8QD7OH2A7p4x80Gf1r4/fgrCyMMvBXlctuw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":486200},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"537decb634243c14af8e6876c49a9ac79c7365ef","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.9_1711378341150_0.6971928560732812","host":"s3://npm-registry-packages"}},"0.9.10":{"name":"@sassoftware/viya-assistantjs","version":"0.9.10","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.10","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"d4da16f8749951191e233e3002434e5027dfb5e3","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.10.tgz","fileCount":10,"integrity":"sha512-AhtWcR9JOAnZFXt8nXheoX27/OHU56DI11MzBRCJoc19AeMzFdsObh+JWviXsBZ9xX/4/03imIeHEeOOHbCFMA==","signatures":[{"sig":"MEYCIQDfCONyu+7tZoPzo7RUqBAkhTqO4DmyP0LjeqiUO2gcDAIhALa7JQauWcSGUAr5iIY/htdfqgFN1EX18R6VMrcz2l2A","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":502281},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"fa1ddf0f5de23e9e71d8ad67be102648c880c0c1","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.10_1711380170715_0.4353044359204985","host":"s3://npm-registry-packages"}},"0.9.11":{"name":"@sassoftware/viya-assistantjs","version":"0.9.11","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.11","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"103bade6d3656d423b8f0592513f32535953f6ae","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.11.tgz","fileCount":10,"integrity":"sha512-+IeaDUYKZo7L/izVPtyLto/O1AoI6Zv4QZf3l6ds+XjKI71Q1W0iQnBob23RnBZ7AvPikYSrm2bdbBSnuWbeaQ==","signatures":[{"sig":"MEYCIQChcQhgStF6LkRp8wvu19yW8CMDn/byKulFIJNYEbCRowIhAIhgQaRG/8QNlAr7q2Seb23oOen+LE036k3v231AoqCK","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":503655},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"0537e43b726ea4fd3d3e058ffc059dd00bd74b78","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.11_1711381721826_0.4357791009105829","host":"s3://npm-registry-packages"}},"0.9.12":{"name":"@sassoftware/viya-assistantjs","version":"0.9.12","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.9.12","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"c47381bd0665653770318bdce2a87d8a393f4a4c","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.9.12.tgz","fileCount":10,"integrity":"sha512-VpXr81OEtY36HGYkNQmdayV7lCYW2Zcd4k4fq8/2HxDx05I8E3qXr0oyCHTZdyI6inZhXYW50v2eUKf+gc+UeA==","signatures":[{"sig":"MEYCIQC7uR2xaO9dEG9wgaCN/rgeo1m0lW4obddGajqpG20noQIhALa9SnLb6/0rusNfWyCiEKLRKwcDveKqPRDhNxrvi7Vw","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":505394},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"e6b0a3ef068ce487031b54e5ab115e24d0c944b0","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.9.12_1711383040375_0.5095621734307585","host":"s3://npm-registry-packages"}},"0.10.0":{"name":"@sassoftware/viya-assistantjs","version":"0.10.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"d59b6154d014cc4836a3f9d7df484abe28b05ebc","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.0.tgz","fileCount":10,"integrity":"sha512-Bc0uuWKwmKWaCOSEqd0Z3FeYt/DnKlCOCYS8eFKUBkWAlbz/ArxsNHfP69DyAh5S9gTgrsCsvGDit2uIzrRGuw==","signatures":[{"sig":"MEUCIGW7fwe28AHaU/LnKOBKtH0EU/HmhveR3VYAawSCA9lXAiEAnlTQMbwSZIpYRH5jy4i3gmoEuZ/bcdKbgJiqEdFz1VA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":479362},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"0cdd777f34c69d5b8660239761bf570d64e049b4","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.0_1711385454717_0.6080420861591871","host":"s3://npm-registry-packages"}},"0.10.1":{"name":"@sassoftware/viya-assistantjs","version":"0.10.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.1","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"df299529ac6e790eeb64759d6f1ec6c4a256a5f8","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.1.tgz","fileCount":10,"integrity":"sha512-D0WcXPJn8yQnR83CIBq6BT3BGe1txCZ/0baQ9Fj7a022/bkRMZkkdp0PIxlGCotg7O2E+sCnn6VkAG/byCGDtw==","signatures":[{"sig":"MEQCIHGgHbmSmY+IGDTY857KmUuM8ZfHLcVgUAl1UG0SdAV/AiAkEp2nLez4+CUyteTx/7EgKuoTJ4W0R7k1sAcCIaZ3zw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":505929},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"05cd7944212fc1776fbc4662a07144f023e14c1a","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.1_1711386826630_0.7939398214717852","host":"s3://npm-registry-packages"}},"0.10.2":{"name":"@sassoftware/viya-assistantjs","version":"0.10.2","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.2","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"a3bb4a8c5388e356d9c423f3e0a1ab3c1fe96138","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.2.tgz","fileCount":10,"integrity":"sha512-J8ZQ8oCGDGTDvLur7D/ow8fqG9Y5PGhPhI/n6vj38tnWFiT7HYxM3DmTSF5Yhnz4j44PTdMYb7h327v50Z+IuA==","signatures":[{"sig":"MEQCIETwLBauPPmhCrWHu6QsDQC6+hJ3sjCpF42ivdv5EUIOAiAQ21pq9fH4jDJOjg4bbUupXHOODI4k2Il8aK6C8Espuw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":523107},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"db8d9eb446076bf29d067f8019c5e8548a16c29b","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.2_1711396134714_0.40152257884161546","host":"s3://npm-registry-packages"}},"0.10.3":{"name":"@sassoftware/viya-assistantjs","version":"0.10.3","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.3","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"8980070889ec2c92571492a0fa5a93fcc7249523","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.3.tgz","fileCount":10,"integrity":"sha512-Cv9CxfRVzhphK7FOu9ac2jgko1OCkYuhoHsSk8MF3swGx0K6vEbV/gpCUV1dRM137xMJZ2qF0EZWPhMd4fBz5g==","signatures":[{"sig":"MEUCIC5q+Yq53rnvc1QLdFVt2VKNR3RSXhZHR2/PVuHm7N8zAiEA6u98HejYfXNE1jkDHJe5i7ys/pR3nVNHXfF1r6Qcq8U=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":522822},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"5e9a27e2f24fdc48791194690b86756e4a0e3866","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.3_1711402150333_0.3759026604455318","host":"s3://npm-registry-packages"}},"0.10.4":{"name":"@sassoftware/viya-assistantjs","version":"0.10.4","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.4","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"f17454d20d9e439f669cc719ad3dc6173a3153f4","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.4.tgz","fileCount":10,"integrity":"sha512-mDVnqGyibby6kSnQZ4cOzu7OvGgMftdsK5o0/rhq692gU8PYIPfD4YocynW2n3XS0V93cqI2e13WA6JaEwemIg==","signatures":[{"sig":"MEYCIQD6BRei5IWQxDBoCQUhukZmBvQDwN5K3TOIvPYdV23+eQIhAL/O9KZ1OQ7Jj8sZ4CE4z5GbiZVr45n47DOxH7bLCOJC","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":495806},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"b60daad5faba4e27e82aae642e6776768a082167","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.4_1711404357916_0.6158613458618667","host":"s3://npm-registry-packages"}},"0.10.5":{"name":"@sassoftware/viya-assistantjs","version":"0.10.5","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.5","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"b109036be555f3ba6dfbbcd03e087a01822834d4","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.5.tgz","fileCount":10,"integrity":"sha512-JsJGyIignuEpxSYMy45ZLOjVJyWn2oYxw7Sc6VNn5IcngSpllk8hbW+KIUqV+tfu9ImZI6ubkooMUx1oc6UinQ==","signatures":[{"sig":"MEYCIQCluqmyXiCzdkxI0okPgNUA3g6/4nRw9zFO515V20tXkgIhAJgp1cp4C+sOXV/zW/cihP+Oh11sXBulmtnexclD/8aK","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":494885},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"2093ccbb1b47059997dd28b8131e7e4bbe72767e","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.5_1711467659039_0.590612976666814","host":"s3://npm-registry-packages"}},"0.10.6":{"name":"@sassoftware/viya-assistantjs","version":"0.10.6","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.6","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"3a2169eafb9f3521ad267da5c51139839358d61e","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.6.tgz","fileCount":10,"integrity":"sha512-+tuXoYOC2q1PpKi3ceHKxbIF9H/mOCMg8N1zW+eDSAAywUFmssNuI/hFvSW+rTJ4qgU2Lr7AKcZjL23G1irlTw==","signatures":[{"sig":"MEYCIQC9xrSS4QhodqqzTx9V1koFj3ZWxI0S6oU326M6N0TamgIhALYaIK2d5kWJo+YXnW9td7ezLRJBpvIMy8C+fQ0k8iK5","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":500756},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"b80fc78fd492e3b5101e43c05f850340f5294c60","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.6_1711474759363_0.24003973191689454","host":"s3://npm-registry-packages"}},"0.10.8":{"name":"@sassoftware/viya-assistantjs","version":"0.10.8","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.8","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"d7e9b2583760eb1d3c631ed3c86470705ffd0061","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.8.tgz","fileCount":10,"integrity":"sha512-llxxyUMTLSi+Rjt/C13HpLwuyUcVG6ixWbLeCkoPfKc2tDqqURa8QfRSeYzyRJai6FudYiRkyDj6pjHukeaVBA==","signatures":[{"sig":"MEQCIBEBwlz40mNT6DOfERc7JFQLaJPKCHqLSrYZ1UWaa2hzAiBdyThC1ea/VdQGCmWRT8h7rbyKf8t8VwmlcoFqAiLVmw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":507959},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"505a1adabe0865f08d03305f535e76d257ffd629","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.7","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.8_1711544998072_0.978660921482307","host":"s3://npm-registry-packages"}},"0.10.9":{"name":"@sassoftware/viya-assistantjs","version":"0.10.9","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.9","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"c53d682a1747044d146e40af2a737979e50906fd","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.9.tgz","fileCount":10,"integrity":"sha512-wtZc6sCrREQqNt/mBTsxfo2w2l01wiJ8CISLcga7Em1eX7ClDJO/gCOKHoDPP24h/aaAhnPHMZek1TTfPDYzqw==","signatures":[{"sig":"MEQCIBVEu0TNfWhm5wnDer3T52oPTEMdJujiobdPQTCYH284AiBwIhX/yVpiL8QQARrLlDtRNqexGc22SZASkX+Um4wzow==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":529498},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"557cc68d5723e19b77363a1c896d67239051df4a","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.9_1711578503754_0.875109496786068","host":"s3://npm-registry-packages"}},"0.10.10":{"name":"@sassoftware/viya-assistantjs","version":"0.10.10","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.10","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"eccfffc55c71dae144af769db5fac1acf382610e","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.10.tgz","fileCount":10,"integrity":"sha512-sxW/LaLFQfDpNRn2yWE42Iw2RABQoPWqTwRX/PR2nZsqbXBBuS+a1JKB3HEDIR8zcVSvIbEsW8XoK+Ui4UwD0g==","signatures":[{"sig":"MEYCIQDA3HsuEPJnZqZFjqUWBh+1AHKW8F+u7FQnKnbLliDPtwIhAJ32XQTGpReDNd/oVAU2yCUgTL8PudQ1aWVuTBBktPvS","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":525017},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"4046cbfed1875ee879daf63873f8803fcdf57397","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.10_1711579600881_0.6706744869889774","host":"s3://npm-registry-packages"}},"0.10.11":{"name":"@sassoftware/viya-assistantjs","version":"0.10.11","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.11","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"b1f70b7df623f6d2d92cbb108366df5a1038add2","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.11.tgz","fileCount":10,"integrity":"sha512-2j75+s2TjfCjHhoeK9GD84EO61U2JDpijoRaN85efqHf0yDBTvGoYjsxksXGeXTpNXm71RnlwaNt/HcYuv5aVQ==","signatures":[{"sig":"MEQCIHOJ87tRYvL/pgVp3Bch0PtelAdPcSJ1hIjSwlb3I5htAiATolshV3KTscpEHpd0LipOFPMcuQcdx2ZxdmQ4OvKG6g==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":500215},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"3c9fdd0e9e44e911401e4e5a978abf4f5c306062","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.11_1711629639798_0.07516407507312972","host":"s3://npm-registry-packages"}},"0.10.12":{"name":"@sassoftware/viya-assistantjs","version":"0.10.12","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.10.12","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"627b56d9d33e50109d11eeafc930c8be9c4f7c31","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.10.12.tgz","fileCount":10,"integrity":"sha512-33syBJMuMeC45kMzAJdV8wWS3Ls8qm7cYLm0r2FYEiJGCMz3J/S+1yN0PcP2hwIiChmUEefB8nz4vu+zxVTeFw==","signatures":[{"sig":"MEQCIARNgalUKtcC142mo7Bn/2qW0DDE9NhOlScwAeb0QeKHAiBEoxkU29vz8qDFi+9F0nFtJ3qaJNE80U88ZMArv1/D2w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":500817},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"809073db168cfbc6593265fa9f60f1e94e238a56","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.10.12_1711661702046_0.17905682010045187","host":"s3://npm-registry-packages"}},"0.11.0":{"name":"@sassoftware/viya-assistantjs","version":"0.11.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.11.0","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"f51d9eff86315cfe4fac423ddba0dfa07bb35c92","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.11.0.tgz","fileCount":10,"integrity":"sha512-PcgNBHSmRPrGEOuOmtzyv0yATVTg3zz+UAUy01Z99XjC9pdLZezrOrqALbRqLZOwN6XzSKHdGxIR5O0eDjJrjg==","signatures":[{"sig":"MEYCIQDU8QqbmBN70vwla1jOq8TXLMD+gr+l8x1e1RyhV85WWAIhAOhsZ1pBIvxISaOZsuIstFpXNqll21wQrL1cBlErZCUV","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":501087},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"d807f403390d2aee42d3ea3b570f86e2d1aeed3f","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.11.0_1711664054057_0.5264766694171243","host":"s3://npm-registry-packages"}},"0.11.1":{"name":"@sassoftware/viya-assistantjs","version":"0.11.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.11.1","maintainers":[{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"ca62be841de21c4946bf9f0be3c08eb1e7bbeb64","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.11.1.tgz","fileCount":10,"integrity":"sha512-CYv+c+L770606VUlkqx4zFmGoh+4FshihL52o3hRrY7mZ+3HiZ8VD2PtAFjW7tD2/xbJXSF/lxcGVtYSbyTsxg==","signatures":[{"sig":"MEQCIESwQSf8WcwghGSYkz5X3d/1p1Fn5SspA/ihjR0JHk6GAiBzVvj65dFPqPOF98PTXXrtUvDAvS/v2DUmbA0Y1Dvs8g==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":571507},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"122a9b62ccbeabb904226822db2ed07fa4ea6c5d","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm","addsas":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisas.js"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.11.1_1712059161130_0.7998774671032038","host":"s3://npm-registry-packages"}},"0.12.0":{"name":"@sassoftware/viya-assistantjs","version":"0.12.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.12.0","maintainers":[{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"ed6e81987d1cf58903c516fce5d1cbf1af83d9e7","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.12.0.tgz","fileCount":10,"integrity":"sha512-vGNDRuoDEdYHrO3V+p0x+UKD8Az/AYGVFh/85/dinK6l9ng1ZPQkuIGaXc1evZi0zJp4C1e6BxIhsE/BxyV03Q==","signatures":[{"sig":"MEUCIH9g+HUBIKRVdIJbnS8XX6zNhtW/+PabR9ZUv+XUai6DAiEArqmBDK2YXTDn+2JE21/7zjp64ZWRqeTG/zdhGW3/k9I=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":677487},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can add your own tools or replace the builtins with your tools\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis are different.\r\nAlso azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So it is not ready for prime\r\n time but good enough to develop non-production Assistants.\r\n\r\n### Key features and drawbacks of Assistant\r\n\r\n**Advantages**\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n**Drawbacks**\r\n\r\nI will list these, but one must give openai some leeway since the Assistant is\r\nstill in beta\r\n\r\n1. The time to process a prompt is long and unpredictable.\r\n2. The time to process the response from the functions is long and unpredictable.\r\n3. The api is different between openai and azureai.\r\n\r\nThere has been no indication from openai when the performance issue will\r\n be addressed.\r\nMaybe the streaming capabilities announced recently might help address this issue\r\n\r\n**Opinion:**\r\n\r\nThe concepts behind the Assistant Api is a very good one and can help users develop\r\nAI Assistants with minimal effort.\r\n\r\nAt this point one should start prototyping the AI Assistant in the hope that the\r\nperformance issues will be resolved.\r\n\r\n### gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\nModels I am using:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n---\r\n> The goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nand run SAS code. .\r\n\r\n---\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to our aureai resource url if provider is azureai>\r\n  },\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: '', replace: false},\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  // set the source to cas or compute. \r\n  // if you want to run the AI assistant without Viya set source to none\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'//  \r\n      },\r\n    source: 'cas' \r\n  },\r\n  code: true,\r\n  retrieval: <Must be false for azureai>\r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"19c38b39eb4e5b470f03edf989d6b4f15c198433","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","sic":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisic.js","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.12.0_1712158279538_0.7496746684729367","host":"s3://npm-registry-packages"}},"0.14.0":{"name":"@sassoftware/viya-assistantjs","version":"0.14.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.14.0","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"e4bfab85bacba052a04cac6bba442d1113d935ed","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.14.0.tgz","fileCount":10,"integrity":"sha512-4GDB8vUB33jkDVaPS0vjjDwcbg5Boenb3RD03Fo0wDoY5qoo08fCNrNPTSETEL6zDFdyIns2BPO3aH3EagDsYQ==","signatures":[{"sig":"MEUCIQDMek6G4ot7x9Cm/4Y+Fn4ejQNbs2hOeuBAzdA9Pk5zGAIgLzl7ZJwKLWKCdOd+xmFb9Kf1C4bR7MONX+fYSjXPKz8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":541380},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya.\r\n\r\nThe goal of @sassoftware/viya-assistantjs library is to simplify the development\r\nof AI Assistants for Viya using either the openai or azureai implementation.\r\n\r\n- <a href=\"https://https://sassoftware.github.io/restaf-demos\">Documentation </a>\r\n- <a href=\"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs\">Repository</a>\r\n\r\nThe library comes with a set of builtin tools to get a list of libraries, tables\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Basic flow\r\n\r\n1. The library comes with capabilities to query Viya for\r\n   - libraries\r\n   - tables\r\n   - data from specific table\r\n   - run SAS code (prompt must include the code to execute)\r\n\r\n2. As a developer, you can replace the default tools with your own custom tools.\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api calls to SAS(or other sources)\r\n    will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n\r\nSee [these starter examples](#started) below.\r\n\r\n## Introduction to azure and openai Assistant API\r\n\r\nThe Assistant API is a new API that was announced late in 2003 by openai.Visit\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">openai Assistants works</a>\r\nto get the details.\r\n\r\nWith this api one can build a \"RAG\" with SAS Viya capabilities.\r\n\r\nThe Assistant API is supported by both openai and azureai. However their apis\r\n are different. Also azureai does not support the retrieval tool yet.\r\n\r\nThe Assistant API is in beta/preview. It seems to be evolving. So use with the standard\r\nwarning for usinf beta releases.\r\n\r\n## Key features and drawbacks of Assistant\r\n\r\n1. The Assistant manages the conversation thru the *thread*\r\n2. The threads are persistent. So one can use the thread in subsequent sessions.\r\n3. Users can extend the Assistant with *custom tools*. The tools allow the\r\nAssistant to use these tools to satisfy a prompt. The custom tools can access\r\ninformation only known to the user. For Viys users this mean they can use SAS\r\nViya capabilities to satisfy user queries.\r\n4. One can upload and attach files to the assistant. Assistant will search thru\r\nthe files to see if a prompt can be answered by the content of these files.The \"retrieval\"\r\ntool has to be enabled(not available in azureai at the time of this writing).\r\n5.Assistant comes with a tool called 'code_interpreter' than can generate and\r\nexecute python code\r\n\r\n## gpt models\r\n\r\nThe information here is a moving target. Check with the provider\r\nfor the proper model and zone to use for Assistant API.\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n\r\n## Getting Started<a id=\"started\"></a>\r\n\r\n- [AI Assistant with defaults](#default)\r\n- [Extend Assistant to support custom tool](#extend)\r\n\r\nIf you are developing a react app the call sequence is the same.\r\n\r\n## Creating a AI Assistant with defaults<a name=\"default\"></a>\r\n\r\nA version of this is [here](https://github.com/sassoftware/restaf-demos/blob/viya-assistantjs/samples/example1.js)\r\n\r\n### Step 0 - Create a nodejs project and install the following:\r\n\r\n- @sassoftware/viya-assistantjs\r\n\r\nRecommend that your set type to module in your package.json\r\n\r\n### Create your program and custom tool\r\n\r\n> In your index.js add the following imports:\r\n\r\n```javascript\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\n```\r\n\r\n> Create the configuration object as shown below. Substitute your own values\r\n\r\n```javascript\r\nlet config = {\r\n  provider: 'openai'|'azureai', // Depending on who your account is with\r\n  model: 'gpt-4-turbo-review'| for azureai the model you created in the portal\r\n  credentials: {\r\n    key: <your key> // obtain from provider\r\n    endPoint: <set this to your azureai resource url if provider is azureai>\r\n  },\r\n  temperature: 0.5,\r\n  // leave the next 4 items as is - explained in the document\r\n  assistantid: 'NEW', //leave it as is for now\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: 'NEW', // Ignore this for now\r\n  domainTools: {tools: [], functionList: {}, instructions: ''},\r\n  code: true, //for code intrepreter\r\n  retrieval: true  // must be false for azureai\r\n\r\n  // fill in the host and token to authenticate to Viya\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: 'server',\r\n      host: host,  // viya url - https://myviyaserver.acme.com\r\n      token: token,// viya token  - obtained from sas-viya auth login|loginCode\r\n      tokenType: 'bearer'\r\n      },\r\n    source: 'cas' // 'cas', 'compute', 'none'\r\n  },\r\n  userData: {}, // user data -passthru to tools\r\n  \r\n}\r\n```\r\n\r\n> Add a function to handle the prompts\r\n\r\n```javascript\r\n\r\nchat(config)\r\n  .then (() => console.log('bye'))\r\n  .catch(err => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### A note on prompts\r\n\r\nHere are some prompts to try:(enter exit to stop the chat)\r\n\r\nadd 1 + 1\r\n\r\nwho is the CEO of SAS Institute?\r\n\r\n>Warning: The actual api calls to Viya is quick, but the  \r\ntotal response time from azure or openai might be much longer.\r\n\r\nlist lib\r\n\r\nlist the tables in public\r\n\r\nfetch data from cars. Limit the rows to 10\r\n\r\n> A fun prompt - try it\r\nFetch data from cars where origin='Japan'\r\n\r\n## Extend Assistant with custom tools<a name=\"extend\"></a>\r\n\r\nIn this section we will extend the tools with a custom tool.\r\nThis tool maintains a list of courses.\r\n\r\nTo do this we have to fill in the domainTools in the configuration.\r\n\r\n### Step 1: Define the customTool\r\n\r\n**Key points**\r\n\r\n1. Give the tool a name. This will also be the name of the function\r\nthat implements the tool.\r\n\r\n2. The description is important - This is what helps gpt decide\r\n whether this tool can satisfy the request\r\n\r\n3. The parameters are what system will extract from the prompt\r\nand send it to your function as a params object. In this example the\r\nvalue of the program will be extracted.\r\n\r\n```javascript\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n```\r\n\r\n### Step 2: Create the function to handle the request\r\n\r\n```javascript\r\n// You need to add this import to the program\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n### Step 3: Create the domainTool object in configuration\r\n\r\n```javascript\r\n// add the definitions to te config\r\nconfig.domainTools = {\r\n  tools: tools,\r\n  functionList: { myuniversity: myuniversity },\r\n  instructions: instructions,\r\n  replace: false,\r\n};\r\n```\r\n\r\n### Step 4\r\n\r\nRun the program as you did befoee\r\n\r\n### Prompts\r\n\r\n> Here is a sample prompt\r\n\r\n```text\r\ncan I take a math course?\r\n\r\ncan I take a course on Dune?\r\n```\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"377d19c75a92583516d482064971b304d1e49516","scripts":{"esm":"webpack  --config webpack.config.mjs","pub":"npm publish --tag dev --access public","sic":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node clisic.js","umd":"webpack  --config webpack.config.umd.mjs","lint":"eslint . --ext .js --fix","test":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli.js","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","wpack":"rimraf dist && npm run umd && npm run esm"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.26.0","@azure/openai":"^1.0.0-beta.11","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","webpack":"^5.90.3","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","webpack-cli":"^5.1.4","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","webpack-node-externals":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.14.0_1713218481437_0.42804703744596484","host":"s3://npm-registry-packages"}},"0.15.0":{"name":"@sassoftware/viya-assistantjs","version":"0.15.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.15.0","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"126625afb0fd30a0c94a0220aa78f0b0fc865cbf","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.15.0.tgz","fileCount":10,"integrity":"sha512-MEimdCshdnpnBJhrWmJo/z60r2A410tV9J5jtef6wVH+C9Acl/FMuiWph7nJcYiEwjkdcAgkg4mapjhUrmcsnQ==","signatures":[{"sig":"MEUCIDg6KZ3RkR7xdgs4u5xu7gxHNlwfhoaNdabZxQXvvXlYAiEAnteP0w2f7W+liBZRm1V7Uq5WpOObZrtC6714G81Z0S4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":561915},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It uses the Assistant from openai and\r\nazureai(based on configuration).\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-work</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## gpt models\r\n\r\nModels used in the development of this library\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n\r\n// Step 2: setup configuration, Use the tools defined above\r\nlet config = {\r\n  provider: 'openai',// or 'azureai'\r\n  model: process.env.OPENAI_MODEL, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: 'NEW', //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: 'NEW',\r\n  domainTools:  {tools: tools, functionList: {myuniversity}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However this example demonstrates how to \r\ninclude \"corporate\" or \"private\" information to resolve the prompt.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, gptControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information\r\n  let appEnv = await gptControl.viyaOnDemand(gptControl, source);\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n// Step 2: setup configuration\r\nlet config = {\r\n  provider: \"openai\", // or 'azureai'\r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: \"NEW\", //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: \"NEW\", //create a new thread\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant for myUniverity\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {},\r\n};\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's anything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"de5084cedf9c5ab314fa6e2e2c1e38391d1f4d7b","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example && node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","testa":"dotenvx  run -f .env.azureai -- npm run test","testd":"dotenvx  run -f .env.openai -- npm run debug","testo":"dotenvx  run -f .env.openai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.15.0_1713899794210_0.05099622383851177","host":"s3://npm-registry-packages"}},"0.16.0":{"name":"@sassoftware/viya-assistantjs","version":"0.16.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.16.0","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"2b96a23d977dc7756389792b4c417180cd3226fa","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.16.0.tgz","fileCount":10,"integrity":"sha512-lH7BITnxGc03UCJk5gBcaQ87OO4B1H/4KP1rlfh2RVv9/8vPYKTydV9/oSF3y/mcw+ch+g/aEnUslpjUOiNqCA==","signatures":[{"sig":"MEUCIBl9IvdoTmu+1uRDt8fQ4P3HyFaNP4EH5aSKk8/XetPTAiEA4rPQSarkChK7mRs44KacamVyNNBAEPRxLZxeui/Gl6U=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":576919},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It supports the Assistant\r\nfrom openai and Azure\r\n\r\nSee [documentation here](https://sassoftware.github.io/viya-assistantjs/)\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-works</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Usage\r\n\r\nInstall the package using npm\r\n\r\n```cmd\r\nnpm install @sassoftware/viya-assistantjs\r\n```\r\n\r\nIn your JavaScript program import the entries.\r\nThe documentation is [here](https://sassoftware.github.io/restaf-demos/index.html)\r\n\r\n## gpt models\r\n\r\nModels used in the development of this library\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n    - The tools can be simple functions or calls to Viya or other services\r\n    - The tools can be used to satisfy user requests\r\n    - The tools can be used to upload files to the assistant\r\n    - See these links for more examples\r\n      - [Starter tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n      - [Samples](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs-samples)\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n   - The file uploaded in openai will be added to a vector store\r\n\r\nSee the two examples for a quick introduction to  this library.\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration, Use the tools defined above\r\nlet config = {\r\n  devMode: true,\r\n  provider: 'openai',\r\n  model: process.env.OPENAI_MODEL, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: null,\r\n  vectorStoreid: null,\r\n  domainTools:  {tools: tools, functionList: {myuniversity}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However this example demonstrates\r\nhow to call Viya to respond to a user query.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\nSome key points:\r\n\r\n1. The viyaConfig object is used to pass the host and token information to the\r\n   assistant. This is used to logon to Viya.\r\n2. The getViyaSession method is used to get the session information for the\r\n   assistant to call Viya.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, gptControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information (source is either cas or sas|compute)\r\n  let appEnv = await gptControl.getViyaSession(gptControl, source);\r\n\r\n  // limit the number of tables to return\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  // see https://sassoftwares.github.io/restaf for information on restafedit\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration\r\nlet config = {\r\n  devMode: true,\r\n  provider: \"openai\", // or 'azureai'\r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null, //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: null, //create a new thread\r\n  vectorStoreid: null, //create a new vector store\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant to list the tables in a sas or cas library\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {}, // your data to be passed on to the tools\r\n};\r\n```\r\n\r\n```javascript\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's \r\nanything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's\r\n anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"c915c62197a579797f6dca7d09888c2d5d310290","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","testa":"dotenvx  run -f .env.azureai -- npm run test","testd":"dotenvx  run -f .env.openai -- npm run debug","testo":"dotenvx  run -f .env.openai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.16.0_1713973520267_0.8313600246430017","host":"s3://npm-registry-packages"}},"0.16.1":{"name":"@sassoftware/viya-assistantjs","version":"0.16.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.16.1","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"615fbfccb29e137d6f4e524a1128cdfa511aba67","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.16.1.tgz","fileCount":10,"integrity":"sha512-PKmtTXClwuyqLO41fwEwniMMzsz9soQHw9hOLkwv8GTQD8iA0ORw1/YBU19TsCmsZJ53mQiXctRaxifYvUvusw==","signatures":[{"sig":"MEYCIQDmDPanK1smwXeJJWTk1acuKW4jT5eKlcNCkpDHXqoBAAIhAIwtcgvFAr1FaBCcuf+r6yALNArQQyTk3d5gPK0C3lar","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":577495},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It supports the Assistant\r\nfrom openai and Azure\r\n\r\nSee [documentation here](https://sassoftware.github.io/viya-assistantjs/)\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-works</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Usage\r\n\r\nInstall the package using npm\r\n\r\n```cmd\r\nnpm install @sassoftware/viya-assistantjs\r\n```\r\n\r\nIn your JavaScript program import the entries.\r\nThe documentation is [here](https://sassoftware.github.io/restaf-demos/index.html)\r\n\r\n## gpt models\r\n\r\nModels used in the development of this library\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n    - The tools can be simple functions or calls to Viya or other services\r\n    - The tools can be used to satisfy user requests\r\n    - The tools can be used to upload files to the assistant\r\n    - See these links for more examples\r\n      - [Starter tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n      - [Samples](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs-samples)\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n   - The file uploaded in openai will be added to a vector store\r\n\r\nSee the two examples for a quick introduction to  this library.\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuniversity',\r\n      description: 'verify the specified course is available',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuniversity(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  if (courseList.includes(course)) {\r\n    return `${course} is available`;\r\n  } else {\r\n    return `${course} is not available`;\r\n  }\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration, Use the tools defined above\r\nlet config = {\r\n  devMode: true,\r\n  provider: 'openai',\r\n  model: process.env.OPENAI_MODEL, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: null,\r\n  vectorStoreid: null,\r\n  domainTools:  {tools: tools, functionList: {myuniversity}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However this example demonstrates\r\nhow to call Viya to respond to a user query.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\nSome key points:\r\n\r\n1. The viyaConfig object is used to pass the host and token information to the\r\n   assistant. This is used to logon to Viya.\r\n2. The getViyaSession method is used to get the session information for the\r\n   assistant to call Viya.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, gptControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information (source is either cas or sas|compute)\r\n  let appEnv = await gptControl.getViyaSession(gptControl, source);\r\n\r\n  // limit the number of tables to return\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  // see https://sassoftwares.github.io/restaf for information on restafedit\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration\r\nlet config = {\r\n  devMode: true,\r\n  provider: \"openai\", // or 'azureai'\r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null, //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: null, //create a new thread\r\n  vectorStoreid: null, //create a new vector store\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant to list the tables in a sas or cas library\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {}, // your data to be passed on to the tools\r\n};\r\n```\r\n\r\n```javascript\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let gptControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(gptControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's \r\nanything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's\r\n anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"ad65735a996704a2c45188075ac0cbd2c3e467bd","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","testa":"dotenvx  run -f .env.azureai -- npm run test","testd":"dotenvx  run -f .env.openai -- npm run debug","testo":"dotenvx  run -f .env.openai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.16.1_1713989960375_0.9051192854251542","host":"s3://npm-registry-packages"}},"0.16.2":{"name":"@sassoftware/viya-assistantjs","version":"0.16.2","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.16.2","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"96826f5ff938314aad996992b705c031589f00eb","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.16.2.tgz","fileCount":10,"integrity":"sha512-7hoqurb6EJPY+sLMlGbzMqq1HN0GaLPE7BgKwCc4UPzEdY3H1e2cHSzmvX7t86N3/cD15CTn6i3vGFfUMLBb4Q==","signatures":[{"sig":"MEUCIQDiBzDjN/EmwUnlrIitHO9n51dshZ4F3a1YdMYGpHWSqgIge0UX/bHidhCxOoaaxnZISiJptipfFXccUG1qgPJln/s=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":582315},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It supports the Assistant\r\nfrom openai and Azure\r\n\r\nSee [documentation here](https://sassoftware.github.io/viya-assistantjs/)\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-works</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Usage\r\n\r\nInstall the package using npm\r\n\r\n```cmd\r\nnpm install @sassoftware/viya-assistantjs\r\n```\r\n\r\nIn your JavaScript program import the entries.\r\nThe documentation is [here](https://sassoftware.github.io/restaf-demos/index.html)\r\n\r\n## gpt models\r\n\r\nModels used in the development of this library\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n    - The tools can be simple functions or calls to Viya or other services\r\n    - The tools can be used to satisfy user requests\r\n    - The tools can be used to upload files to the assistant\r\n    - See these links for more examples\r\n      - [Starter tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n      - [Samples](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs-samples)\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n   - The file uploaded in openai will be added to a vector store\r\n\r\nSee the two examples for a quick introduction to  this library.\r\n\r\n## Tool function signature\r\n\r\nThe tool function signature is as follows:\r\n\r\n```javascript\r\nasync function myToolFunction(params, userData, appControl) {\r\n  // params: parameters passed to the tool from gpt\r\n  // userData: userData set by the developer in the configuration object\r\n  // appControl: information about the assistant(returned from setupAssistant)\r\n  // return: a string or an object\r\n}\r\n```\r\n\r\n> The appControl is the control object of the library - so do not modify\r\nthis object.\r\n\r\nThe appControl object has the following properties that are useful in the tool function:\r\n\r\n```javascript\r\n{\r\n  getViyaSession: <function>, // to get viya session information\r\n  uploadFile: <function>,// to upload content to a file\r\n}\r\n\r\n### getViyaSession\r\n\r\nThe function takes one argument, the source(cas|sas), and returns an object of type appEnv. This object has Viya sessionID and other information needed to access Viya using REST api. See <link> for more information. Some of the information is targeted to users of @sassoftware/restaf.\r\n\r\n```javascript\r\nlet appEnv = await appControl.getViyaSession('cas');\r\n```\r\n\r\n### uploadFile\r\n\r\nThis function is used to upload content. The call will result in creation of a\r\n file with the specified name.\r\n If the provider is openai,\r\n then file is added to the current vector store and used in subsequent\r\n  calls to the assistant.\r\nSee the example below\r\n\r\n```javascript\r\n\r\n    let f = await appControl.uploadFile('catalogSearch.txt', content, 'text/plain', 'assistants');\r\n    Parameters are:\r\n    - filename: name of the file to be created\r\n    - content: content to be written to the file\r\n    - mimeType: mime type of the content - see https://platform.openai.com/docs/assistants/tools/file-search/vector-stores\r\n    - purpose: assistants is the only one supported at this time\r\n```\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuni',\r\n      description: 'verify the specified course is available for myuni university',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuni(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  return (courseList.includes(course) \r\n    ?  return `${course} is available`\r\n    :  return `${course} is not available`);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration, Use the tools defined above\r\nlet config = {\r\n  devMode: true,\r\n  provider: 'openai',\r\n  model: process.env.OPENAI_MODEL,\r\n  temperature: 0.5, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: null,\r\n  vectorStoreid: null,\r\n  domainTools:  {tools: tools, functionList: {myuni}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However this example demonstrates\r\nhow to call Viya to respond to a user query.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\nSome key points:\r\n\r\n1. The viyaConfig object is used to pass the host and token information to the\r\n   assistant. This is used to logon to Viya.\r\n2. The getViyaSession method is used to get the session information for the\r\n   assistant to call Viya.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, appControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information (source is either cas or sas|compute)\r\n  let appEnv = await appControl.getViyaSession(source);\r\n\r\n  // limit the number of tables to return\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  // see https://sassoftwares.github.io/restaf for information on restafedit\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration\r\nlet config = {\r\n  devMode: true,\r\n  provider: \"openai\", // or 'azureai'\r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null, //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: null, //create a new thread\r\n  vectorStoreid: null, //create a new vector store\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant to list the tables in a sas or cas library\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {}, // your data to be passed on to the tools\r\n};\r\n```\r\n\r\n```javascript\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's \r\nanything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's\r\n anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"a9ad7c57e20527daf0c23e40ff25dd028a6abee7","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","testd":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm run test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.16.2_1714054496738_0.007569186895743929","host":"s3://npm-registry-packages"}},"0.16.3":{"name":"@sassoftware/viya-assistantjs","version":"0.16.3","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.16.3","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"21437319b18c1a02214279c39b7662df5e74e2f2","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.16.3.tgz","fileCount":10,"integrity":"sha512-ynne6tuTGWbYpreeGy2zF8bh4UZtL9DH8hnkl9pp1vlCqpy7ylgC9ubrsloWDJey9W16I9WoblTTXRo+b31PbQ==","signatures":[{"sig":"MEUCIFIb562BYNGv7D7c9Y5hVDW7tHBFGtQRqdXLIDAv5AXpAiEAxLnIRYLDX1APO5YOhyg6FYQz0RWQxDgVGe0fuizqLG8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":610449},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. It supports the Assistant\r\nfrom openai and Azure\r\n\r\nSee [documentation here](https://sassoftware.github.io/viya-assistantjs/)\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-works</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Usage\r\n\r\nInstall the package using npm\r\n\r\n```cmd\r\nnpm install @sassoftware/viya-assistantjs\r\n```\r\n\r\nIn your JavaScript program import the entries.\r\nThe documentation is [here](https://sassoftware.github.io/restaf-demos/index.html)\r\n\r\n## gpt models\r\n\r\nModels used in the development of this library\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai: gpt-4 1106 preview in zone East US 2\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n    - The tools can be simple functions or calls to Viya or other services\r\n    - The tools can be used to satisfy user requests\r\n    - The tools can be used to upload files to the assistant\r\n    - See these links for more examples\r\n      - [Starter tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n      - [Samples](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs-samples)\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n   - The file uploaded in openai will be added to a vector store\r\n\r\nSee the two examples for a quick introduction to  this library.\r\n\r\n## Tool function signature\r\n\r\nThe tool function signature is as follows:\r\n\r\n```javascript\r\nasync function myToolFunction(params, userData, appControl) {\r\n  // params: parameters passed to the tool from gpt\r\n  // userData: userData set by the developer in the configuration object\r\n  // appControl: information about the assistant(returned from setupAssistant)\r\n  // return: a string or an object\r\n}\r\n```\r\n\r\n> The appControl is the control object of the library - so do not modify\r\nthis object.\r\n\r\nThe appControl object has the following properties that are useful in the tool function:\r\n\r\n```javascript\r\n{\r\n  getViyaSession: <function>, // to get viya session information\r\n  uploadFile: <function>,// to upload content to a file\r\n}\r\n\r\n### getViyaSession\r\n\r\nThe function takes one argument, the source(cas|sas), and returns an object of type appEnv. This object has Viya sessionID and other information needed to access Viya using REST api. See <link> for more information. Some of the information is targeted to users of @sassoftware/restaf.\r\n\r\n```javascript\r\nlet appEnv = await appControl.getViyaSession('cas');\r\n```\r\n\r\n### uploadFile\r\n\r\nThis function is used to upload content. The call will result in creation of a\r\n file with the specified name.\r\n If the provider is openai,\r\n then file is added to the current vector store and used in subsequent\r\n  calls to the assistant.\r\nSee the example below\r\n\r\n```javascript\r\n\r\n    let f = await appControl.uploadFile('catalogSearch.txt', content, 'text/plain', 'assistants');\r\n    Parameters are:\r\n    - filename: name of the file to be created\r\n    - content: content to be written to the file\r\n    - mimeType: mime type of the content - see https://platform.openai.com/docs/assistants/tools/file-search/vector-stores\r\n    - purpose: assistants is the only one supported at this time\r\n```\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuni',\r\n      description: 'verify the specified course is available for myuni university',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuni(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  return (courseList.includes(course) \r\n    ?  return `${course} is available`\r\n    :  return `${course} is not available`);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration, Use the tools defined above\r\nlet config = {\r\n  devMode: true,\r\n  provider: 'openai',\r\n  model: process.env.OPENAI_MODEL,\r\n  temperature: 0.5, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: null,\r\n  vectorStoreid: null,\r\n  domainTools:  {tools: tools, functionList: {myuni}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However this example demonstrates\r\nhow to call Viya to respond to a user query.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\nSome key points:\r\n\r\n1. The viyaConfig object is used to pass the host and token information to the\r\n   assistant. This is used to logon to Viya.\r\n2. The getViyaSession method is used to get the session information for the\r\n   assistant to call Viya.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, appControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information (source is either cas or sas|compute)\r\n  let appEnv = await appControl.getViyaSession(source);\r\n\r\n  // limit the number of tables to return\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  // see https://sassoftwares.github.io/restaf for information on restafedit\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration\r\nlet config = {\r\n  devMode: true,\r\n  provider: \"openai\", // or 'azureai'\r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null, //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: null, //create a new thread\r\n  vectorStoreid: null, //create a new vector store\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant to list the tables in a sas or cas library\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {}, // your data to be passed on to the tools\r\n};\r\n```\r\n\r\n```javascript\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's \r\nanything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's\r\n anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"f0e72f0de7ca4b506ddd1955d0bf5c6c16f124ae","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","testd":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm run test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.16.3_1714156374548_0.022282529872656998","host":"s3://npm-registry-packages"}},"0.17.0":{"name":"@sassoftware/viya-assistantjs","version":"0.17.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.17.0","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"88cd472c0ecae719a44c1c234890f7d5422d34bb","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.17.0.tgz","fileCount":10,"integrity":"sha512-I7dr12fwiynfEW0A829IF2n7c0FiGrGOw2LGd+ILu+8azu645IzH0Fs4MPsZeCuV5/jny0a4WB3W+ii1eN3Dgg==","signatures":[{"sig":"MEYCIQC321bJrQKc7/Ac9ojDxU5mCQyIMZP10e2dJ6eVB9lC/gIhAIB9q8zdR8JdGObiCk32NkkOa72JYtLucSxMxMvm2jpr","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":609813},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"45488b7f066bc26aa9ba3c25fa4847a6080bb8c3","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.17.0_1714334650970_0.9754757432202681","host":"s3://npm-registry-packages"}},"0.17.1":{"name":"@sassoftware/viya-assistantjs","version":"0.17.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.17.1","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"13d9dbf2a9c220a71ba6f81219985253e49f5d0d","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.17.1.tgz","fileCount":10,"integrity":"sha512-nq+7uGoNRUPvsnRed6+hvc1af1Qx6e/+fSunGA6ENuwYql5nLsI9FEcgW8aBwti4+JYMkiBmyAPfMbClv74jrw==","signatures":[{"sig":"MEYCIQDbDfFiHBpCUIo0CDOkxl0Tx3BaTfzSP+068D3tJ8sehAIhANIxeFgfZ96rAfXch8qyP7cOsbYmnUd9zYJajZOw5vS/","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":609446},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. This  version supports OpenAI Assistant.\r\n\r\n> A note on azureai Assistant support:\r\n At the current time, AzureAI assistant does not support retrieval/file-search  tools.\r\n\r\nSee [documentation here](https://sassoftware.github.io/viya-assistantjs/)\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-works</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Usage\r\n\r\nInstall the package using npm\r\n\r\n```cmd\r\nnpm install @sassoftware/viya-assistantjs\r\n```\r\n\r\nIn your JavaScript program import the entries.\r\nThe documentation is [here](https://sassoftware.github.io/restaf-demos/index.html)\r\n\r\n## gpt models\r\n\r\nModels used in the development of this library\r\n\r\n- openai: gpt-4-turbo-preview\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n    - The tools can be simple functions or calls to Viya or other services\r\n    - The tools can be used to satisfy user requests\r\n    - The tools can be used to upload files to the assistant\r\n    - See these links for more examples\r\n      - [Starter tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n      - [Samples](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs-samples)\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n   - The file uploaded in openai will be added to a vector store\r\n\r\nSee the two examples for a quick introduction to  this library.\r\n\r\n## Tool function signature\r\n\r\nThe tool function signature used by this library is as follows.\r\n\r\n```javascript\r\nasync function myToolFunction(params, userData, appControl) {\r\n  // params: parameters passed to the tool from gpt\r\n  // userData: userData set by the developer in the configuration object\r\n  // appControl: returned from setupAssistant\r\n  // return: a string or an object\r\n}\r\n```\r\n\r\n> The appControl is the control object of the library - so do not modify\r\nthis object.\r\n\r\nThe appControl object has the following properties that are useful in the tool function:\r\n\r\n```javascript\r\n{\r\n  getViyaSession: <function>, // to get viya session information\r\n  uploadFile: <function>,// to upload content to a file\r\n}\r\n```\r\n\r\n### getViyaSession\r\n\r\nThe function takes one argument, the source(cas|sas), and returns an object of\r\ntype appEnv.This object has Viya sessionID and other information needed to access\r\nViya using REST api.\r\n\r\nSee [this link](https://sassoftware.github.io/restaf-demos/global.html#appEnv)\r\nfor details on the appEnv object.\r\n\r\n```javascript\r\nlet appEnv = await appControl.getViyaSession('cas');\r\n```\r\n\r\n### uploadFile\r\n\r\nUse this function to upload content to the assistant. in openai, the file is\r\nadded to the current vector store and available for file-search.\r\n\r\n```javascript\r\n    A sample call is shown below\r\n    let f = await appControl.uploadFile('mydoc.txt', content, 'text/plain', 'assistants');\r\n    Parameters are:\r\n    - mydoc.txt: name of the file to be created\r\n    - content: content to be written to the file\r\n    - mimeType: mime type of the content - see https://platform.openai.com/docs/assistants/tools/file-search/vector-stores\r\n    - purpose: 'assistants' is the only purpose supported at this time\r\n```\r\n\r\n## Example 1: Using the builtin tools\r\n\r\nThe library comes with a a default set of tools to help you get started.\r\nThe source code for these tools are available [here](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n\r\nThe tools are:\r\n\r\n- catalogSearch - uses the Information Catalog service to search for information\r\n  - SAS Information Catalog license required. Otherwise it will fail.\r\n- keywords - a simple tool to format comma-separated keywords(used by testing tools)\r\n- listLibrary - list libraries in a cas or sas session\r\n- listTables - list tables in a cas or sas library\r\n- readTable - read a table in a cas or sas library\r\n\r\nThe sample program is below.\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\n\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuni',\r\n      description: 'verify the specified course is available for myuni university',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuni(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  return (courseList.includes(course) \r\n    ?  return `${course} is available`\r\n    :  return `${course} is not available`);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration, Use the tools defined above\r\nlet config = {\r\n  devMode: true,\r\n  provider: 'openai',\r\n  model: process.env.OPENAI_MODEL,\r\n  temperature: 0.5, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: null,\r\n  vectorStoreid: null,\r\n  domainTools:  {tools: tools, functionList: {myuni}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However, this example demonstrates\r\nthe basics of calling Viya to respond to a user query.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\nSome key points:\r\n\r\n1. The viyaConfig object is used to pass the host and token information to the\r\n   assistant. This is used to logon to Viya.\r\n2. The getViyaSession method is used to get the session information for the\r\n   assistant to call Viya.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, appControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information (source is either cas or sas|compute)\r\n  let appEnv = await appControl.getViyaSession(source);\r\n\r\n  // limit the number of tables to return\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  // see https://sassoftwares.github.io/restaf for information on restafedit\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration\r\nlet config = {\r\n  devMode: true,\r\n  provider: \"openai\", \r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null, //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: null, //create a new thread\r\n  vectorStoreid: null, //create a new vector store\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant to list the tables in a sas or cas library\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {}, // your data to be passed on to the tools\r\n};\r\n```\r\n\r\n```javascript\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's\r\nanything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's\r\n anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"387f8400c7b3686d116356b728482b684ba99d0a","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.17.1_1714402680472_0.7525841381484466","host":"s3://npm-registry-packages"}},"0.17.2":{"name":"@sassoftware/viya-assistantjs","version":"0.17.2","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.17.2","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"6f6028e7f8c5a9189be05af6688d9fe967af716d","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.17.2.tgz","fileCount":10,"integrity":"sha512-uH3T5ijSHgCsvWommklEqKB77mT4fRejkYDGUxibbgYzfg2DFIZauIDYq5gO3+LjtZzj4MtZVzrPI7GITz9lnw==","signatures":[{"sig":"MEUCIQCW9eCtHbRrNCW4uYNQy+oXMeRJpZLB66pCP4fftCyhxwIgT7pcCw8UPw+z2LLyMaDKaM5xnULKYYOQSDswAmlJihw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":608740},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. This  version supports OpenAI Assistant.\r\n\r\n> A note on azureai Assistant support:\r\n At the current time, AzureAI assistant does not support retrieval/file-search  tools.\r\n\r\nSee [documentation here](https://sassoftware.github.io/viya-assistantjs/)\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-works</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Usage\r\n\r\nInstall the package using npm\r\n\r\n```cmd\r\nnpm install @sassoftware/viya-assistantjs\r\n```\r\n\r\nIn your JavaScript program import the entries.\r\nThe documentation is [here](https://sassoftware.github.io/restaf-demos/index.html)\r\n\r\n## gpt models\r\n\r\nModels used in the development of this library\r\n\r\n- openai: gpt-4-turbo-preview\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n    - The tools can be simple functions or calls to Viya or other services\r\n    - The tools can be used to satisfy user requests\r\n    - The tools can be used to upload files to the assistant\r\n    - See these links for more examples\r\n      - [Starter tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n      - [Samples](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs-samples)\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n   - The file uploaded in openai will be added to a vector store\r\n\r\nSee the two examples for a quick introduction to  this library.\r\n\r\n## Tool function signature\r\n\r\nThe tool function signature used by this library is as follows.\r\n\r\n```javascript\r\nasync function myToolFunction(params, userData, appControl) {\r\n  // params: parameters passed to the tool from gpt\r\n  // userData: userData set by the developer in the configuration object\r\n  // appControl: returned from setupAssistant\r\n  // return: a string or an object\r\n}\r\n```\r\n\r\n> The appControl is the control object of the library - so do not modify\r\nthis object.\r\n\r\nThe appControl object has the following properties that are useful in the tool function:\r\n\r\n```javascript\r\n{\r\n  getViyaSession: <function>, // to get viya session information\r\n  uploadFile: <function>,// to upload content to a file\r\n}\r\n```\r\n\r\n### getViyaSession\r\n\r\nThe function takes one argument, the source(cas|sas), and returns an object of\r\ntype appEnv.This object has Viya sessionID and other information needed to access\r\nViya using REST api.\r\n\r\nSee [this link](https://sassoftware.github.io/restaf-demos/global.html#appEnv)\r\nfor details on the appEnv object.\r\n\r\n```javascript\r\nlet appEnv = await appControl.getViyaSession('cas');\r\n```\r\n\r\n### uploadFile\r\n\r\nUse this function to upload content to the assistant. in openai, the file is\r\nadded to the current vector store and available for file-search.\r\n\r\n```javascript\r\n    A sample call is shown below\r\n    let f = await appControl.uploadFile('mydoc.txt', content, 'text/plain', 'assistants');\r\n    Parameters are:\r\n    - mydoc.txt: name of the file to be created\r\n    - content: content to be written to the file\r\n    - mimeType: mime type of the content - see https://platform.openai.com/docs/assistants/tools/file-search/vector-stores\r\n    - purpose: 'assistants' is the only purpose supported at this time\r\n```\r\n\r\n## Example 1: Using the builtin tools\r\n\r\nThe library comes with a a default set of tools to help you get started.\r\nThe source code for these tools are available [here](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n\r\nThe tools are:\r\n\r\n- catalogSearch - uses the Information Catalog service to search for information\r\n  - SAS Information Catalog license required. Otherwise it will fail.\r\n- keywords - a simple tool to format comma-separated keywords(used by testing tools)\r\n- listLibrary - list libraries in a cas or sas session\r\n- listTables - list tables in a cas or sas library\r\n- readTable - read a table in a cas or sas library\r\n\r\nThe sample program is below.\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\n\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuni',\r\n      description: 'verify the specified course is available for myuni university',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuni(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  return (courseList.includes(course) \r\n    ?  return `${course} is available`\r\n    :  return `${course} is not available`);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration, Use the tools defined above\r\nlet config = {\r\n  devMode: true,\r\n  provider: 'openai',\r\n  model: process.env.OPENAI_MODEL,\r\n  temperature: 0.5, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: null,\r\n  vectorStoreid: null,\r\n  domainTools:  {tools: tools, functionList: {myuni}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However, this example demonstrates\r\nthe basics of calling Viya to respond to a user query.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\nSome key points:\r\n\r\n1. The viyaConfig object is used to pass the host and token information to the\r\n   assistant. This is used to logon to Viya.\r\n2. The getViyaSession method is used to get the session information for the\r\n   assistant to call Viya.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, appControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information (source is either cas or sas|compute)\r\n  let appEnv = await appControl.getViyaSession(source);\r\n\r\n  // limit the number of tables to return\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  // see https://sassoftwares.github.io/restaf for information on restafedit\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration\r\nlet config = {\r\n  devMode: true,\r\n  provider: \"openai\", \r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null, //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: null, //create a new thread\r\n  vectorStoreid: null, //create a new vector store\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant to list the tables in a sas or cas library\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {}, // your data to be passed on to the tools\r\n};\r\n```\r\n\r\n```javascript\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's\r\nanything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's\r\n anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"9eccec502a1fa4618e96f00e46f427d31a2436c7","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.17.2_1714408421937_0.04441591404300249","host":"s3://npm-registry-packages"}},"0.17.4":{"name":"@sassoftware/viya-assistantjs","version":"0.17.4","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.17.4","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"6ef72bd9e082500c8fb08123a3223ac1d3019216","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.17.4.tgz","fileCount":10,"integrity":"sha512-NzCPSP8MuZACjkLq5y/mUvsPElUEXs+fzkVGSeB0rNKsOJNHy9HM30BAGGN2f++r5xzzMc5J54GsfVbvj+eB4w==","signatures":[{"sig":"MEYCIQD6eY0Y6IwQpTjQPotVPQmqWlb185bd/CqFAY+LOfzS0gIhAO10bZxC/78vPNxX0Vgec19hXDXrggfYfcLgoUpsoVQ/","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":611889},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"2a773929abe2a7b26fb2a9de6da120ed78d0baa1","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.17.4_1714487852750_0.09750196542265788","host":"s3://npm-registry-packages"}},"0.17.5":{"name":"@sassoftware/viya-assistantjs","version":"0.17.5","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.17.5","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"cfa8147106887d91d2d78ab87b6adac3970c4898","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.17.5.tgz","fileCount":10,"integrity":"sha512-E3hQsfAaQQuNXz4RZmLEh6bjYZ28+srykTJ4UshMTSGSaC7ygbyXRE/LEckn7AqQFwjtPxYtfwmkLN9gSqFW3Q==","signatures":[{"sig":"MEUCICki648a6lzoQVZrEZDANmzev1+5VdAaCs/zBovXE8FtAiEAtKjYD3kexSRDDBlDl1kj6ykhjuuQIbKlcLZ/nDWDfz4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":615088},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"9df6b4110bf8ce4f75c3d39d5b48bf6c378e7fd5","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.17.5_1714506311241_0.9596563905713507","host":"s3://npm-registry-packages"}},"0.18.0":{"name":"@sassoftware/viya-assistantjs","version":"0.18.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.18.0","maintainers":[{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"cbf531f385094b03e4a77ce3e4384df3227f8f5d","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.18.0.tgz","fileCount":10,"integrity":"sha512-YPZRsouSqp+q7UpKdOah3BIJyZ382J1MO1Z9Ks8QDRG+v2XUX5Z6iCzUtBIo4SaS+WG73bTgFJKQW39VhfMojQ==","signatures":[{"sig":"MEYCIQDBwLJpwSQggatepG067juXi9eLln7yCk1qAR2nQhiPdgIhAJmcen4U2TuarxXXmoUFXsZOwtFB0GBQLRHsclI9F1/m","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":615853},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"64400b586bd7ea92bf35e71050da5fa46fa3c672","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.18.0_1714573157943_0.9170449220312762","host":"s3://npm-registry-packages"}},"0.18.1":{"name":"@sassoftware/viya-assistantjs","version":"0.18.1","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.18.1","maintainers":[{"name":"daarth","email":"Daniel.Arthur@sas.com"},{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"3c4b1bb98d1894b036fe4ee59c4d13eb10e1119e","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.18.1.tgz","fileCount":10,"integrity":"sha512-JvmWdf8vOE5FkVHTy/jXjnfC5KyNBRnOi8WQYNsjZoH+OdH+NoF1/TTLDIMgd1KANdBXk/lvwF/m88Nx1wsJWg==","signatures":[{"sig":"MEUCIHwQXGO7Tv2AHvuzU+xtsPCNsvivX5RyIr45s10XJaXwAiEA9RjDlcxAQPnRM/3XX+/qd1t3gDIymoEr7X8YWjQFx2c=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":615998},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"13a60baa4f8b1569194787bd02065a7a22d62b03","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.18.1_1714664582900_0.3024647848193154","host":"s3://npm-registry-packages"}},"0.19.0":{"name":"@sassoftware/viya-assistantjs","version":"0.19.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.19.0","maintainers":[{"name":"daarth","email":"Daniel.Arthur@sas.com"},{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"235076be97660c9aa3dbda99836575ed9cf1a418","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.19.0.tgz","fileCount":10,"integrity":"sha512-UqQJPdw1y+Selj8kvqkvTnkp5+8XLnIZHfzLu//hfvArVFivqfE0oIEw9sDGwhepcxWEw+NL9pL0qC2BTLcI9w==","signatures":[{"sig":"MEUCIQCxOKM5wVSoWh7jmiP7mPT3F3Vg4HSfWFvgWSFyDgWYvwIgSgpxB2sgonTdbfVlpLB3NttZYbGXvpbq33IWOnrxoo4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":626503},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"431407911c63140344009d9d82eba24301c9a0f3","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.19.0_1714853110608_0.7195524146100853","host":"s3://npm-registry-packages"}},"0.20.0":{"name":"@sassoftware/viya-assistantjs","version":"0.20.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.20.0","maintainers":[{"name":"daarth","email":"Daniel.Arthur@sas.com"},{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"22ff6a957eee8f69c6926652d2137d690b79c82a","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.20.0.tgz","fileCount":10,"integrity":"sha512-UNOjPL61tsWRX6McAWSvfZRwJiI9KReR0nuCQUJLEr/uCYc1xiv0u3WelSPA1eNYopWMkv5Zb/HKVGi35CvKUA==","signatures":[{"sig":"MEYCIQDp56Sn86IcR/5AfZBaI/VPFNrN5qib8+TR4TVB/y6/EwIhAJ7JDXuYMDPSmrKVRMcwW9bgiZRrJx4bvgeb1a2SFdXT","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":652977},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. This  version supports OpenAI Assistant.\r\n\r\n> A note on azureai Assistant support:\r\n At the current time, AzureAI assistant does not support retrieval/file-search  tools.\r\n\r\nSee [documentation here](https://sassoftware.github.io/viya-assistantjs/)\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-works</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Usage\r\n\r\nInstall the package using npm\r\n\r\n```cmd\r\nnpm install @sassoftware/viya-assistantjs\r\n```\r\n\r\nIn your JavaScript program import the entries.\r\nThe documentation is [here](https://sassoftware.github.io/restaf-demos/index.html)\r\n\r\nSee the [tutorial section](https://sassoftware.github.io/restaf-demos/index.html) \r\nfor examples on the various capabilities of this library.\r\n\r\n## gpt models\r\n\r\nSpecify the models to use in the configuration object. The library was developed using the\r\nthe following:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai(eastus2): Model: gpt-4 version: 1106-preview\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n    - The tools can be simple functions or calls to Viya or other services\r\n    - The tools can be used to satisfy user requests\r\n    - The tools can be used to upload files to the assistant\r\n    - See these links for more examples\r\n      - [Starter tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n      - [Samples](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs-samples)\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n   - The file uploaded in openai will be added to a vector store\r\n\r\nSee the two examples for a quick introduction to  this library.\r\n\r\n## Tool function signature\r\n\r\nThe tool function signature used by this library is as follows.\r\n\r\n```javascript\r\nasync function myToolFunction(params, userData, appControl) {\r\n  // params: parameters passed to the tool from gpt\r\n  // userData: userData set by the developer in the configuration object\r\n  // appControl: returned from setupAssistant\r\n  // return: a string or an object\r\n}\r\n```\r\n\r\n> The appControl is the control object returned by setupAssistant. \r\nDo not modify this object.\r\n\r\nThe appControl object has the following properties that are useful in the tool function:\r\n\r\n```javascript\r\n{\r\n  getViyaSession: <function>, // to get viya session information\r\n  uploadFile: <function>,// to upload content to a file\r\n}\r\n```\r\n\r\n### getViyaSession\r\n\r\nThe function takes one argument, the source(cas|sas), and returns an object of\r\ntype appEnv.This object has sessionID for specified source \r\nand other information needed to access Viya using REST api.\r\n\r\nSee [this link](https://sassoftware.github.io/restaf-demos/global.html#appEnv)\r\nfor details on the appEnv object.\r\n\r\n```javascript\r\nlet appEnv = await appControl.getViyaSession('cas');\r\n```\r\n\r\n### uploadFile\r\n\r\nUse this function to upload content to the assistant. in openai, the file is\r\nadded to the current vector store and available for file-search.\r\n\r\n```javascript\r\n    A sample call is shown below\r\n    let f = await appControl.uploadFile('mydoc.txt', content, 'text/plain', 'assistants');\r\n    Parameters are:\r\n    - mydoc.txt: name of the file to be created\r\n    - content: content to be written to the file\r\n    - mimeType: mime type of the content - see https://platform.openai.com/docs/assistants/tools/file-search/vector-stores\r\n    - purpose: 'assistants' is the only purpose supported at this time\r\n\r\n    The return value is the following object:\r\n    {\r\n      \"fileName:  <name of file>\r\n      \"fileid: \"<id of the file>\",\r\n      \"vectorStoreid\": \"<id of the vector store(for azure)>\",\r\n    }\r\n```\r\n\r\n## devMode flag\r\n\r\nThis is a flag you can set in the configuration flag. When set to true,\r\nthe setupAssistant will do the following:\r\n\r\n1. If an assistant with specified name exists, the following will be deleted:\r\n    - assistant\r\n    - thread used during the last session\r\n    - vectorStore used during the last session\r\n2. Any files uploaded during the last session will be deleted.\r\n\r\nThis ensures that the new test session is clean and does not have\r\nany artifacts from the previous runs.\r\n\r\n## Response from runAssistant\r\n\r\nThe response from runAssistant is an array of objects. Each object has the \r\nfollowing properties:\r\n\r\n```javascript\r\n[\r\n    {\r\n        \"id\": <id of the message>,\r\n        \"role\": \"assistant\",\r\n        \"type\": <type of content, usually text>\r\n        \"content\": <The content of the message>\r\n    }\r\n]\r\n\r\n## Builtin Tools\r\n\r\nThe library comes with a set of [builtin tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs) to help you get started.\r\n\r\nTo use these, set the domainTools property in the configuration object as follows:\r\n  \r\n```javascript\r\n{\r\n  tools: [],\r\n  functionList: {},\r\n  instructions: ''\r\n}\r\n```\r\n\r\nThe builtin tools are:\r\n\r\n- catalogSearch - uses the Information Catalog service to search for information\r\n- keywords - a simple tool to format comma-separated keywords(used by testing tools)\r\n- listLibrary - list libraries in a cas or sas session\r\n- listTables - list tables in a cas or sas library\r\n- readTable - read a table in a cas or sas library\r\n.\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\n\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuni',\r\n      description: 'verify the specified course is available for myuni university',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuni(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  return (courseList.includes(course) \r\n    ?  return `${course} is available`\r\n    :  return `${course} is not available`);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration, Use the tools defined above\r\nlet config = {\r\n  devMode: true,\r\n  provider: 'openai',\r\n  model: process.env.OPENAI_MODEL,\r\n  temperature: 0.5, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: null,\r\n  vectorStoreid: null,\r\n  domainTools:  {tools: tools, functionList: {myuni}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However, this example demonstrates\r\nthe basics of calling Viya to respond to a user query.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\nSome key points:\r\n\r\n1. The viyaConfig object is used to pass the host and token information to the\r\n   assistant. This is used to logon to Viya.\r\n2. The getViyaSession method is used to get the session information for the\r\n   assistant to call Viya.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, appControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information (source is either cas or sas|compute)\r\n  let appEnv = await appControl.getViyaSession(source);\r\n\r\n  // limit the number of tables to return\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  // see https://sassoftwares.github.io/restaf for information on restafedit\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration\r\nlet config = {\r\n  devMode: true,\r\n  provider: \"openai\", \r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null, //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: null, //create a new thread\r\n  vectorStoreid: null, //create a new vector store\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant to list the tables in a sas or cas library\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {}, // your data to be passed on to the tools\r\n};\r\n```\r\n\r\n```javascript\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's\r\nanything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's\r\n anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"8edf1b382d7a84ff5e58f89d54f872040f3a729d","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.20.0_1715002620728_0.4206566178395523","host":"s3://npm-registry-packages"}},"0.21.0":{"name":"@sassoftware/viya-assistantjs","version":"0.21.0","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","_id":"@sassoftware/viya-assistantjs@0.21.0","maintainers":[{"name":"daarth","email":"Daniel.Arthur@sas.com"},{"name":"martin-coutts-sas","email":"martin.coutts@sas.com"},{"name":"romacf","email":"robert.macfarlane@sas.com"},{"name":"mtlhmo","email":"harry.moore@sas.com"},{"name":"timothy.crider-sas","email":"timothy.crider@sas.com"},{"name":"mtlstg","email":"stephen.gemmell@sas.com"},{"name":"kenjackson","email":"kenj55@gmail.com"},{"name":"ryanauldsas","email":"ryan.auld@sas.com"},{"name":"mtlsmc","email":"stephen.mckenna@sas.com"},{"name":"coalman","email":"tehcoalman@gmail.com"},{"name":"jefurbee","email":"joe.furbee@sas.com"},{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},{"name":"ckedwards","email":"ckedwards24@gmail.com"},{"name":"rbtlevey","email":"robert.levey@sas.com"},{"name":"brmorr","email":"bradley.morris@sas.com"},{"name":"bjtomlin","email":"ben.tomlinson@sas.com"},{"name":"jolyna","email":"Josh.Lyna@sas.com"}],"homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"dist":{"shasum":"18ba2c8da54186dbe29b20bbd0c54cb11c20becb","tarball":"https://registry.npmjs.org/@sassoftware/viya-assistantjs/-/viya-assistantjs-0.21.0.tgz","fileCount":10,"integrity":"sha512-0d6k/clnBcch19BWK6G0+vLg8fS8hrsaLa8KM0IIKEnntquSRnk48DT59l436M2IOoxCxkUi9r4p0/DTcPPGzQ==","signatures":[{"sig":"MEYCIQDAdvxNBy/M9yxwn2n8u53jUZWOEedhcREvZTAttf7MvgIhAOgjp4i+4D5zrbNYk6LnnK6wfT+7+pPZFrAMnTFNp0Zj","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":649531},"main":"./dist/index.js","type":"module","unpkg":"./dist/index.umd.js","module":"./dist/index.module.js","readme":"# @sassoftware/viya-assistantjs - Build your own AI ASSISTANT for SAS Viya\r\n\r\n@sassoftware/viya-assistantjs is a light weight JavaScript library to help SAS\r\nusers build AI Assistants with minimal coding. This  version supports OpenAI Assistant.\r\n\r\n> A note on azureai Assistant support:\r\n At the current time, AzureAI assistant does not support retrieval/file-search  tools.\r\n\r\nSee [documentation here](https://sassoftware.github.io/viya-assistantjs/)\r\n\r\nSee\r\n<a href=\"https://platform.openai.com/docs/assistants/how-it-works\">how-it-works</a>\r\nfor clear explanation of openai Assistant.\r\n\r\n## Usage\r\n\r\nInstall the package using npm\r\n\r\n```cmd\r\nnpm install @sassoftware/viya-assistantjs\r\n```\r\n\r\nIn your JavaScript program import the entries.\r\nThe documentation is [here](https://sassoftware.github.io/restaf-demos/index.html)\r\n\r\nSee the [tutorial section](https://sassoftware.github.io/restaf-demos/index.html) \r\nfor examples on the various capabilities of this library.\r\n\r\n## gpt models\r\n\r\nSpecify the models to use in the configuration object. The library was developed using the\r\nthe following:\r\n\r\n- openai: gpt-4-turbo-preview\r\n- azureai(eastus2): Model: gpt-4 version: 1106-preview\r\n\r\n## Basic flow\r\n\r\n1. Setup configuration object with information about the provider, model, credentials\r\n2. Create tools or use the builtin tools to satisfy user requests\r\n    - The tools can be simple functions or calls to Viya or other services\r\n    - The tools can be used to satisfy user requests\r\n    - The tools can be used to upload files to the assistant\r\n    - See these links for more examples\r\n      - [Starter tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs)\r\n      - [Samples](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs-samples)\r\n\r\n3. Call the *setupAssistant* method with this information\r\nalong with other configuration information.\r\n4. Submit user prompt using the *runAssistant* method\r\n   - The prompt might be resolved by gpt(ex: Who is CEO of SAS Institute)\r\n   - The prompt might request viya-assistantjs to call one of the tools to\r\n   satisfy the request. This is where the rest api call to SAS will happen.\r\n5. Process this response and repeat step 4.\r\n6. Additionally you can use the *uploadFile* method\r\nto upload information to the Assistant for use with the retrieval or\r\ncode_interpreter tool.\r\n   - The file uploaded in openai will be added to a vector store\r\n\r\nSee the two examples for a quick introduction to  this library.\r\n\r\n## Tool function signature\r\n\r\nThe tool function signature used by this library is as follows.\r\n\r\n```javascript\r\nasync function myToolFunction(params, userData, appControl) {\r\n  // params: parameters passed to the tool from gpt\r\n  // userData: userData set by the developer in the configuration object\r\n  // appControl: returned from setupAssistant\r\n  // return: a string or an object\r\n}\r\n```\r\n\r\n> The appControl is the control object returned by setupAssistant. \r\nDo not modify this object.\r\n\r\nThe appControl object has the following properties that are useful in the tool function:\r\n\r\n```javascript\r\n{\r\n  getViyaSession: <function>, // to get viya session information\r\n  uploadFile: <function>,// to upload content to a file\r\n}\r\n```\r\n\r\n### getViyaSession\r\n\r\nThe function takes one argument, the source(cas|sas), and returns an object of\r\ntype appEnv.This object has sessionID for specified source \r\nand other information needed to access Viya using REST api.\r\n\r\nSee [this link](https://sassoftware.github.io/restaf-demos/global.html#appEnv)\r\nfor details on the appEnv object.\r\n\r\n```javascript\r\nlet appEnv = await appControl.getViyaSession('cas');\r\n```\r\n\r\n### uploadFile\r\n\r\nUse this function to upload content to the assistant. in openai, the file is\r\nadded to the current vector store and available for file-search.\r\n\r\n```javascript\r\n    A sample call is shown below\r\n    let f = await appControl.uploadFile('mydoc.txt', content, 'text/plain', 'assistants');\r\n    Parameters are:\r\n    - mydoc.txt: name of the file to be created\r\n    - content: content to be written to the file\r\n    - mimeType: mime type of the content - see https://platform.openai.com/docs/assistants/tools/file-search/vector-stores\r\n    - purpose: 'assistants' is the only purpose supported at this time\r\n\r\n    The return value is the following object:\r\n    {\r\n      \"fileName:  <name of file>\r\n      \"fileid: \"<id of the file>\",\r\n      \"vectorStoreid\": \"<id of the vector store(for azure)>\",\r\n    }\r\n```\r\n\r\n## devMode flag\r\n\r\nThis is a flag you can set in the configuration flag. When set to true,\r\nthe setupAssistant will do the following:\r\n\r\n1. If an assistant with specified name exists, the following will be deleted:\r\n    - assistant\r\n    - thread used during the last session\r\n    - vectorStore used during the last session\r\n2. Any files uploaded during the last session will be deleted.\r\n\r\nThis ensures that the new test session is clean and does not have\r\nany artifacts from the previous runs.\r\n\r\n## Response from runAssistant\r\n\r\nThe response from runAssistant is an array of objects. Each object has the \r\nfollowing properties:\r\n\r\n```javascript\r\n[\r\n    {\r\n        \"id\": <id of the message>,\r\n        \"role\": \"assistant\",\r\n        \"type\": <type of content, usually text>\r\n        \"content\": <The content of the message>\r\n    }\r\n]\r\n\r\n## Builtin Tools\r\n\r\nThe library comes with a set of [builtin tools](https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs/src/builtins/tools/functionWithSpecs) to help you get started.\r\n\r\nTo use these, set the domainTools property in the configuration object as follows:\r\n  \r\n```javascript\r\n{\r\n  tools: [],\r\n  functionList: {},\r\n  instructions: ''\r\n}\r\n```\r\n\r\nThe builtin tools are:\r\n\r\n- catalogSearch - uses the Information Catalog service to search for information\r\n- keywords - a simple tool to format comma-separated keywords(used by testing tools)\r\n- listLibrary - list libraries in a cas or sas session\r\n- listTables - list tables in a cas or sas library\r\n- readTable - read a table in a cas or sas library\r\n.\r\n\r\n## Example 1: Creating a AI Assistant with a simple custom tool<a name=\"default\"></a>\r\n\r\nSee notes in the program below\r\n\r\n```javascript\r\n\r\n// Step 1: Import the necessary modules\r\nimport * as readline from 'node:readline/promises';\r\nimport { stdin as input, stdout as output } from 'node:process';\r\n\r\nimport getToken from './getToken.js';\r\nimport {setupAssistant, runAssistant} from '@sassoftware/viya-assistantjs';\r\nlet {host, token} = getToken();\r\n//getToken is defined at the end of the program below\r\n\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nlet tools = [\r\n  {\r\n    type: 'function',\r\n    function: {\r\n      name: 'myuni',\r\n      description: 'verify the specified course is available for myuni university',\r\n      parameters: {\r\n        properties: {\r\n          course: {\r\n              type: 'string',\r\n              description: 'the name of the course',\r\n            },\r\n          },\r\n          type: 'object',\r\n          required: ['course'],\r\n        },\r\n      },\r\n  },\r\n];\r\n\r\nasync function myuni(params, appEnv) {\r\n  let { course } = params;\r\n  const courseList = ['math', 'science', 'english', 'history', 'art'];\r\n  return (courseList.includes(course) \r\n    ?  return `${course} is available`\r\n    :  return `${course} is not available`);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration, Use the tools defined above\r\nlet config = {\r\n  devMode: true,\r\n  provider: 'openai',\r\n  model: process.env.OPENAI_MODEL,\r\n  temperature: 0.5, \r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n  threadid: null,\r\n  vectorStoreid: null,\r\n  domainTools:  {tools: tools, functionList: {myuni}, instructions: 'Assistant for myUniverity'},\r\n  viyaConfig: {\r\n    logonPayload: null\r\n  },\r\n  userData: {}\r\n}\r\n\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log('done'))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question('>');\r\n    // exit session\r\n    if (prompt.toLowerCase() === 'exit' || prompt.toLowerCase() === 'quit') {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = ' ';\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt,promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n\r\n## Run the program\r\n\r\n```cmd\r\nnode index.js\r\n```\r\n\r\nIf everthing was setup properly, your should get a prompt(>). Enter your prompts\r\nand get results.\r\n\r\n### Sample prompts for Example1\r\n\r\nPrompt: can I take a math course?\r\nResponse: Yes, you can take the Math course at myUniversity as it is available.\r\n\r\nPrompt: can I take courses on Dune?\r\nResponse: The course in \"Dune\" is not available at the university.\r\n\r\nPrompt: can I take course in math, physics and chemistry?\r\nResponse: Here are the availability statuses for the courses you inquired about:\r\n\r\n- Math: Available\r\n- Physics: Not available\r\n- Chemistry: Not available\r\n\r\n---\r\n\r\n## Creating a AI Assistant with a Viya-based tool<a name=\"extend\"></a>\r\n\r\nThis example has a tool to list tables in a given caslib or libref. Clearly one\r\nwould not use AI Assistant for this purpose. However, this example demonstrates\r\nthe basics of calling Viya to respond to a user query.\r\n\r\nThis example uses @sassoftware/restafedit to make the API calls. You can\r\nuse other ways to call Viya and get responses.\r\n\r\nSome key points:\r\n\r\n1. The viyaConfig object is used to pass the host and token information to the\r\n   assistant. This is used to logon to Viya.\r\n2. The getViyaSession method is used to get the session information for the\r\n   assistant to call Viya.\r\n\r\n```javascript\r\n// Step 1: Import the necessary modules\r\nimport * as readline from \"node:readline/promises\";\r\nimport { stdin as input, stdout as output } from \"node:process\";\r\nimport getToken from \"./getToken.js\";\r\nimport { setupAssistant, runAssistant } from \"@sassoftware/viya-assistantjs\";\r\nlet { host, token } = getToken();\r\n```\r\n\r\n```javascript\r\n//Step 2: Define the custom tools\r\n\r\nconst tools = [\r\n  {\r\n    type: \"function\",\r\n    function: {\r\n      name: \"listTables\",\r\n      description: `for a given library for  either sas or cas source, get the list of available tables.\r\n      (ex: list tables in cas library samples, list tables in sas library sashelp)\r\n      Optionally let user specify the source as cas or compute.`,\r\n      parameters: {\r\n        properties: {\r\n          library: {\r\n            type: \"string\",\r\n            description: \"A SAS library like casuser, sashelp, samples\",\r\n          },\r\n          start: {\r\n            type: \"integer\",\r\n            description: \"Start at lookup at this index. Default is 0.\",\r\n          },\r\n          limit: {\r\n            type: \"integer\",\r\n            description:\r\n              \"Return only this many tables. If not specified, then return 10 tables.\",\r\n          },\r\n          source: {\r\n            type: \"string\",\r\n            description: \"The source of the data. cas or compute\",\r\n            enum: [\"cas\", \"compute\"],\r\n          },\r\n        },\r\n        type: \"object\",\r\n        required: [\"library\"],\r\n      },\r\n    },\r\n  },\r\n];\r\nasync function listTables(params, userData, appControl) {\r\n  let { library, source, start, limit } = params;\r\n  // get session information (source is either cas or sas|compute)\r\n  let appEnv = await appControl.getViyaSession(source);\r\n\r\n  // limit the number of tables to return\r\n  let p = {\r\n    qs: {\r\n      limit: limit == null ? 10 : limit,\r\n      start: start == null ? 0 : start,\r\n    },\r\n  };\r\n\r\n  // get the list of libs for the selected source\r\n  // see https://sassoftwares.github.io/restaf for information on restafedit\r\n  let r = await appEnv.restafedit.getTableList(library, appEnv, p);\r\n  return JSON.stringify(r);\r\n}\r\n```\r\n\r\n```javascript\r\n// Step 3: setup configuration\r\nlet config = {\r\n  devMode: true,\r\n  provider: \"openai\", \r\n  model: process.env.OPENAI_MODEL,\r\n  credentials: {\r\n    key: process.env.OPENAI_KEY, // obtain from provider\r\n  },\r\n  assistantid: null, //create a new assistant\r\n  assistantName: \"SAS_ASSISTANT\",\r\n\r\n  threadid: null, //create a new thread\r\n  vectorStoreid: null, //create a new vector store\r\n  domainTools: {\r\n    tools: tools,\r\n    functionList: { listTables },\r\n    instructions: \"Assistant to list the tables in a sas or cas library\",\r\n  },\r\n  viyaConfig: {\r\n    logonPayload: {\r\n      authType: \"server\",\r\n      host: host,\r\n      token: token,\r\n      tokenType: \"bearer\",\r\n    },\r\n  },\r\n  userData: {}, // your data to be passed on to the tools\r\n};\r\n```\r\n\r\n```javascript\r\n// run a chat session\r\nchat(config)\r\n  .then((r) => console.log(\"done\"))\r\n  .catch((err) => console.log(err));\r\n\r\nasync function chat(config) {\r\n  //Setup assistant\r\n  let appControl = await setupAssistant(config);\r\n\r\n  // create readline interface and chat with user\r\n  const rl = readline.createInterface({ input, output });\r\n\r\n  // process user input in a loop\r\n  while (true) {\r\n    let prompt = await rl.question(\">\");\r\n    // exit session\r\n    if (prompt.toLowerCase() === \"exit\" || prompt.toLowerCase() === \"quit\") {\r\n      rl.close();\r\n      break;\r\n    }\r\n    // let assistant process the prompt\r\n    let promptInstructions = \" \";\r\n    try {\r\n      // run prompt\r\n      let response = await runAssistant(appControl, prompt, promptInstructions);\r\n      console.log(response[0].content);\r\n    } catch (err) {\r\n      console.log(err);\r\n    }\r\n  }\r\n}\r\n  \r\n```\r\n\r\n## Sample prompts and responses\r\n\r\nPrompt: list sas tables in sashelp\r\nResponse: Here are the tables available in the SAS library named \"sashelp\":\r\n\r\n1. `AACOMP`\r\n2. `AARFM`\r\n3. `ADSMSG`\r\n4. `AFMSG`\r\n5. `AIR`\r\n6. `AIRLINE`\r\n7. `AIRSHIFT`\r\n8. `AMLMSG`\r\n9. `APPLIANC`\r\n10. `ARSTOP`\r\n\r\nPlease let me know if you need details on any of these tables or if there's\r\nanything else I can assist you with.\r\n\r\nPrompt: list tables in cas library Public\r\nResponse:Here are the tables available in the CAS library named \"Public\":\r\n\r\n1. `CARS`\r\n2. `STUDENTS_TRAIN`\r\n3. `HEART_DISEASE`\r\n4. `BREASTSDG`\r\n5. `ADULT_TRAIN`\r\n6. `ADULT_TEST`\r\n7. `CMS_OPIOID_SDOH`\r\n8. `BANKING`\r\n9. `STUDENTS_TEST`\r\n10. `BIKE_SHARING_DEMAND`\r\n\r\nPlease let me know if you need information on any of these tables or if there's\r\n anything else I can assist you with.\r\n","source":"./src/index.js","engines":{"npm":">=9.7.2","node":">=18.0.0"},"exports":{"import":"./dist/index.modern.js","require":"./dist/index.js"},"gitHead":"7ad40e7ae727c296475f2401bf08ac689c0f579c","scripts":{"pub":"npm publish --tag dev --access public","lint":"eslint . --ext .js --fix","test":"cd example &&  node cli.js","build":"rimraf dist && microbundle --name viyaAssistantjs","debug":"cd example && cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk cli","jsdoc":"rimraf docs && jsdoc -c jsdoc.json","start":"cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --no-warnings cli","debuga":"dotenvx  run -f .env.azureai -- npm run debug","debugo":"dotenvx  run -f .env.openai -- npm run debug","openai":"dotenvx  run -f .env.openai -- npm test","azureai":"dotenvx  run -f .env.azureai -- npm test"},"_npmUser":{"name":"devakumaraswamy","email":"deva.kumar@sas.com"},"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"_npmVersion":"9.7.2","description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","directories":{},"_nodeVersion":"20.4.0","dependencies":{"openai":"^4.38.3","@azure/openai":"^1.0.0-beta.12","@sassoftware/restafedit":"^2.4.8","@azure/openai-assistants":"^1.0.0-beta.5"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jsdoc":"^4.0.2","dotenv":"^16.4.5","eslint":"^8.56.0","rimraf":"^3.0.2","inquirer":"^9.2.15","cross-env":"^7.0.3","better-docs":"^2.7.3","microbundle":"^0.15.1","babel-loader":"^9.1.3","eslint-plugin-n":"^16.6.2","@dotenvx/dotenvx":"^0.35.1"},"_npmOperationalInternal":{"tmp":"tmp/viya-assistantjs_0.21.0_1715806370567_0.41871453005344716","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-03-12T16:04:28.162Z","modified":"2026-08-25T15:21:02.263Z","0.1.0":"2024-03-12T16:04:28.504Z","0.2.0":"2024-03-12T16:24:31.823Z","0.2.1":"2024-03-12T17:42:17.982Z","0.2.2":"2024-03-12T19:22:13.125Z","0.2.3":"2024-03-13T20:03:18.750Z","0.3.0":"2024-03-14T14:03:28.756Z","0.3.3":"2024-03-14T15:58:41.553Z","0.4.0":"2024-03-15T14:17:20.435Z","0.5.0":"2024-03-17T17:25:48.845Z","0.5.1":"2024-03-17T20:04:42.741Z","0.6.0":"2024-03-18T10:58:57.530Z","0.6.2":"2024-03-18T19:46:21.149Z","0.6.4":"2024-03-19T11:06:21.531Z","0.6.5":"2024-03-19T12:26:45.364Z","0.6.6":"2024-03-19T13:04:04.245Z","0.6.7":"2024-03-19T13:39:21.059Z","0.6.8":"2024-03-19T14:06:20.583Z","0.7.0":"2024-03-19T19:31:55.107Z","0.7.1":"2024-03-19T20:02:53.522Z","0.9.0":"2024-03-20T14:19:17.696Z","0.9.1":"2024-03-21T18:55:49.703Z","0.9.2":"2024-03-21T19:25:29.571Z","0.9.3":"2024-03-22T12:26:55.915Z","0.9.4":"2024-03-22T14:51:20.130Z","0.9.5":"2024-03-22T16:53:59.452Z","0.9.6":"2024-03-22T17:54:58.566Z","0.9.7":"2024-03-25T13:22:02.573Z","0.9.8":"2024-03-25T14:24:59.001Z","0.9.9":"2024-03-25T14:52:21.355Z","0.9.10":"2024-03-25T15:22:50.883Z","0.9.11":"2024-03-25T15:48:41.998Z","0.9.12":"2024-03-25T16:10:40.674Z","0.10.0":"2024-03-25T16:50:54.912Z","0.10.1":"2024-03-25T17:13:46.905Z","0.10.2":"2024-03-25T19:48:54.874Z","0.10.3":"2024-03-25T21:29:10.549Z","0.10.4":"2024-03-25T22:05:58.129Z","0.10.5":"2024-03-26T15:40:59.173Z","0.10.6":"2024-03-26T17:39:19.617Z","0.10.8":"2024-03-27T13:09:58.256Z","0.10.9":"2024-03-27T22:28:23.987Z","0.10.10":"2024-03-27T22:46:41.065Z","0.10.11":"2024-03-28T12:40:39.966Z","0.10.12":"2024-03-28T21:35:02.246Z","0.11.0":"2024-03-28T22:14:14.228Z","0.11.1":"2024-04-02T11:59:21.460Z","0.12.0":"2024-04-03T15:31:19.788Z","0.14.0":"2024-04-15T22:01:21.646Z","0.15.0":"2024-04-23T19:16:34.406Z","0.16.0":"2024-04-24T15:45:20.452Z","0.16.1":"2024-04-24T20:19:20.635Z","0.16.2":"2024-04-25T14:14:56.886Z","0.16.3":"2024-04-26T18:32:54.765Z","0.17.0":"2024-04-28T20:04:11.202Z","0.17.1":"2024-04-29T14:58:00.667Z","0.17.2":"2024-04-29T16:33:42.088Z","0.17.4":"2024-04-30T14:37:32.957Z","0.17.5":"2024-04-30T19:45:11.451Z","0.18.0":"2024-05-01T14:19:18.158Z","0.18.1":"2024-05-02T15:43:03.228Z","0.19.0":"2024-05-04T20:05:10.887Z","0.20.0":"2024-05-06T13:37:00.870Z","0.21.0":"2024-05-15T20:52:50.770Z"},"bugs":{"url":"https://github.com/sassoftware/restaf-demos/issues"},"author":{"name":"Deva Kumar","email":"deva.kumar@sas.com"},"license":"Apache-2.0","homepage":"https://github.com/sassoftware/restaf-demos/tree/viya-assistantjs#readme","keywords":["gpt","gpt functions","openai assistant","azureai assistant","SAS REST API","restaf","restaflib","restafedit","SAS","SAS Viya","AI Assistant"],"repository":{"url":"git+https://github.com/sassoftware/restaf-demos.git#viya-assistantjs","type":"git"},"description":"A starter library to build chats for SAS Viya uing OpenAI or AzureAI  Assistant API","maintainers":[{"email":"joe.furbee@sas.com","name":"jefurbee"},{"email":"deva.kumar@sas.com","name":"devakumaraswamy"},{"email":"ckedwards24@gmail.com","name":"ckedwards"},{"email":"robert.levey@sas.com","name":"rbtlevey"},{"email":"bradley.morris@sas.com","name":"brmorr"},{"email":"ben.tomlinson@sas.com","name":"bjtomlin"},{"email":"Josh.Lyna@sas.com","name":"jolyna"},{"email":"stephen.mckenna@sas.com","name":"mtlsmc"},{"email":"stephen.gemmell@sas.com","name":"mtlstg"},{"email":"ryan.auld@sas.com","name":"ryanauldsas"},{"email":"kenj55@gmail.com","name":"kenjackson"},{"email":"harry.moore@sas.com","name":"mtlhmo"},{"email":"martin.coutts@sas.com","name":"martin-coutts-sas"},{"email":"robert.macfarlane@sas.com","name":"romacf"},{"email":"timothy.crider@sas.com","name":"timothy.crider-sas"},{"email":"Daniel.Arthur@sas.com","name":"daarth"},{"email":"ewsken_sas@outlook.com","name":"ewsken_sas"},{"email":"Bryan.Behrenshausen@sas.com","name":"semioticrobotic"},{"email":"barry.peddycord@sas.com","name":"barry-sas"},{"email":"nurb.lampert@sas.com","name":"nurb.lampert"},{"email":"craig.mckay@sas.com","name":"mtlcmc"},{"email":"naji.shehab@sas.com","name":"mtlnsh"},{"email":"tom.mceachan@sas.com","name":"tom-mceachan_sasinst"}],"readme":"","readmeFilename":""}