Manoj ahirwar
Manoj ahirwar

Reputation: 1106

Keep getting Deployment not found when switching to Azure OpenAI from OpenAI

I have been using OpenAI with langchain in my application and recently tries to switch to Azure OpenAI but keep getting error - Error: Azure OpenAI API deployment name not found.

Following is the code I am using

import { AzureChatOpenAI } from '@langchain/openai';

  const llm = new AzureChatOpenAI({
    temperature: 0,
    azureOpenAIApiDeploymentName: 'GPT35turbo16k',
    azureOpenAIApiVersion: '0613',
    azureOpenAIApiInstanceName: 'https://my-instance-name.openai.azure.com/',
    azureOpenAIApiKey: 'my-api-key',
    streaming: true,
    verbose: true,
    callbacks: [
      {
        handleLLMNewToken(token: string) {
          res.write(
            JSON.stringify({
              type: 'html',
              content: token,
            }),
          );
        },
      },
    ],
  });

I already created deployment in Azure and using deployment name instead of model name. screenshot of azure attached.

Screenshot 2024-06-08 at 11 59 19 PM

Screenshot 2024-06-08 at 11 59 19 PM

any help is appreciated. Thanks

Upvotes: 0

Views: 483

Answers (2)

qkfang
qkfang

Reputation: 388

click on deployment name hyperlink in your screenshot and go to the deployment detail page as below:

  • #1 = azureOpenAIApiInstanceName
  • #2 = azureOpenAIApiVersion
  • #3 = azureOpenAIApiDeploymentName
  • #4 = azureOpenAIApiKey

enter image description here

Upvotes: 0

eventHandler
eventHandler

Reputation: 1211

The request looks good, except for the API version. You should get the right version from the Microsoft documentation.

As of now, the latest stable General Availability API version is 2024-02-01. In your example, you should have:

import { AzureChatOpenAI } from '@langchain/openai';

  const llm = new AzureChatOpenAI({
    temperature: 0,
    azureOpenAIApiDeploymentName: 'GPT35turbo16k',
    azureOpenAIApiVersion: '2024-02-01', // use the right version here
    azureOpenAIApiInstanceName: 'https://my-instance-name.openai.azure.com/',
    azureOpenAIApiKey: 'my-api-key',
    streaming: true,
    verbose: true,
    callbacks: [
      {
        handleLLMNewToken(token: string) {
          res.write(
            JSON.stringify({
              type: 'html',
              content: token,
            }),
          );
        },
      },
    ],
  });

Upvotes: 0

Related Questions