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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vimo-ai/ai-platform-sdk

v0.0.1-beta.1

Published

SDK for AI Platform Server - 统一 AI 调用层,支持多渠道、流式传输、工具调用

Readme

AI Platform Chat SDK

这是一个专用于与 AI Platform Server 的聊天功能进行交互的轻量级 Node.js SDK。它全面使用 fetch API,并为流式响应提供了一流的支持。

安装

如果您在同一个 monorepo 中使用此 SDK,您可以使用本地路径依赖。在您另一个项目的 package.json 中添加:

"dependencies": {
  "ai-platform-sdk": "file:../sdk"
}

然后运行 npm installpnpm install

在此之后,您需要先编译 SDK:

cd sdk
pnpm build

在 NestJS 中使用

为了在 NestJS 应用中实现依赖注入和单例模式,我们提供了 AIPlatformSdkModule

1. 导入模块

在您项目的根模块(例如 app.module.ts)中导入 AIPlatformSdkModule

// in your-app/src/app.module.ts
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AIPlatformSdkModule } from 'ai-platform-sdk';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    AIPlatformSdkModule.forRootAsync(),
  ],
})
export class AppModule {}

2. 配置环境变量

在您项目的 .env 文件中添加以下变量:

AI_PLATFORM_BASE_URL=http://localhost:3000
AI_PLATFORM_API_KEY=your_secret_api_key

3. 在服务中注入客户端

// in your-app/src/some.service.ts
import { Inject, Injectable } from '@nestjs/common';
import { AIPlatformClient, AI_PLATFORM_CLIENT } from 'ai-platform-sdk';

@Injectable()
export class SomeService {
  constructor(
    @Inject(AI_PLATFORM_CLIENT) private readonly aiPlatformClient: AIPlatformClient,
  ) {}

  // 示例:调用流式API
  async streamExample() {
    const stream = this.aiPlatformClient.chat.streamChat({ input: '给我讲个关于程序员的笑话' });
    
    console.log('AI 回复:');
    for await (const chunk of stream) {
      process.stdout.write(chunk);
    }
    console.log(); // for a newline
  }

  // 示例:调用非流式API
  async nonStreamExample() {
    const reply = await this.aiPlatformClient.chat.chat({ input: '你好!' });
    console.log('AI 回复:', reply);
  }
}

API 参考

所有方法都位于 client.chat 命名空间下。

client.chat.chat(params)

进行一次性的、非流式的聊天调用。

  • 参数: { input: string; channel?: PROVIDER_CHANNEL; model?: string; }
  • 返回: Promise<string> - AI 的完整回复。

client.chat.streamChat(params)

进行基于 GET 请求的流式聊天。

  • 参数: { input: string; channel?: PROVIDER_CHANNEL; model?: string; }
  • 返回: AsyncIterable<string> - 一个可以 for...await...of 循环的异步迭代器,每次迭代返回一个数据块(字符串)。

client.chat.streamChatWithToolsAndMessages(body)

进行基于 POST 请求的、支持完整消息历史和工具的流式聊天。

  • 参数: { messages: ChatCompletionMessageParam[], tools: ChatCompletionTool[], ... }

  • 返回: AsyncIterable<string> - 同上。