lobehub / lobe-chat

🤯 Lobe Chat - an open-source, modern-design AI chat framework. Supports Multi AI Providers( OpenAI / Claude 3 / Gemini / Ollama / Azure / DeepSeek), Knowledge Base (file upload / knowledge management / RAG ), Multi-Modals (Vision/TTS) and plugin system. One-click FREE deployment of your private ChatGPT/ Claude application.
https://chat-preview.lobehub.com
Other
44.41k stars 9.96k forks source link

[Bug] azure openAI 配置问题请教 #4115

Closed xiaoJack closed 1 month ago

xiaoJack commented 1 month ago

📦 Environment

Docker

📌 Version

v1.19.27

💻 Operating System

Other Linux

🌐 Browser

Chrome

🐛 Bug Description

您好,麻烦咨询 azure openAI 配置问题 通过浏览器配置方式

WeChatWorkScreenshot_50b4d726-2745-4ba5-a7e7-28019dbad7c7 WeChatWorkScreenshot_ad979e2c-583c-4c64-a65c-b1d7d6427979

一直提示错误 { "error": { "code": "DeploymentNotFound", "message": "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.", "deployId": "gpt-4o-mini" }, "endpoint": "https://***.openai.azure.com/", "provider": "azure" }

API_KEY 和 ENDPOINT 确定了都没有错误,看了历史issues和官网配置教程没找到解决方法

📷 Recurrence Steps

No response

🚦 Expected Behavior

No response

📝 Additional Information

No response

lobehubbot commented 1 month ago

👀 @xiaoJack

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. Please make sure you have given us as much context as possible.\ 非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

dosubot[bot] commented 1 month ago

@xiaoJack 你好!我是Dosu,一个可以帮助你解决bug、回答问题,并成为贡献者的机器人。我会在等待人类维护者的期间帮助你解决问题。

I found some similar discussions and issues that might help you resolve the "DeploymentNotFound" error:

  1. Similar Discussions:

  2. Closed Issues:

To resolve the "DeploymentNotFound" error, ensure that the deployment ID (model) you are using is correct and exists in your Azure OpenAI service. Here are the steps to verify and correct the deployment:

  1. Verify Deployment ID:

    • Ensure that the deployment ID gpt-4o-mini exists in your Azure OpenAI service.
    • If it does not exist, create a new deployment with the correct name and configuration.
  2. Create Azure OpenAI Instance:

    • Use the following code snippet to create an Azure OpenAI instance:
    import OpenAI, { ClientOptions } from 'openai';
    import urlJoin from 'url-join';
    
    import { getLLMConfig } from '@/config/llm';
    import { ChatErrorType } from '@/types/fetch';
    
    // create Azure OpenAI Instance
    export const createAzureOpenai = (params: {
     apiVersion?: string | null;
     endpoint?: string | null;
     model: string;
     userApiKey?: string | null;
    }) => {
     const { OPENAI_PROXY_URL = '', AZURE_API_VERSION, AZURE_API_KEY } = getLLMConfig();
    
     const endpoint = !params.endpoint ? OPENAI_PROXY_URL : params.endpoint;
     const baseURL = urlJoin(endpoint, `/openai/deployments/${params.model.replace('.', '')}`);
    
     const defaultApiVersion = AZURE_API_VERSION || '2023-08-01-preview';
     const apiVersion = !params.apiVersion ? defaultApiVersion : params.apiVersion;
     const apiKey = !params.userApiKey ? AZURE_API_KEY : params.userApiKey;
    
     if (!apiKey) throw new Error('AZURE_API_KEY is empty', { cause: ChatErrorType.NoOpenAIAPIKey });
    
     const config: ClientOptions = {
       apiKey,
       baseURL,
       defaultHeaders: { 'api-key': apiKey },
       defaultQuery: { 'api-version': apiVersion },
     };
    
     return new OpenAI(config);
    };
  3. Error Handling:

    • Ensure that the error handling code correctly identifies and handles the "DeploymentNotFound" error:
    if (error.code) {
     switch (error.code) {
       case 'DeploymentNotFound': {
         error = { ...error, deployId: model };
       }
     }
    } else {
     error = {
       cause: error.cause,
       message: error.message,
       name: error.name,
     } as any;
    }
    
    const errorType = error.code
     ? AgentRuntimeErrorType.ProviderBizError
     : AgentRuntimeErrorType.AgentRuntimeError;
    
    throw AgentRuntimeError.chat({
     endpoint: this.maskSensitiveUrl(this.baseURL),
     error,
     errorType,
     provider: ModelProvider.Azure,
    });

By following these steps, you should be able to resolve the "DeploymentNotFound" error and ensure that your Azure OpenAI deployment is correctly configured [6][7].

To continue talking to Dosu, mention @dosu.

sxjeru commented 1 month ago

模型列表直接用 gpt-4o 即可,你这是环境变量中的用法。

另外“连通性测试”目前用的是 gpt-4o-mini,如果你 Azure 那边没开通,连通性测试是过不了的。

lobehubbot commented 1 month ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


You can directly use gpt-4o for the model list. This is how you use it in environment variables.

xiaoJack commented 1 month ago

模型列表直接用 gpt-4o 即可,你这是环境变量中的用法。

另外“连通性测试”目前用的是 gpt-4o-mini,如果你 Azure 那边没开通,连通性测试是过不了的。

WeChatWorkScreenshot_c3e8cce8-fe3a-42e0-9849-a97aece58cf3 WeChatWorkScreenshot_e28e474e-b0fb-48bf-bab7-23b5895dcca6

部署名和模型名我都试了,还是同样的错误,环境变量的方式也试了,还是一样

lobehubbot commented 1 month ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


You can use gpt-4o directly for the model list. This is how you use it in environment variables.

In addition, the "connectivity test" currently uses gpt-4o-mini. If you have not activated Azure, the connectivity test will not pass.

WeChatWorkScreenshot_c3e8cce8-fe3a-42e0-9849-a97aece58cf3 WeChatWorkScreenshot_e28e474e-b0fb-48bf-bab7-23b5895dcca6

I tried both the deployment name and the model name, but still the same error. I also tried the environment variable method, but still the same error.

sxjeru commented 1 month ago

不要用连通性检查,直接去聊天试试。

lobehubbot commented 1 month ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Don't use connectivity check, just go to chat and try.

xiaoJack commented 1 month ago

不要用连通性检查,直接去聊天试试。

抱歉现在才回复,我刚刚试了使用部署名一直在loading,使用模型名就直接报错,我直接在mac docker部署的,在系统里面使用官方 curl 请求都正常没问题的

image