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

koishi-plugin-openai-compatible

v1.1.3

Published

这是一个适用于Koishi的OpenAI兼容聊天插件,支持与所有兼容OpenAI API的大模型进行聊天交互。

Downloads

795

Readme

koishi-plugin-openai-compatible

一个支持所有兼容 OpenAI API 的 Koishi 插件,提供完整的 AI 对话功能,包括黑名单、请求冷却、自定义指令和情绪分析等高级功能。

功能特性

  • ✅ 支持所有兼容 OpenAI 的 API(OpenAI、Azure OpenAI、各类国产大模型等)
  • ✅ 可配置 API 端点、模型和参数
  • ✅ 可设置自定义系统提示词
  • ✅ 支持黑名单功能,阻止特定用户使用
  • ✅ 支持请求冷却配置,防止滥用
  • ✅ 支持自定义指令名
  • ✅ 支持控制是否开启提示(关闭后所有错误提示都不会输出)
  • ✅ 支持情绪分析功能(可选)
    • 分析 AI 输出内容的情绪
    • 自动添加对应的情绪表情包
    • 支持自定义情绪与表情包的映射

安装

# 使用 npm
npm install koishi-plugin-openai-compatible

# 或使用 yarn
yarn add koishi-plugin-openai-compatible

# 或使用 pnpm
pnpm add koishi-plugin-openai-compatible

配置

在 Koishi 配置文件中启用插件并配置:

plugins:
  openai-compatible:
    # API 配置
    endpoint: 'https://api.openai.com/v1/chat/completions'
    apiKey: 'your-api-key-here'
    model: 'gpt-3.5-turbo'

    # 情绪分析配置
    enableEmotion: false  # 是否启用情绪分析
    emotionEndpoint: 'https://api.openai.com/v1/chat/completions'
    emotionApiKey: 'your-emotion-api-key'
    emotionModel: 'gpt-3.5-turbo'  # 推荐使用较快的模型
    emotionImages:
      '快乐': 'https://example.com/happy.gif'
      '伤心': 'https://example.com/sad.gif'
      '生气': 'https://example.com/angry.gif'

    # 提示词配置
    systemPrompt: '你是一个友好的 AI 助手。'
    emotionSystemPrompt: '分析文本的情绪,只返回情绪名称。'

    # 参数配置
    temperature: 0.7
    maxTokens: 2000
    topP: 1
    frequencyPenalty: 0
    presencePenalty: 0

    # 黑名单和冷却
    blacklist: []
    cooldown: 10000  # 10 秒

    # 命令名和提示
    commandName: 'ai'
    enableMessage: true  # 是否开启提示(关闭后所有错误提示都不会输出)

情绪分析配置

启用情绪分析功能时,需要注意:

  1. 推荐使用较快的模型:情绪分析需要额外一次 API 调用,建议使用响应速度快的模型(如 gpt-3.5-turbo
  2. 配置情绪映射:在 emotionImages 中配置情绪名称与表情包图片链接的映射
  3. 系统提示词:插件内置了严格的系统提示词,确保情绪分析模型只返回情绪名称

情绪类型

支持的情绪类型:

  • 快乐、开心、高兴
  • 伤心、难过、悲伤
  • 生气、愤怒
  • 惊讶
  • 疑惑
  • 害怕、恐惧
  • 平静、中立

使用方法

基本对话

.ai 你好
.ai 解释什么是量子力学
.ai 写一首关于春天的诗

管理命令

需要管理员权限:

# 黑名单管理
.ai.admin.add <userId>        # 添加用户到黑名单
.ai.admin.remove <userId>     # 从黑名单移除用户
.ai.admin.list                # 查看黑名单

# 冷却管理
.ai.admin.clearcooldown <userId>  # 清除用户冷却时间

# 状态查看
.ai.admin.status              # 查看插件状态

API 兼容性

本插件支持所有兼容 OpenAI API 格式的服务:

  • OpenAI 官方 API
  • Azure OpenAI
  • 通义千问(通过兼容 API)
  • 智谱 AI(通过兼容 API)
  • 百度文心一言(通过兼容 API)
  • 其他兼容 OpenAI API 格式的服务

使用自定义 API 示例

plugins:
  openai-compatible:
    endpoint: 'https://your-custom-api.com/v1/chat/completions'
    apiKey: 'your-api-key'
    model: 'your-model-name'

注意事项

  1. API Key 安全:请妥善保管您的 API Key,不要泄露给他人
  2. 成本控制:建议设置合理的冷却时间和令牌限制,避免产生高额费用
  3. 情绪分析成本:启用情绪分析会使每次请求的成本增加约一倍
  4. 黑名单管理:定期检查黑名单,及时移除已解除限制的用户
  5. 提示控制:关闭提示功能后,用户将不会收到任何错误提示(包括黑名单、冷却、输入为空、请求失败等),适用于需要静默处理的场景

开发

# 安装依赖
npm install

# 构建项目
npm run build

许可证

MIT License