Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure OpenAI 支持吗 #7

Closed
WangNingkai opened this issue May 23, 2024 · 21 comments
Closed

Azure OpenAI 支持吗 #7

WangNingkai opened this issue May 23, 2024 · 21 comments

Comments

@WangNingkai
Copy link

No description provided.

@idootop
Copy link
Owner

idootop commented May 23, 2024

默认不支持 Azure OpenAI,感兴趣的话可以按照 https://www.npmjs.com/package/openai 文档自己定制,欢迎 PR。
image

@idootop
Copy link
Owner

idootop commented May 26, 2024

v2.0.0 版本已添加支持,请按 OpenAI 文档配置相应环境变量。

@shog86
Copy link
Contributor

shog86 commented Jun 4, 2024

v2.0.0 版本已添加支持,请按 OpenAI 文档配置相应环境变量。

请问在env里设置了endpoint和key之后,设置model的变量还是 OPENAI_MODEL吗?

@idootop
Copy link
Owner

idootop commented Jun 4, 2024

@shog86 模型变量名称 OPENAI_MODEL 不变

@shog86
Copy link
Contributor

shog86 commented Jun 4, 2024

所以Azure的话设置endpoint,key,model三个变量就行是吧,和OpenAI的一样,deployment不用设置哈?

@idootop
Copy link
Owner

idootop commented Jun 4, 2024

不确定,我没有 Azure 的账号用来测试,具体需要配置那些环境变量自己查文档:https://github.com/openai/openai-node?tab=readme-ov-file#microsoft-azure-openai

@shog86
Copy link
Contributor

shog86 commented Jun 6, 2024

Azure的日志来了,求分析,响应了提示语,但缺参数得不到回复,然后服务也因此停止了

2024/06/06 01:39:01 Speaker ✅ 服务已启动...
2024/06/06 01:39:29 Speaker 🔥 请你介绍一下美国儿科学会
2024/06/06 01:39:30 Speaker 🔊 请稍等
/app/node_modules/.pnpm/openai@4.47.3/node_modules/openai/index.js:163
throw new Errors.OpenAIError("The OPENAI_API_VERSION environment variable is missing or empty; either provide it, or instantiate the AzureOpenAI client with an apiVersion option, like new AzureOpenAI({ apiVersion: 'My API Version' }).");
^

OpenAIError: The OPENAI_API_VERSION environment variable is missing or empty; either provide it, or instantiate the AzureOpenAI client with an apiVersion option, like new AzureOpenAI({ apiVersion: 'My API Version' }).
at new AzureOpenAI (/app/node_modules/.pnpm/openai@4.47.3/node_modules/openai/index.js:163:19)
at OpenAIClient._init (/app/dist/index.cjs:1066:51)
at OpenAIClient.chatStream (/app/dist/index.cjs:1128:10)
at _MyBot.chatWithStreamResponse (/app/dist/index.cjs:2291:12)
at _MyBot.ask (/app/dist/index.cjs:2273:33)
at async AISpeaker._askAIForAnswerSteps.res.response (/app/dist/index.cjs:990:20)
at async AISpeaker.askAIForAnswer (/app/dist/index.cjs:1024:19)
at async AISpeaker.onMessage (/app/dist/index.cjs:739:24)

Node.js v20.14.0

@idootop
Copy link
Owner

idootop commented Jun 6, 2024

补一下 OPENAI_API_VERSION 环境变量,具体填什么值,查一下 OpenAI 的使用文档

@shog86
Copy link
Contributor

shog86 commented Jun 6, 2024

补一下 OPENAI_API_VERSION 环境变量,具体填什么值,查一下 OpenAI 的使用文档

完了之后是需要重启容器,还是删掉重启docker run?

@idootop
Copy link
Owner

idootop commented Jun 6, 2024

直接删了重启吧

@shog86
Copy link
Contributor

shog86 commented Jun 6, 2024

现在长这样,晚上回家试试
Server Box 2024-06-06 12 33 49

@shog86
Copy link
Contributor

shog86 commented Jun 6, 2024

image

@idootop
Copy link
Owner

idootop commented Jun 6, 2024

@shog86 1. 提示 set-cookie 访问的对象为空,这个问题我后面修一下,但是看起来并不影响正常登录小米账号。2. Azure 404 的问题估计还是哪里配置的不正确,我今晚试试注册一个 Azure 试试,或者你在我微信公众号后台私信我你的帐号信息,联调一下。

