
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
@ibm-cloud/watsonx-ai
Advanced tools
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.
npm 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.
WATSONX_AI_AUTH_TYPE=iam
WATSONX_AI_APIKEY=<YOUR-APIKEY>
WATSONX_AI_AUTH_TYPE=bearertoken
WATSONX_AI_BEARER_TOKEN=<YOUR-BEARER-TOKEN>
WATSONX_AI_AUTH_TYPE=cp4d
WATSONX_AI_USERNAME=<YOUR_USERNAME>
WATSONX_AI_PASSWORD=<YOUR_PASSWORD>
WATSONX_AI_URL=url
If any troubles regarding SSL verification appear, such as "Error: self-signed certificate in certificate chain", please try setting up environment variables as below:
WATSONX_AI_DISABLE_SSL=true
WATSONX_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:
It is mandatory to set projectId
or spaceId
unless you are working with lightweight engine.
const { WatsonXAI } = require('@ibm-cloud/watsonx-ai');
// Service instance
const watsonxAIService = WatsonXAI.newInstance({
version: '2024-05-31',
serviceUrl: 'https://us-south.ml.cloud.ibm.com',
});
const textGenRequestParametersModel = {
max_new_tokens: 100,
};
const params = {
input: 'Generate a short greeting for project kick-off meeting.',
modelId: 'ibm/granite-13b-chat-v2',
projectId: '<YOUR_PROJECT_ID>',
parameters: textGenRequestParametersModel,
};
try {
const textGeneration = watsonxAIService
.generateText(params)
.then((res) => {
console.log("\n\n***** TEXT RESPONSE FROM MODEL *****");
console.log(res.result.results[0].generated_text);
})
} catch (err) {
console.warn(err);
}
When you run this code, you should see result similar to the following output:
***** TEXT RESPONSE FROM MODEL *****
Welcome to the project kick-off meeting. I'm glad you could make it.
For a watsonx.ai lightweight engine, you do not need to provide a projectId
or spaceId
. Remember to set environment variables (IBM watsonx.ai software authentication
) before proceeding.
const { WatsonXAI } = require('@ibm-cloud/watsonx-ai');
// Service instance
const watsonxAIService = WatsonXAI.newInstance({
version: '2024-05-31',
serviceUrl: process.env.SERVICE_URL,
});
const params = {
input: 'Generate a short greeting for project kick-off meeting.',
modelId: 'mistralai/ministral-8b-instruct',
};
try {
const textGeneration = watsonxAIService
.generateText(params)
.then((res) => {
console.log("\n\n***** TEXT RESPONSE FROM MODEL *****");
console.log(res.result.results[0].generated_text);
})
} catch (err) {
console.warn(err);
}
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.
FAQs
IBM watsonx.ai Node.js SDK
We found that @ibm-cloud/watsonx-ai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 17 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.