包详细信息

watsonx-ai-provider

ibm378MIT1.0.4

watsonx.ai provider for Vercel AI SDK

ai, ai sdk, ibm, vercel

自述文件

watsonx-ai-provider

watsonx-ai-provider provides watsonx.ai language model support for Vercel’s AI SDK.

To use this in your code:

npm i watsonx-ai-provider
import { generateText } from "ai";
import { createWatsonxProvider } from "watsonx-ai-provider";

const watsonx = createWatsonxProvider({ projectId: process.env.WATSONX_AI_PROJECT_ID });

const result = await generateText({
  model: watsonx("ibm/granite-3-8b-instruct"),
  messages: [{ role: "user", content: "Tell me a joke about IBM." }],
});

console.log(result.text);

The above example relies on the following environment variables being set:

WATSONX_AI_AUTH_TYPE=iam
WATSONX_AI_APIKEY=YOUR_API_KEY_HERE
WATSONX_AI_PROJECT_ID=YOUR_PROJECT_ID_HERE

You can also programatically authenticate, such as with:

import { IamAuthenticator } from "ibm-cloud-sdk-core";

const watsonx = createWatsonxProvider({
  authenticator: new IamAuthenticator({
    apikey: "YOUR_KEY",
  })
  projectId: process.env.WATSONX_AI_PROJECT_ID,
});

See the custom providers section of the AI SDK documentation for details.