Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
陈银花 a194211414 | 1 year ago | |
---|---|---|
templates | 1 year ago | |
README.md | 1 year ago | |
app.py | 1 year ago | |
run.py | 1 year ago |
最近火出圈的 ChatGPT 公司 OpenAI 发布了 Chat API 和 gpt-3.5-turbo 模型,我们现在可以通过API 来使用与 ChatGPT 一样的 NLP 模型。
使用OpenAI API,可以使用gpt-3.5-turbo构建自己的应用程序,可执行以下任务:
下面用 Python 来讲解如何使用 openai python SDK 实现自己的聊天机器人。
如果你之前使用过 openai python SDK,请确保升级到了最新版本 (0.27.0);
如果还没有安装 Python 运行环境,请先安装 python(建议python版本>=3.9)。
你需要获取 API Key, 如果你已经使用过 openai SDK 那么你可能已经有 API Key 了(这种情况请跳过本节内容)。
登录 https://platform.openai.com/ 并导航到 https://platform.openai.com/account/api-keys 点击 Create new secret key 按钮可以获取一个新的 API Key。
注意:API Key 内容只会显示一次。点击复制按钮把 API Key 复制并保存好。
可以使用git工具拉去代码。或者直接下载压缩包。
需要安装如下模块启用后端模块:
pip install fastapi uvicorn openai
需要安装如下模块启用前端模块:
pip install Jinja2 python-multipart
在app.py中,找到 openai.api_key="xxxxxxxx"
, 替换open api key为你的key。
运行:run.py文件, 启动命令:python run.py
Web Server 已经启动完毕。
用浏览器打开 http://127.0.0.1:8080 可以看到一个基本的聊天窗口。现在就可以正常开始聊天啦!
Python+ChatGPT API,搭建专属你的智能聊天机器人
Python HTML
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》