赞
踩
https://platform.openai.com/docs/quickstart/build-your-application
本示例会生成一个简单的ChatGPT api接口调用server程序,该程序可以给用户输入的宠物类别为宠物取三个名字。打开网页后,会看到用户输入界面,输入宠物类别,比如cat,然后回车,界面中会给出三个宠物名字。
1.系统:ubuntu20.04 或以上( python版本示例需要用到它自带的python10环境,其它版本自己装python10应该也可以 )
该系统需要能上网
2、一个用openAI账号(最好plus版,免费版很受限制)生成的secret_key
python版:git clone https://github.com/openai/openai-quickstart-python.git
node.js版:git clone https://github.com/openai/openai-quickstart-node.git
如果不想用git,可以直接打开上面的网址,手动下载代码的zip压缩包
在其中生成secret_key,并复制下来:
OPENAI_API_KEY="seret_key内容"
python版:
cd .../openai-quickstart-python
python -m venv venv. venv/bin/activate
pip install -r requirements.txt
flask run
此时命令行会提示服务器正在运行:http://127.0.0.1/5000
node.js版:
npm install npm run dev 此时命令行会提示服务器正在运行:http://127.0.0.1/3000 可能遇到的问题: 执行命令npm run dev时出现: showAll: args["--show-all"] ?? false, syntaxError: Unexpected token '?' 原因:node.js版本不是v18,改为v18: To fix this, you need to follow the steps in this order: Run this command to get the nvm: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash Restart your terminal. Install nvm: nvm install v18.12.1 Start nvm: npm run dev You can use nvm list-remote to look at a complete list of the versions to choose from. For more information, read here under option 3: installing-node-using-the-node-version-manager
参考:https://stackoverflow.com/questions/74707066/nextjs-unexpected-token
python版:http://127.0.0.1/5000
node.js版:http://127.0.0.1/3000
此时应打开网页,网页中显示宠物命名界面。在输入栏输入宠物类别并回车,比如dog,页面会给出三个宠物名字。
祝大家愉快!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。