开通 azure openAI之后,就可以使用它的服务了。
目前它提供了这几个模型
- gpt-35-turbo
- gpt-35-turbo-16k
- text-embedding-ada-002
开通azure openAI
增加资源 Azure OpenAI
部署 模型
打开 openAI资源,在 资源管理 找到 "manage deployments"
点击 按钮后,会跳转到 azure openAI studio
在这个画面, 点击 "create new deployment" 可以部署模型
使用
需要先获取几个关键信息
endpoint
key
api version
可以在 资源画面获取这些信息
在 python 代码使用
import openai
openai.api_key = os.getenv("AZURE_OPENAI_KEY")
openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT") # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
openai.api_type = 'azure'
openai.api_version = '2023-05-15' # this may change in the future
deployment_name='gpt-35-turbo-16k' #This will correspond to the custom name you chose for your deployment when you deployed a model.
response = openai.ChatCompletion.create(
engine=deployment_name, messages=message_log, temperature=0, timeout=1
)
content = (
response["choices"][0].get("message").get("content").encode("utf8").decode()
)
在 vs code 使用
- 安装插件 genieai.chatgpt-vscode
- 增加配置项目
"genieai.azure.url": "https://geninit-openai.openai.azure.com/openai/deployments/gpt-35-turbo-16k/chat/completions?api-version=2023-05-15"
使用 Azure OpenAI