gpt4 book ai didi

python - 从 Python 获取对外部服务的 API 调用的详细信息

转载 作者:行者123 更新时间:2023-12-03 06:12:11 24 4
gpt4 key购买 nike

我想获取从 python 代码到外部服务的 API 调用的详细信息(端点、参数等)。例如。在代码中

import openai
openai.api_type = "azure"
openai.api_base = "<your endpoint>"
openai.api_version = "2022-12-01"
openai.api_key = "<your token>"
engine = "test-code"
print(engine, openai.api_type, openai.api_key, openai.api_base, openai.api_version, openai.organization)
codex_query="What is OpenAI?"
response = openai.Completion.create(engine=engine, prompt=codex_query, stop="#")
print (response)
print (response['choices'][0]['text'])

我想检查对 Azure Open AI 服务的实际调用。我想要这样做的原因是因为上面的独立脚本可以工作,但是当我在开源中做同样的事情时,我试图增强它,并给出一个错误:

Invalid request - The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.

最佳答案

Invalid request - The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.

在您的代码中,您使用了engine,但是您需要提及您的部署名称。您可以使用下面的门户获取部署名称。

enter image description here

如果您已经创建了部署名称,请等待一段时间,因为预览似乎需要一段时间。

我尝试使用相同的代码将部署名称更改为deployment1,它执行成功。

代码:

import openai


openai.api_type = "azure"
openai.api_base = "your-endpoint-name"
openai.api_version = "2022-12-01"
openai.api_key = "your-azure-api-key"
deploymentname = "Deployment1"
print(deploymentname, openai.api_type, openai.api_key, openai.api_base, openai.api_version, openai.organization)
codex_query="What is OpenAI provide me details?"
response = openai.Completion.create(engine=deploymentname, prompt=codex_query,stop="#")
print (response)
print (response['choices'][0]['text'])

输出:

 Deployment1 azure xxxxxxxx xxxxxxx 2022-12-01 None
{
"id": "cmpl-7adGc6hEbwALupcxxxxxxxxx",
"object": "text_completion",
"created": 1688965106,
"model": "code-davinci-002",
"choices": [
{
"text": "\n\nOpenAI is a artificial intelligence Artificial Intelligence is an art of making",
"index": 0,
"finish_reason": "length",
"logprobs": null
}
],
"usage": {
"completion_tokens": 16,
"prompt_tokens": 7,
"total_tokens": 23
}
}


OpenAI is a artificial intelligence Artificial Intelligence is an art of making

enter image description here

引用:

openai-samples/Basic_Samples/Completions/basic_completions_example_sdk.ipynb at main · Azure/openai-samples · GitHub

关于python - 从 Python 获取对外部服务的 API 调用的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76642829/

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