gpt4 book ai didi

python - Azure Api 和 ChatGPT 的问题 (python)

转载 作者:行者123 更新时间:2023-12-02 05:49:21 26 4
gpt4 key购买 nike

我的任务是处理 Azure OpenAI 服务和 ChatGPT。在这个过程中,当他们给我 key 、端点等时,我遇到了这个问题:

openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://platform.openai.com/account/api-keys for details.

这里是代码:

import os
import openai
openai.api_type = "azure"
openai.api_version = "2023-05-15"
openai.api_base = os.getenv("EndPointHERE")
openai.api_key = os.getenv("KeyHere")

response = openai.ChatCompletion.create(
engine="KSUAI",
messages=[
{"role": "system", "content": "Assistant is a large language model trained by OpenAI."},
{"role": "user", "content": "Who were the founders of Microsoft?"}
]
)

print(response)

print(response['choices'][0]['message']['content'])

最佳答案

通过从代码中删除 os.getenv 并将给定的键和端点直接写入变量来解决该问题

关于python - Azure Api 和 ChatGPT 的问题 (python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76596008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com