I am trying to connect to Azure OpenAI using the latest version of SDK (version 2.0.0-beta.1) but no matter what I do, I am getting Resource not found
error). When I use the previous version (1.0.0-beta.12) of the SDK, everything works well.
These are the settings in my environment file:
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"
and this is how I am creating my client:
azureOpenAIClient = new AzureOpenAI({
baseURL: process.env.AZURE_OPENAI_ENDPOINT,
// apiKey: process.env.AZURE_OPENAI_API_KEY, (tried without commenting it as well)
deployment: process.env.AZURE_OPENAI_CHAT_COMPLETION_MODEL_DEPLOYMENT_ID,
apiVersion: process.env.AZURE_OPENAI_API_VERSION,
});
and this is my code:
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;
}
I even tried changing the model
to my deployment id above but the result is the same.
I am pretty sure I am missing something really trivial but I am not able to figure it out. Can anyone tell me what I am doing wrong here? Thanks.
UPDATE
Here's the stack trace:
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
The issue was that I was trying to set baseURL
property when I was instantiating AzureOpenAI
. The correct property is endpoint
.
Here's the GitHub issue that solved my problem: https://github.com/Azure/azure-sdk-for-js/issues/30669.