npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ibm-cloud/watsonx-ai

v1.3.0

Published

IBM watsonx.ai Node.js SDK

Downloads

446,366

Readme

Build Status npm-version semantic-release

IBM watsonx.ai Node.js SDK

Node.js client library to interact with IBM watsonx.ai service.

Table of Contents

Overview

The IBM watsonx.ai Node.js SDK allows developers to programmatically interact with the IBM watsonx.ai service.

Prerequisites

  • You need an IBM Cloud (SaaS offering) or have access to IBM Cloud Pak® for Data (on-prem offering).
  • You need to have an access to watsonx.ai service in either of above environments.
  • Node.js >=14: This SDK is tested with Node.js versions 14 and up. It may work on previous versions but this is not officially supported.

Installation

npm install @ibm-cloud/watsonx-ai

Using the SDK

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.

With environment variables

You can set the following environment variables for chosen authentication type.

IAM authentication

WATSONX_AI_AUTH_TYPE=iam
WATSONX_AI_APIKEY=<YOUR-APIKEY>

Bearer token authentication

WATSONX_AI_AUTH_TYPE=bearertoken
WATSONX_AI_BEARER_TOKEN=<YOUR-BEARER-TOKEN>

CP4D authentication

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

With an external credentials file

To use an external configuration file, please see the general SDK usage information for guidance. Additionally, please see the following template files for:

With programmatic approach

To learn more about how to use programmatic authentication, see the Node.js SDK Core document about authentication.

Code examples

Basic example - text generation/inference

The following code examples authenticate with the environment variables. Please set environment variables before proceeding with examples:

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.

More examples

For more examples, please refer to the following directory, which contains self-contained examples of several flows, where you could use this SDK in.

Questions

If you are having difficulties using this SDK or have a question about the IBM Cloud services, please ask a question at Stack Overflow.

Issues

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.

Open source @ IBM

Find more open source projects on the IBM Github Page

Contributing

See CONTRIBUTING.

License

This project is released under the Apache 2.0 license. The license's full text can be found in LICENSE.