Gathering detailed insights and metrics for @ibm-cloud/watsonx-ai
Gathering detailed insights and metrics for @ibm-cloud/watsonx-ai
Gathering detailed insights and metrics for @ibm-cloud/watsonx-ai
Gathering detailed insights and metrics for @ibm-cloud/watsonx-ai
npm install @ibm-cloud/watsonx-ai
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
3 Stars
18 Commits
1 Forks
1 Watching
2 Branches
18 Contributors
Updated on 27 Nov 2024
TypeScript (53.73%)
JavaScript (44.6%)
Shell (1.67%)
Cumulative downloads
Total Downloads
Last day
41.4%
17,992
Compared to previous day
Last week
13.3%
88,822
Compared to previous week
Last month
546.2%
331,171
Compared to previous month
Last year
0%
383,583
Compared to previous year
3
20
Node.js client library to interact with IBM watsonx.ai service.
The IBM watsonx.ai Node.js SDK allows developers to programmatically interact with the IBM watsonx.ai service.
1npm install @ibm-cloud/watsonx-ai
For general SDK usage information, please see this link
IBM watsonx.ai Node.js SDK documentation can be found here
This library requires configuration with a service URL and platform credentials to authenticate to your account.
There are several ways to set these authentication properties.
You can set the following environment variables for chosen authentication type.
1WATSONX_AI_AUTH_TYPE=iam 2WATSONX_AI_APIKEY=<YOUR-APIKEY>
1WATSONX_AI_AUTH_TYPE=bearertoken 2WATSONX_AI_BEARER_TOKEN=<YOUR-BEARER-TOKEN>
1WATSONX_AI_AUTH_TYPE=cp4d 2WATSONX_AI_USERNAME=<YOUR_USERNAME> 3WATSONX_AI_PASSWORD=<YOUR_PASSWORD> 4WATSONX_AI_URL=url
If any troubles regarding SSL verification appear, such as "Error: self-signed certificate in certificate chain", please try setting up enviromental virables as below:
1WATSONX_AI_DISABLE_SSL=true 2WATSONX_AI_AUTH_DISABLE_SSL=true
To use an external configuration file, please see the general SDK usage information for guidance. Additionally, please see the following template files for:
To learn more about how to use programmatic authentication, see the Node.js SDK Core document about authentication.
The following code examples authenticate with the environment variables. Please set environment variables before proceeding with examples:
1const { WatsonXAI } = require('@ibm-cloud/watsonx-ai'); 2 3// Service instance 4const watsonxAIService = WatsonXAI.newInstance({ 5 version: '2024-05-31', 6 serviceUrl: 'https://us-south.ml.cloud.ibm.com', 7}); 8 9const textGenRequestParametersModel = { 10 max_new_tokens: 100, 11}; 12 13const params = { 14 input: 'Generate a short greeting for project kick-off meeting.', 15 modelId: 'ibm/granite-13b-chat-v2', 16 projectId: '<YOUR_PROJECT_ID>', 17 parameters: textGenRequestParametersModel, 18}; 19 20try { 21 const textGeneration = watsonxAIService 22 .generateText(params) 23 .then((res) => { 24 console.log("\n\n***** TEXT RESPONSE FROM MODEL *****"); 25 console.log(res.result.results[0].generated_text); 26 }) 27} catch (err) { 28 console.warn(err); 29}
When you run this code, you should see result similar to the following output:
1***** TEXT RESPONSE FROM MODEL ***** 2Welcome to the project kick-off meeting. I'm glad you could make it.
For more examples, please refer to the following directory, which contains self-contained examples of several flows, where you could use this SDK in.
If you are having difficulties using this SDK or have a question about the IBM Cloud services, please ask a question at Stack Overflow.
If you encounter an issue with the SDK, you are welcome to submit a bug report. Before that, please search for similar issues. It's possible someone has already encountered this issue.
Find more open source projects on the IBM Github Page
See CONTRIBUTING.
This project is released under the Apache 2.0 license. The license's full text can be found in LICENSE.
No vulnerabilities found.
No security vulnerabilities found.