@shog86
Copy link
Contributor

shog86 commented Jun 6, 2024

从你的报错信息来看,这是一个典型的 HTTP 404 错误,即“资源未找到”(Resource Not Found)。这是由于在调用 Azure OpenAI API 时,指定的资源或端点不存在或无法找到。

以下是可能的解决步骤和检查点:

  1. 检查 URL 和端点:

    • 确保你使用的 API URL 是正确的。在某些情况下,拼写错误或路径错误可能导致找不到资源。
    const apiUrl = "https://your-correct-endpoint.azure.com/path";
  2. 检查 API 路径和版本:

    • 确保你使用的 API 路径和版本是正确的。不正确的路径可能会引发 404 错误。
  3. 检查资源 ID:

    • 在请求中,如果需要特定资源 ID,请确认该 ID 是正确且存在的。
  4. 确保资源已部署:

    • 确保你在 Azure Portal 上正确地部署并配置了 OpenAI 服务和相关资源。
  5. 查看 API 请求参数:

    • 有时请求参数错误也可能导致 404 错误,确保参数名称和格式正确无误。
  6. Azure OpenAI 服务状态:

    • 检查 Azure 服务的状态页面,确保没有运行维护或中断事件。
  7. 示例代码校验:

    • 确保你调用 API 的代码没有语法或逻辑错误。以下是一个调用 Azure OpenAI API 的示例代码:
    const openai = require('openai');
    
    const apiKey = "your-api-key";
    openai.apiKey = apiKey;
    
    const apiClient = new openai.AzureOpenAI({
        baseUrl: "https://your-correct-endpoint.azure.com/path", // 确保此URL是正确的
        apiKey: apiKey,
    });
    
    async function fetchOpenAIData() {
        try {
            const response = await apiClient.chatStream({
                model: "model-id", // 确保模型ID是有效的
                messages: [
                    { role: "user", content: "Hello!" }
                ]
            });
            console.log(response);
        } catch (error) {
            console.error("Error:", error);
        }
    }
    
    fetchOpenAIData();

如果以上步骤都无法解决问题,建议查看详细的 API 文档或联系 Azure 支持团队获取更多帮助。

@idootop
Copy link
Owner

idootop commented Jun 6, 2024

@shog86 你配置的这几个环境变量名称都没问题,你再按 Azure 的官方教程看看,这几个环境变量的值对不对:https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-javascript

@shog86
Copy link
Contributor

shog86 commented Jun 7, 2024

Server Box 2024-06-07 08 56 00

成了

env里长这样

image

API version要按Playground里示例代码那样写,不能按Azure部署那儿显示的写

@idootop
Copy link
Owner

idootop commented Jun 7, 2024

赞👍多谢反馈

@jooekong
Copy link

@shog86 @idootop
请教两位大佬,azure openai还是遇到404报错, .env配置如下, 镜像是最新的6.22的,这是哪里配置的有问题吗? 敏感信息用xxx替代了

deployment=gpt-4o
OPENAI_API_VERSION=2024-02-15-preview
AZURE_OPENAI_API_KEY=xxx
AZURE_OPENAI_ENDPOINT=https://xxxx.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT=gpt-4o-2024-0513(OpenAI)

@idootop
Copy link
Owner

idootop commented Jun 27, 2024

@jooekong 感觉像是这样

OPENAI_API_VERSION=2024-02-15-preview
AZURE_OPENAI_API_KEY=xxx
AZURE_OPENAI_ENDPOINT=https://xxxx.openai.azure.com
AZURE_OPENAI_DEPLOYMENT=gpt-4o

@jooekong
Copy link

@jooekong 感觉像是这样

OPENAI_API_VERSION=2024-02-15-preview
AZURE_OPENAI_API_KEY=xxx
AZURE_OPENAI_ENDPOINT=https://xxxx.openai.azure.com
AZURE_OPENAI_DEPLOYMENT=gpt-4o

这样也不行。。怎么打开debug日志?看看拼出来的url啥的,抓包太麻烦了

@idootop
Copy link
Owner

idootop commented Jun 28, 2024

@jooekong 用的 OpenAI 的 SDK,没有打印日志的开关

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants