<div align="center">
<a href="https://v2.nonebot.dev/store"><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/nbp_logo.png" width="180" height="180" alt="NoneBotPluginLogo"></a>
<br>
<p><img src="https://github.com/A-kirami/nonebot-plugin-template/blob/resources/NoneBotPlugin.svg" width="240" alt="NoneBotPluginText"></p>
</div>
<div align="center">
# nonebot_plugin_openAI_completions
_✨ NoneBot 调用openAI completions接口实现的对话插件 ✨_
<a href="https://github.com/Ikaros-521/nonebot_plugin_openAI_completions/stargazers">
<img alt="GitHub stars" src="https://img.shields.io/github/stars/Ikaros-521/nonebot_plugin_openAI_completions?color=%09%2300BFFF&style=flat-square">
</a>
<a href="https://github.com/Ikaros-521/nonebot_plugin_openAI_completions/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/Ikaros-521/nonebot_plugin_openAI_completions?color=Emerald%20green&style=flat-square">
</a>
<a href="https://github.com/Ikaros-521/nonebot_plugin_openAI_completions/network">
<img alt="GitHub forks" src="https://img.shields.io/github/forks/Ikaros-521/nonebot_plugin_openAI_completions?color=%2300BFFF&style=flat-square">
</a>
<a href="./LICENSE">
<img src="https://img.shields.io/github/license/Ikaros-521/nonebot_plugin_openAI_completions.svg" alt="license">
</a>
<a href="https://pypi.python.org/pypi/nonebot_plugin_openAI_completions">
<img src="https://img.shields.io/pypi/v/nonebot_plugin_openAI_completions.svg" alt="pypi">
</a>
<a href="https://www.python.org">
<img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="python">
</a>
</div>
适用于nonebot2 v11的调用openAI completions接口实现的对话插件,部分源码由chatGPT编写。
调用的相关API源自api.openai.com
## 🔧 开发环境
Nonebot2:2.0.0b5
python:3.8.13
操作系统:Windows10(Linux兼容性问题不大)
编辑器:pycharm
## 💿 安装
环境依赖`aiohttp`库
且需要注册openAI账号,获取secret key,配置env后才能正常使用!
### 1. nb-cli安装(推荐)
在你bot工程的文件夹下,运行cmd(运行路径要对啊),执行nb命令安装插件,插件配置会自动添加至配置文件
```
nb plugin install nonebot_plugin_openAI_completions
```
### 2. 本地安装
先安装下 `aiohttp`
```
pip install aiohttp
```
将项目clone到你的机器人插件下的对应插件目录内(一般为机器人文件夹下的`src/plugins`),然后把`nonebot_plugin_openAI_completions`文件夹里的内容拷贝至上一级目录即可。
clone命令参考(得先装`git`,懂的都懂):
```
git clone https://github.com/Ikaros-521/nonebot_plugin_openAI_completions.git
```
也可以直接下载压缩包到插件目录解压,然后同样提取`nonebot_plugin_openAI_completions`至上一级目录。
目录结构: ```你的bot/src/plugins/nonebot_plugin_openAI_completions/__init__.py```
### 3. pip安装
```
pip install nonebot_plugin_openAI_completions
```
打开 nonebot2 项目的 ```bot.py``` 文件, 在其中写入
```nonebot.load_plugin('nonebot_plugin_openAI_completions')```
当然,如果是默认nb-cli创建的nonebot2的话,在bot路径```pyproject.toml```的```[tool.nonebot]```的```plugins```中添加```nonebot_plugin_openAI_completions```即可
pyproject.toml配置例如:
```
[tool.nonebot]
plugin_dirs = ["src/plugins"]
plugins = ["nonebot_plugin_openAI_completions"]
```
### 更新版本
```
nb plugin update nonebot_plugin_openAI_completions
```
## 🔧 配置
### secret key获取方式
获取 openai 的 secret key 需要您先创建一个 openai 账号,然后在其网站上申请 API key。
具体流程如下:
1、访问 openai 网站(https://beta.openai.com/),点击右上角的“Sign up”按钮进行注册。
2、在注册页面填写相关信息并提交,完成账号创建。
3、登录 openai 网站,点击右上角的“Developer”菜单,进入开发者控制台。
4、在开发者控制台中点击“New API Key”按钮,创建一个新的 API key。
5、在弹出的窗口中输入您的 API key 名称,然后点击“Create”按钮。
6、在创建完成后,您可以在开发者控制台中看到您创建的 API key 的 secret key。
### env配置
```
# 在你的env文件中添加如下配置(我的是.env.prod)
openai_secret_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```
| 配置项 | 必填 | 默认值 | 说明 |
|:----------------:|:----:|:----:|:----------------------------:|
| `openai_secret_key` | 是 | `""` | 参考上文secret key获取方式 |
## 🎉 功能
调用openAI的API接口获取请求返回直接输出,简单粗暴。
## 👉 命令
### /cplt 或 /openai 或 /ai
命令结构:```/cplt [你想问的内容]```
例如:```/cplt 用python实现hello world``` 或 ```/openai 你叫什么名字``` 或 ```/ai 今天是什么日子```
bot返回内容:

## ⚙ 拓展
自己动手丰衣足食

## 📝 更新日志
<details>
<summary>展开/收起</summary>
### 0.0.1
- 插件初次发布
</details>
## 致谢
- [chat.openai.com](https://chat.openai.com)
Raw data
{
"_id": null,
"home_page": "https://github.com/Ikaros-521/nonebot_plugin_openAI_completions",
"name": "nonebot-plugin-openai-completions",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Ikaros",
"author_email": "327209194@qq.com",
"download_url": "https://files.pythonhosted.org/packages/d9/0c/ce06a8732f127d3ffdfc189333e791d745e24bef9b14c2ca39510bb1c036/nonebot_plugin_openai_completions-0.0.1.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n <a href=\"https://v2.nonebot.dev/store\"><img src=\"https://github.com/A-kirami/nonebot-plugin-template/blob/resources/nbp_logo.png\" width=\"180\" height=\"180\" alt=\"NoneBotPluginLogo\"></a>\n <br>\n <p><img src=\"https://github.com/A-kirami/nonebot-plugin-template/blob/resources/NoneBotPlugin.svg\" width=\"240\" alt=\"NoneBotPluginText\"></p>\n</div>\n\n<div align=\"center\">\n\n# nonebot_plugin_openAI_completions\n \n_\u2728 NoneBot \u8c03\u7528openAI completions\u63a5\u53e3\u5b9e\u73b0\u7684\u5bf9\u8bdd\u63d2\u4ef6 \u2728_\n \n<a href=\"https://github.com/Ikaros-521/nonebot_plugin_openAI_completions/stargazers\">\n <img alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/Ikaros-521/nonebot_plugin_openAI_completions?color=%09%2300BFFF&style=flat-square\">\n</a>\n<a href=\"https://github.com/Ikaros-521/nonebot_plugin_openAI_completions/issues\">\n <img alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues/Ikaros-521/nonebot_plugin_openAI_completions?color=Emerald%20green&style=flat-square\">\n</a>\n<a href=\"https://github.com/Ikaros-521/nonebot_plugin_openAI_completions/network\">\n <img alt=\"GitHub forks\" src=\"https://img.shields.io/github/forks/Ikaros-521/nonebot_plugin_openAI_completions?color=%2300BFFF&style=flat-square\">\n</a>\n<a href=\"./LICENSE\">\n <img src=\"https://img.shields.io/github/license/Ikaros-521/nonebot_plugin_openAI_completions.svg\" alt=\"license\">\n</a>\n<a href=\"https://pypi.python.org/pypi/nonebot_plugin_openAI_completions\">\n <img src=\"https://img.shields.io/pypi/v/nonebot_plugin_openAI_completions.svg\" alt=\"pypi\">\n</a>\n<a href=\"https://www.python.org\">\n <img src=\"https://img.shields.io/badge/python-3.8+-blue.svg\" alt=\"python\">\n</a>\n\n</div>\n\n\u9002\u7528\u4e8enonebot2 v11\u7684\u8c03\u7528openAI completions\u63a5\u53e3\u5b9e\u73b0\u7684\u5bf9\u8bdd\u63d2\u4ef6\uff0c\u90e8\u5206\u6e90\u7801\u7531chatGPT\u7f16\u5199\u3002 \n\u8c03\u7528\u7684\u76f8\u5173API\u6e90\u81eaapi.openai.com \n\n## \ud83d\udd27 \u5f00\u53d1\u73af\u5883\nNonebot2\uff1a2.0.0b5 \npython\uff1a3.8.13 \n\u64cd\u4f5c\u7cfb\u7edf\uff1aWindows10\uff08Linux\u517c\u5bb9\u6027\u95ee\u9898\u4e0d\u5927\uff09 \n\u7f16\u8f91\u5668\uff1apycharm \n\n## \ud83d\udcbf \u5b89\u88c5\n\u73af\u5883\u4f9d\u8d56`aiohttp`\u5e93 \n\u4e14\u9700\u8981\u6ce8\u518copenAI\u8d26\u53f7\uff0c\u83b7\u53d6secret key\uff0c\u914d\u7f6eenv\u540e\u624d\u80fd\u6b63\u5e38\u4f7f\u7528\uff01 \n\n### 1. nb-cli\u5b89\u88c5\uff08\u63a8\u8350\uff09\n\u5728\u4f60bot\u5de5\u7a0b\u7684\u6587\u4ef6\u5939\u4e0b\uff0c\u8fd0\u884ccmd\uff08\u8fd0\u884c\u8def\u5f84\u8981\u5bf9\u554a\uff09\uff0c\u6267\u884cnb\u547d\u4ee4\u5b89\u88c5\u63d2\u4ef6\uff0c\u63d2\u4ef6\u914d\u7f6e\u4f1a\u81ea\u52a8\u6dfb\u52a0\u81f3\u914d\u7f6e\u6587\u4ef6 \n```\nnb plugin install nonebot_plugin_openAI_completions\n```\n\n### 2. \u672c\u5730\u5b89\u88c5\n\u5148\u5b89\u88c5\u4e0b `aiohttp`\n```\npip install aiohttp\n```\n\u5c06\u9879\u76eeclone\u5230\u4f60\u7684\u673a\u5668\u4eba\u63d2\u4ef6\u4e0b\u7684\u5bf9\u5e94\u63d2\u4ef6\u76ee\u5f55\u5185\uff08\u4e00\u822c\u4e3a\u673a\u5668\u4eba\u6587\u4ef6\u5939\u4e0b\u7684`src/plugins`\uff09\uff0c\u7136\u540e\u628a`nonebot_plugin_openAI_completions`\u6587\u4ef6\u5939\u91cc\u7684\u5185\u5bb9\u62f7\u8d1d\u81f3\u4e0a\u4e00\u7ea7\u76ee\u5f55\u5373\u53ef\u3002 \nclone\u547d\u4ee4\u53c2\u8003\uff08\u5f97\u5148\u88c5`git`\uff0c\u61c2\u7684\u90fd\u61c2\uff09\uff1a\n```\ngit clone https://github.com/Ikaros-521/nonebot_plugin_openAI_completions.git\n``` \n\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4e0b\u8f7d\u538b\u7f29\u5305\u5230\u63d2\u4ef6\u76ee\u5f55\u89e3\u538b\uff0c\u7136\u540e\u540c\u6837\u63d0\u53d6`nonebot_plugin_openAI_completions`\u81f3\u4e0a\u4e00\u7ea7\u76ee\u5f55\u3002 \n\u76ee\u5f55\u7ed3\u6784\uff1a ```\u4f60\u7684bot/src/plugins/nonebot_plugin_openAI_completions/__init__.py``` \n\n\n### 3. pip\u5b89\u88c5\n```\npip install nonebot_plugin_openAI_completions\n``` \n\u6253\u5f00 nonebot2 \u9879\u76ee\u7684 ```bot.py``` \u6587\u4ef6, \u5728\u5176\u4e2d\u5199\u5165 \n```nonebot.load_plugin('nonebot_plugin_openAI_completions')``` \n\u5f53\u7136\uff0c\u5982\u679c\u662f\u9ed8\u8ba4nb-cli\u521b\u5efa\u7684nonebot2\u7684\u8bdd\uff0c\u5728bot\u8def\u5f84```pyproject.toml```\u7684```[tool.nonebot]```\u7684```plugins```\u4e2d\u6dfb\u52a0```nonebot_plugin_openAI_completions```\u5373\u53ef \npyproject.toml\u914d\u7f6e\u4f8b\u5982\uff1a \n``` \n[tool.nonebot]\nplugin_dirs = [\"src/plugins\"]\nplugins = [\"nonebot_plugin_openAI_completions\"]\n``` \n\n### \u66f4\u65b0\u7248\u672c\n```\nnb plugin update nonebot_plugin_openAI_completions\n```\n\n## \ud83d\udd27 \u914d\u7f6e\n\n### secret key\u83b7\u53d6\u65b9\u5f0f\n\u83b7\u53d6 openai \u7684 secret key \u9700\u8981\u60a8\u5148\u521b\u5efa\u4e00\u4e2a openai \u8d26\u53f7\uff0c\u7136\u540e\u5728\u5176\u7f51\u7ad9\u4e0a\u7533\u8bf7 API key\u3002 \n\n\u5177\u4f53\u6d41\u7a0b\u5982\u4e0b\uff1a \n\n1\u3001\u8bbf\u95ee openai \u7f51\u7ad9\uff08https://beta.openai.com/\uff09\uff0c\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u201cSign up\u201d\u6309\u94ae\u8fdb\u884c\u6ce8\u518c\u3002 \n2\u3001\u5728\u6ce8\u518c\u9875\u9762\u586b\u5199\u76f8\u5173\u4fe1\u606f\u5e76\u63d0\u4ea4\uff0c\u5b8c\u6210\u8d26\u53f7\u521b\u5efa\u3002 \n3\u3001\u767b\u5f55 openai \u7f51\u7ad9\uff0c\u70b9\u51fb\u53f3\u4e0a\u89d2\u7684\u201cDeveloper\u201d\u83dc\u5355\uff0c\u8fdb\u5165\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u3002 \n4\u3001\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\u70b9\u51fb\u201cNew API Key\u201d\u6309\u94ae\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 API key\u3002 \n5\u3001\u5728\u5f39\u51fa\u7684\u7a97\u53e3\u4e2d\u8f93\u5165\u60a8\u7684 API key \u540d\u79f0\uff0c\u7136\u540e\u70b9\u51fb\u201cCreate\u201d\u6309\u94ae\u3002 \n6\u3001\u5728\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\u770b\u5230\u60a8\u521b\u5efa\u7684 API key \u7684 secret key\u3002 \n\n### env\u914d\u7f6e\n```\n# \u5728\u4f60\u7684env\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u914d\u7f6e\uff08\u6211\u7684\u662f.env.prod\uff09 \nopenai_secret_key=\"sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"\n```\n| \u914d\u7f6e\u9879 | \u5fc5\u586b | \u9ed8\u8ba4\u503c | \u8bf4\u660e |\n|:----------------:|:----:|:----:|:----------------------------:|\n| `openai_secret_key` | \u662f | `\"\"` | \u53c2\u8003\u4e0a\u6587secret key\u83b7\u53d6\u65b9\u5f0f |\n\n\n## \ud83c\udf89 \u529f\u80fd\n\u8c03\u7528openAI\u7684API\u63a5\u53e3\u83b7\u53d6\u8bf7\u6c42\u8fd4\u56de\u76f4\u63a5\u8f93\u51fa\uff0c\u7b80\u5355\u7c97\u66b4\u3002 \n\n## \ud83d\udc49 \u547d\u4ee4\n\n### /cplt \u6216 /openai \u6216 /ai\n\u547d\u4ee4\u7ed3\u6784\uff1a```/cplt [\u4f60\u60f3\u95ee\u7684\u5185\u5bb9]``` \n\u4f8b\u5982\uff1a```/cplt \u7528python\u5b9e\u73b0hello world``` \u6216 ```/openai \u4f60\u53eb\u4ec0\u4e48\u540d\u5b57``` \u6216 ```/ai \u4eca\u5929\u662f\u4ec0\u4e48\u65e5\u5b50``` \nbot\u8fd4\u56de\u5185\u5bb9\uff1a \n\n\n\n## \u2699 \u62d3\u5c55\n\u81ea\u5df1\u52a8\u624b\u4e30\u8863\u8db3\u98df \n \n\n## \ud83d\udcdd \u66f4\u65b0\u65e5\u5fd7\n\n<details>\n<summary>\u5c55\u5f00/\u6536\u8d77</summary>\n\n### 0.0.1\n\n- \u63d2\u4ef6\u521d\u6b21\u53d1\u5e03 \n\n</details>\n\n## \u81f4\u8c22\n- [chat.openai.com](https://chat.openai.com)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "\u9002\u7528\u4e8enonebot2 v11\u7684\u57fa\u4e8etrace.moe\u7684\u52a8\u753b\u622a\u56fe\u573a\u666f\u8ffd\u6eaf\u63d2\u4ef6",
"version": "0.0.1",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "1b1e4849b6b380ba8c5d2198915e4db2",
"sha256": "0cebc7b87afbb23002705e4c42ddbd245237f586bca72a3773bf05b18c90bf0d"
},
"downloads": -1,
"filename": "nonebot_plugin_openai_completions-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1b1e4849b6b380ba8c5d2198915e4db2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 5461,
"upload_time": "2022-12-05T12:36:31",
"upload_time_iso_8601": "2022-12-05T12:36:31.244939Z",
"url": "https://files.pythonhosted.org/packages/79/21/6ca611739887cfb22e8000357baf6bd8d12a3196b587cc5dee3f21c1ce8b/nonebot_plugin_openai_completions-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "d01a58e2f02f911e579bf0712ff769d3",
"sha256": "9ea4d2602a355357bd83d64d8e19d8174f4288ba3b1ad2ee3a65af02b77b5c10"
},
"downloads": -1,
"filename": "nonebot_plugin_openai_completions-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "d01a58e2f02f911e579bf0712ff769d3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 6131,
"upload_time": "2022-12-05T12:36:34",
"upload_time_iso_8601": "2022-12-05T12:36:34.535825Z",
"url": "https://files.pythonhosted.org/packages/d9/0c/ce06a8732f127d3ffdfc189333e791d745e24bef9b14c2ca39510bb1c036/nonebot_plugin_openai_completions-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-05 12:36:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Ikaros-521",
"github_project": "nonebot_plugin_openAI_completions",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "nonebot-plugin-openai-completions"
}