我尝试使用最新版本的 SDK(版本 2.0.0-beta.1)连接到 Azure OpenAI,但无论我怎么做,都会收到 Resource not found
错误。当我使用之前版本的 SDK(1.0.0-beta.12)时,一切正常。
这些是我环境文件中的设置:
AZURE_OPENAI_ENDPOINT="https://xxx.openai.azure.com/"AZURE_OPENAI_API_KEY="xxxxyyyyxxxxyyyyxxxxyyyyxxxxyyyy"AZURE_OPENAI_CHAT_COMPLETION_MODEL_DEPLOYMENT_ID="gpt-4o"AZURE_OPENAI_API_VERSION="2024-04-01-preview"
这是我创建客户端的方式:
azureOpenAIClient = new AzureOpenAI({ baseURL: process.env.AZURE_OPENAI_ENDPOINT, // apiKey: process.env.AZURE_OPENAI_API_KEY, (尝试过不注释它) deployment: process.env.AZURE_OPENAI_CHAT_COMPLETION_MODEL_DEPLOYMENT_ID, apiVersion: process.env.AZURE_OPENAI_API_VERSION,});
这是我的代码:
const messages: OpenAI.ChatCompletionMessageParam[] = [ { role: 'system', content: systemMessage }, { role: 'user', content: userMessage }, ];const result = await azureOpenAIClient.chat.completions.create( { messages, model: '', response_format: { type: jsonOutput ? 'json_object' : 'text' }, }, {}, );let response = '';for await (const choice of result.choices) { response += choice.message?.content;}
我甚至尝试将 model
更改为上面的部署 ID,但结果还是一样。
我很确定我遗漏了一些非常简单的东西,但我无法找出问题所在。谁能告诉我我做错了什么?谢谢。
更新
这是堆栈跟踪:
NotFoundError: 404 Resource not found at APIError.generate (webpack-internal:///(action-browser)/../../node_modules/openai/error.mjs:67:20) at AzureOpenAI.makeStatusError (webpack-internal:///(action-browser)/../../node_modules/openai/core.mjs:304:65) at AzureOpenAI.makeRequest (webpack-internal:///(action-browser)/../../node_modules/openai/core.mjs:347:30) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)....rest is the list of my files
回答:
问题在于我在实例化 AzureOpenAI
时尝试设置 baseURL
属性。正确的属性应该是 endpoint
。
解决我问题的 GitHub 问题在这里:https://github.com/Azure/azure-sdk-for-js/issues/30669。