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

kimichat.js

v0.1.7

Published

A Kimi Chat nodejs sdk, unofficial version

Downloads

97

Readme

kimichat.js

CI

English Version

kimichat.js 是一个非官方的 Kimi Chat SDK,使用 TypeScript 和 undici 库开发

本项目旨在提供一个简单、高效的方式来接入和使用 Kimi Chat 的官方 API

Features

  • 覆盖官方 API:实现了官方文档中定义的 99% API
  • TypeScript 支持:利用 TypeScript 开发,为开发者提供静态类型检查和智能提示,提高开发效率和项目的可维护性
  • 基于 undici

安装

# 使用 npm 安装:
npm install kimichat.js

# 使用 yarn 安装:
yarn add kimichat.js

# 使用 pnpm 安装
pnpm i kimichat.js

使用方法

请注意, 流式调用需要调用方传入自定义的回调方法, 用于处理数据流

import { KimiChat } from "kimichat.js";
import { PassThrough } from "stream";

const kimi = new KimiChat("Your API Key");

// Chat Completion
const { data: messages } = await kimi.chatCompletions({
  messages: [
    {
      role: "user",
      content: "Hello, how are you?",
    },
  ],
});

// Stream Chat Completion example
kimi.streamChatCompletions({
  messages: [
    {
      role: "user",
      content: "hello",
    },
  ],
  callback: () => {
    const bufs = [] as Buffer[];
    const pt = new PassThrough()
      .on("error", (err: any) => {
        // Handling error
      })
      .on("data", (buf: Buffer) => {
        // Handling buf data
        bufs.push(buf);
      })
      .on("end", () => {
        // Handle buf data on end
        Buffer.concat(bufs).toString("utf8");
      });

    return pt;
  },
});

对于 stream 格式返回数据格式如下, 类型引用 StreamChatCompletionData

data: {"id":"cmpl-1305b94c570f447fbde3180560736287","object":"chat.completion.chunk","created":1698999575,"model":"moonshot-v1-8k","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"cmpl-1305b94c570f447fbde3180560736287","object":"chat.completion.chunk","created":1698999575,"model":"moonshot-v1-8k","choices":[{"index":0,"delta":{"content":"你好"},"finish_reason":null}]}

...

data: {"id":"cmpl-1305b94c570f447fbde3180560736287","object":"chat.completion.chunk","created":1698999575,"model":"moonshot-v1-8k","choices":[{"index":0,"delta":{"content":"。"},"finish_reason":null}]}

data: {"id":"cmpl-1305b94c570f447fbde3180560736287","object":"chat.completion.chunk","created":1698999575,"model":"moonshot-v1-8k","choices":[{"index":0,"delta":{},"finish_reason":"stop","usage":{"prompt_tokens":19,"completion_tokens":13,"total_tokens":32}}]}

data: [DONE]

更多方法请参考 examples

引用

Kimi Chat 官方 API 文档

undici - An HTTP/1.1 client, written from scratch for Node.js

免责声明

本项目为非官方版本,并非 Kimi Chat 官方出品。 使用本 SDK 时,请遵守 Kimi Chat 的相关政策和使用条款。开发者在使用过程中产生的任何问题和后果,本项目概不负责。


欢迎贡献代码,一起完善 kimichat.js!