wsxk / wsxk.github.io

MIT License
5 stars 0 forks source link

openai API试玩 #176

Closed wsxk closed 2 weeks ago

wsxk commented 5 months ago

https://wsxk.github.io/AIapi/

  1. 申请API key
  2. 安装python环境
  3. 设置api key进行开发
  1. 申请API key https://platform.openai.com/api-keys 中创建 API key

  2. 安装python环境 pip install openai pip install python-dotenv

  3. 设置api key进行开发 首先在.gitignore中写入一行.env,随后在你的工作区域下创建.env文件,其中写入你申请到的api key

    Once you add your API key below, make sure to not share it with anyone! The API key should remain private.

    OPENAI_API_KEY=sk-xxxx

然后再写代码 from openai import OpenAI from dotenv import load_dotenv

将.env中的变量加载

load_dotenv() client = OpenAI()

completion = client.chat.completions.create( model=