使用 node.js 快速访问最新的深度学习模型

267 阅读1分钟

借助开源 IntelliNode,开发人员可以毫不费力地将 AI 模型集成到他们的应用程序中。该库支持范围广泛的模型,包括 Google、OpenAI、Coherent 和 Stable Diffusion 提供的模型,使您可以更轻松地根据您的特定要求在模型之间进行切换。

一次安装即可使用npm访问所有模型:
npm i intellinode

调用DALL·E生成图片示例:

const { RemoteImageModel, ImageModelInput } = require('intellinode');

provider='openai';

const imgModel = new RemoteImageModel(apiKey, provider);
const images = await imgModel.generateImages(new ImageModelInput({
    prompt: 'A cartoon-style Shiba Inu dog with a playful expression',
    numberOfImages: 1
}));

要生成具有稳定扩散的图像,这是一个微小的变化:
provider='stability'
provider=SupportedImageModels.STABILITY;

输出:

image.png

这同样适用于音频和文本生成;您可以访问所有模型,在它们之间切换并将您的业务应用程序与各种 AI 模型更改分离开来。

调用 ChatGPT 的示例
const { Chatbot, ChatGPTInput } = require('intellinode');

// set the system model and the user message.
const input = new ChatGPTInput('You are a helpful assistant.');
input.addUserMessage('What is the distance between the Earth and the Moon?');

const responses = await chatbot.chat(input);

调用谷歌语音合成的示例
const { RemoteSpeechModel, Text2SpeechInput } = require('intellinode');

const speechModel = new RemoteSpeechModel(apiKey);
  const input = new Text2SpeechInput({ text: text, language: language });
  const audioContent = await speechModel.generateSpeech(input);

更多示例的 Github 页面:链接