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

ms-openai-libray

v4.86.8

Published

The official TypeScript library for the OpenAI API

Readme


OpenAI TypeScript 和 JavaScript API 库

NPM version npm bundle size

该库提供方便的方式来访问 OpenAI REST API,支持 TypeScript 和 JavaScript。

安装

npm install ms-openai-libray

使用方式

这个库提供了与 OpenAI API 的完整对接,支持聊天完成、流式响应等功能。以下是一个使用示例,演示了如何集成自定义参数 mergeUrl

import OpenAI from 'ms-openai-libray';

const client = new OpenAI({
  apiKey: process.env['OPENAI_API_KEY'], // 你可以直接传入 API key,或者使用环境变量
});

async function main() {
  const chatCompletion = await client.chat.completions.create({
    messages: [{ role: 'user', content: 'Say this is a test' }],
    model: 'gpt-4', // 使用指定模型
    stream: true,  // 启用流式响应
  }, {
    mergeUrl: false, // 新增的参数,控制是否合并 URL。默认情况下,`mergeUrl` 为 `false`,您可以自定义是否合并 URL,默认就会新增 /chat/completions ,当false会移除
  });

  // 输出聊天完成的结果
  console.log(chatCompletion);
}

main();

关键特性

  • mergeUrl:这是一个新增的选项,用于控制是否合并 URL。默认情况下 mergeUrl 参数会自动开启。
    • mergeUrlfalse 时,用户可以自定义是否使用特定的 GPT 模型,同时支持各种 URL 配置。

待实现功能

  • 流式响应的增强:当前流式响应仅支持简单的输出,将来会增强支持更多流式输出场景,尤其是在多轮对话中保持状态。
  • 更灵活的错误处理机制:目前库的错误处理比较基础,未来将实现更加细化的错误码和自定义错误消息。
  • 更多的 API 集成:将支持更多 OpenAI API 接口,包括但不限于图像生成、音频处理等功能。
  • 支持不同的自定义模型:扩展现有的 API 接口,允许用户自定义更多的模型和其配置。
  • 更复杂的配置管理:添加更为灵活的配置项,使用户能够更容易管理 API 密钥和配置。
  • 新增自定义 TS 类型定义:允许用户自定义接口,扩展库的类型定义,使其支持更复杂的需求和接口响应结构。

注意事项

  • mergeUrl 参数与自定义模型的兼容性:如果您使用自定义的 API 或模型配置,需要确保 mergeUrl 参数正确传递,以避免出现不必要的 URL 拼接问题。