{"id":13667575,"url":"https://github.com/cssxsh/mirai-openai-plugin","last_synced_at":"2025-08-18T12:16:34.938Z","repository":{"id":65002050,"uuid":"574774730","full_name":"cssxsh/mirai-openai-plugin","owner":"cssxsh","description":"Mirai Console OpenAI ChatBot 插件","archived":false,"fork":false,"pushed_at":"2023-12-20T06:14:25.000Z","size":1295,"stargazers_count":130,"open_issues_count":3,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T09:05:59.255Z","etag":null,"topics":["chatbot","chatgpt","mirai","mirai-console","mirai-plugin","openai"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cssxsh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-06T03:26:08.000Z","updated_at":"2025-01-08T07:49:21.000Z","dependencies_parsed_at":"2023-11-20T08:28:23.051Z","dependency_job_id":"b251620a-e1cb-4785-94de-daf6053b2141","html_url":"https://github.com/cssxsh/mirai-openai-plugin","commit_stats":{"total_commits":112,"total_committers":2,"mean_commits":56.0,"dds":0.008928571428571397,"last_synced_commit":"800943dc58e5b11a83d6f3d73381c7fbcc3d025b"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssxsh%2Fmirai-openai-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssxsh%2Fmirai-openai-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssxsh%2Fmirai-openai-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssxsh%2Fmirai-openai-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cssxsh","download_url":"https://codeload.github.com/cssxsh/mirai-openai-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248759132,"owners_count":21157094,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbot","chatgpt","mirai","mirai-console","mirai-plugin","openai"],"created_at":"2024-08-02T07:00:40.978Z","updated_at":"2025-04-13T18:21:56.867Z","avatar_url":"https://github.com/cssxsh.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# [Mirai OpenAI Plugin](https://github.com/cssxsh/mirai-openai-plugin)\n\n\u003e Mirai Console 下的 OpenAI Chat Bot 插件\n\n[![maven-central](https://img.shields.io/maven-central/v/xyz.cssxsh.mirai/mirai-openai-plugin)](https://search.maven.org/artifact/xyz.cssxsh.mirai/mirai-openai-plugin)\n[![test](https://github.com/cssxsh/mirai-openai-plugin/actions/workflows/test.yml/badge.svg)](https://github.com/cssxsh/mirai-openai-plugin/actions/workflows/test.yml)\n[![MiraiForum](https://img.shields.io/badge/post-on%20MiraiForum-yellow)](https://mirai.mamoe.net/topic/1849)\n\nBe based on \u003chttps://chat.openai.com/\u003e  \nOpenAI 目前对注册有一定要求，请先阅读 [注册](#注册), 然后创建 [Secret Key](https://platform.openai.com/account/api-keys)  \n注意，不是 `Cookie Token`, 是 `api-key`  \n~~另外，可以直连，不需要代理，只是注册账号的时候需要代理~~   \n`api.openai.com` 已列入黑名单，你需要配置代理  \n如果没有配置，本插件会尝试做一些特殊处理，~~一般情况下也能正常使用~~  \n`api.openai.com` IP地址变更，套了一层 `cloudflare`, 特殊处理失效, 表现为 `403`-`text/html` 响应 \n\n开启聊天默认使用 `chat` (chat_prefix) 触发, 基于 `/v1/chat/completions` 默认模型 `gpt-3.5-turbo`  \n开启问答默认使用 `Q\u0026A` (question_prefix) 触发, 基于 `/v1/completions` 默认模型 `text-davinci-003`  \n开启图片生成默认使用 `?` (image_prefix) 触发  \n停止聊天或问答默认使用 `stop` 触发  \n重载配置默认使用 `openai-reload` (reload_prefix) 触发，使用后将重新加载配置，无需重启 `Mirai Console`\n\n`/v1/chat/completions` 消耗 `tokens` 比 `/v1/completions` 小，但是聊天特化，请自行注意两者的区别  \n如果需要使用 `GPT4`，请参照 [Model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility) 替换模型\n\n默认情况下 `权限检查` 是关闭的, 需要在基本配置中配置开启 (开启后会在日志中给出权限ID)\n\n预置 `prompt` (也称语境或人格)  \n用法例子 `chat #猫娘`  \n自定义配置请阅读 [预置语境](#预置语境)  \n预设的加载优先级 开始指令时指定(`chat #xxx`) \u003e 用户绑定的预设 \u003e 群绑定的预设  \n\n**Since 1.1.0** 添加 `@` 触发聊天配置(手机端回复消息时会附带@, 请注意不要误触)  \n**Since 1.2.0** 将 `chat` 功能对接至 \u003chttps://platform.openai.com/docs/api-reference/chat\u003e, 节省 Usage  \n**Since 1.2.2** Fake SSLSocket  \n**Since 1.3.0** 添加经济系统对接 和 预置语境  \n**Since 1.3.1** 添加一些可能会带来BUG的配置 `立刻开始聊天`, `保持前缀检查`  \n**Since 1.4.0** 修改经济检查逻辑，仅在聊天开始前检查是否余额  \n**Since 1.4.1** 添加绑定预设的引用 `~`  \n**Since 1.5.0** 添加控制 `cname` 功能的配置，用法：在 `Java` 启动参数中添加 `-Dxyz.cssxsh.openai.cname=false`\n\n## 效果\n\n聊天  \n![chat](example/screenshot/chat.jpg)\n问答  \n![completion](example/screenshot/completion.jpg)\n图片  \n![image](example/screenshot/image.jpg)\n预置语境  \n![bind](example/screenshot/bind.png)\n\n## 配置\n\n`openai.yml` 基本配置\n\n*   `proxy` 代理 协议支持 `socks` 和 `http`, 例如 `socks://127.0.0.1:7890`\n*   `completion_prefix` 自定义模型触发前缀, 用来测试模型及消耗, 默认 `\u003e `\n*   `image_prefix` 图片生成触发前缀, 默认 `? `\n*   `chat_prefix` 聊天模型触发前缀, 默认 `chat`\n*   `question_prefix` 问答模型触发前缀, 默认 `Q\u0026A`\n*   `reload_prefix` 重载配置触发前缀, 默认 `openai-reload`\n*   `economy_set_prefix` 经济设置触发前缀, 默认 `tokens`\n*   `bind_set_prefix` 绑定设置触发前缀, 默认 `bind`\n*   `stop` 停止聊天或问答, 默认 `stop`\n*   `token` [Secret Key](https://platform.openai.com/account/api-keys), 插件第一次启动时会要求输入，不用再次编辑文件\n*   `error_reply` 发生错误时回复用户，默认 `true`\n*   `end_reply` 停止聊天时回复用户，默认 `false`\n*   `chat_limit` 聊天服务个数限制\n*   `chat_by_at` 聊天模型触发于`@`，默认 `false`\n*   `has_permission` 权限检查, 为 `true` 时开启\n*   `at_once` 立刻开始聊天/问答(即不会发送 `聊天/问答将开始`, 而是直接接着指令开始聊天) 默认 `false`\n*   `keep_prefix_check` 保持前缀检查(即一定要附带前缀/`@`才会触发对话)，默认 `false`\n*   `has_economy` 经济系统, 为 `true` 时开启 @see \u003chttps://github.com/cssxsh/mirai-economy-core\u003e\n\n`completion.yml` 自定义模型详细配置\n\n*   `model` 模型\n*   `max_tokens` 回答长度\n*   `temperature` 逆天程度，取值 `0.0~2.0`\n\n`image.yml` 图片生成模型详细配置\n\n*   `number` 图片张数\n*   `size` 可选的范围是固定的，请不要更改\n*   `format` 下载方式，请不要更改\n\n`chat.yml` 聊天模型详细配置\n\n*   `gpt_model` 模型\n*   `timeout` 等待停止时间\n*   `max_tokens` 回答长度\n*   `temperature` 逆天程度，取值 `0.0~2.0`\n\n`question.yml` 问答模型详细配置\n\n*   `model` 模型\n*   `timeout` 等待停止时间\n*   `max_tokens` 回答长度\n*   `temperature` 逆天程度，取值 `0.0~2.0`\n\n`economy.yml` 经济相关\n\n*   `sign_plus_assign` 签到增加的tokens数量，默认 `1024`\n\n### 注册\n\n\u003chttps://juejin.cn/post/7175153557941780541\u003e\n\n### 测试\n\n在线测试  \n\u003chttps://platform.openai.com/playground\u003e\n\n官方例子  \n\u003chttps://platform.openai.com/examples\u003e\n\n## 对接经济系统\n\n@see \u003chttps://github.com/cssxsh/mirai-economy-core\u003e\n\n`openai.com` 通过 `tokens`, 分词数量（一般来说句子越长，分词越长）来计算费用。  \n为了防止某些用户过度消耗 `tokens`, 导致额度耗尽。  \n对接后，经济系统将为每个用户计算 `tokens` 额度，个人的可用 `tokens` 为 `0` 时，聊天功能将拒绝响应并提示。\n\n`管理员(未开启权限检查)` 或者 `持有经济权限的用户(已开启权限检查)` 可用为用户设置 `tokens` 额度\n\n用法为 `tokens 114514 @12345` 为用户 `12345` 分配 `114514` 个 `tokens`  \n或者 `tokens 12345` 为全部群成员分配 `114514` 个 `tokens`\n\n## 预置语境\n\n有些人也将其形容为 `人格`, 实际上这个功能是告诉机器人你需要扮演什么角色或者提供什么功能  \n\n配置方法, 在插件数据目录 `data/xyz.cssxsh.mirai.plugin.mirai-openai-plugin/prompts` 下新建 `XXX.txt`  \n然后填入你需要预置的内容  \n**Since 1.5** 将会从 \u003chttps://chathub.gg/api/community-prompts\u003e 加载第三方语境, 同时以 `#\u003c充当 Linux 终端\u003e` 的格式兼容空格\n\n使用方法，在 `chat` 后面附加 `#XXX`, 例如 `chat #猫娘`  \n或者使用 `bind` 为当前用户绑定一个默认 `prompt`, 例如 `bind 猫娘`  \n当消息为群消息，且当前用户为管理员/群主时绑定的对象将是 `群` ，即为 `群` 设置预设\n\n由于 `chat` 会在有附加的内容时(附加的内容会被当作预设处理)，不启用绑定预设  \n所以添加一个新功能, 使用 `~` 或者 `.` 来引用绑定预设, 例如 `chat ~ ...`\n\n## 安装\n\n### MCL 指令安装\n\n**请确认 mcl.jar 的版本是 2.1.0+**  \n`./mcl --update-package xyz.cssxsh.mirai:mirai-openai-plugin --channel maven-stable --type plugins`\n\n### 手动安装\n\n1.  从 [Releases](https://github.com/cssxsh/mirai-openai-plugin/releases) 或者 [Maven](https://repo1.maven.org/maven2/xyz/cssxsh/mirai/mirai-openai-plugin/) 下载 `mirai2.jar`\n2.  将其放入 `plugins` 文件夹中\n\n## [爱发电](https://afdian.net/@cssxsh)\n\n![afdian](.github/afdian.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcssxsh%2Fmirai-openai-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcssxsh%2Fmirai-openai-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcssxsh%2Fmirai-openai-plugin/lists"}