Skip to main content
NoneBotPluginLogo

NoneBotPluginText

nonebot_plugin_openAI_completions

✨ NoneBot 调用openAI completions接口实现的对话插件 ✨

GitHub stars GitHub issues GitHub forks license pypi python

适用于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返回内容:

⚙ 拓展

自己动手丰衣足食

📝 更新日志

展开/收起

0.0.1

  • 插件初次发布

致谢

Metadata

Release files for nonebot-plugin-openai-completions 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-openai-completions 0.0.1
File Size Uploaded
nonebot_plugin_openai_completions-0.0.1.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-openai-completions 0.0.1
File Interpreter ABI Platform
nonebot_plugin_openai_completions-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / nonebot_plugin_openai_completions-0.0.1.tar.gz

Download URL nonebot_plugin_openai_completions-0.0.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9ea4d2602a355357bd83d64d8e19d8174f4288ba3b1ad2ee3a65af02b77b5c10
BLAKE2b-256 checksum
How to use checksums
d90cce06a8732f127d3ffdfc189333e791d745e24bef9b14c2ca39510bb1c036
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.13 Windows/10

Release files / nonebot_plugin_openai_completions-0.0.1-py3-none-any.whl

Download URL nonebot_plugin_openai_completions-0.0.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cebc7b87afbb23002705e4c42ddbd245237f586bca72a3773bf05b18c90bf0d
BLAKE2b-256 checksum
How to use checksums
79216ca611739887cfb22e8000357baf6bd8d12a3196b587cc5dee3f21c1ce8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.13 Windows/10

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page