songquanpeng / one-api

OpenAI 接口管理 & 分发系统,支持 Azure、Anthropic Claude、Google PaLM 2 & Gemini、智谱 ChatGLM、百度文心一言、讯飞星火认知、阿里通义千问、360 智脑以及腾讯混元,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用. OpenAI key management & redistribution system, using a single API for all LLMs, and features an English UI.
https://openai.justsong.cn/
MIT License
17.87k stars 4.05k forks source link

Azure OpenAI API #57

Closed aiastia closed 1 year ago

aiastia commented 1 year ago

想问下有无提上议程

aiastia commented 1 year ago

截图_20230513154708

songquanpeng commented 1 year ago

可以用 Postman 手动测试一下吗?或者 OpenChat 如果有报错信息的话最好发一下。

aiastia commented 1 year ago

Postman 要怎么……

aiastia commented 1 year ago

image

songquanpeng commented 1 year ago

POST: http://localhost:3000/v1/chat/completions

格式选 raw,内容为:

{
    "model": "gpt-3.5-turbo",
    "messages": [{"role": "user", "content": "hi"}]
}

image

这里设置 token,注意指定使用 Azure 通道: image

aiastia commented 1 year ago

{ "error": { "code": "404", "message": "Resource not found" } }

aiastia commented 1 year ago

如果禁用azure 模型 提示 的 就是 { "error": { "message": "you must provide a model parameter", "type": "invalid_request_error", "param": null, "code": null } }

songquanpeng commented 1 year ago

看一下请求体,我怀疑 model 参数没加。

aiastia commented 1 year ago

body 里面的吗 我就复制你的 { "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "hi"}] }

aiastia commented 1 year ago

headers 我没有添加

songquanpeng commented 1 year ago

这就离谱了,Header 不用加,只需要设置 authorization token 就好。

请求路径正确吗?

aiastia commented 1 year ago

这就离谱了,Header 不用加,只需要设置 authorization token 就好。

请求路径正确吗? 你给我的是 POST: http://localhost:3000/v1/chat/completions

我把 localhost:3000 改成自己的域名了 https://***.xyz/v1/chat/completions

aiastia commented 1 year ago

image

songquanpeng commented 1 year ago

这个配置了吗? image

AZURE_OPENAI_ENDPOINT 是这样的格式吗? image

aiastia commented 1 year ago

这个配置了吗? image

AZURE_OPENAI_ENDPOINT 是这样的格式吗? image

默认 API 版本 写的是 0301 AZURE_OPENAI_ENDPOINT(azure 官网上是叫 终结点吧) 写的是azure 上复制的域名 https://hj***.openai.azure.com

songquanpeng commented 1 year ago

写错了,目前必须填 2023-03-15-preview,这个版本是 Azure 自己定义的版本。

aiastia commented 1 year ago

已经改了 现在换了一个提示

{ "error": { "message": "Invalid Content-Type header (text/plain), expected application/json. (HINT: If you're using curl, you can pass -H 'Content-Type: application/json')", "type": "invalid_request_error", "param": null, "code": null } }

songquanpeng commented 1 year ago

请求体格式没选对: image

aiastia commented 1 year ago

{ "id": "chatcmpl-7FepLXnl9gryYFYQIMlbmx554gV5e", "object": "chat.completion", "created": 1683966215, "model": "gpt-35-turbo", "choices": [ { "index": 0, "finish_reason": "stop", "message": { "role": "assistant", "content": "Hello! How can I assist you today?" } } ], "usage": { "completion_tokens": 9, "prompt_tokens": 9, "total_tokens": 18 } }

songquanpeng commented 1 year ago

这已经 Okay 了,现在再试一下 OpenChat。

aiastia commented 1 year ago

这已经 Okay 了,现在再试一下 OpenChat。

都一样的报错 ……

image

这个是我用 官网的 api (禁用了azure 的提示)

{
    "id": "chatcmpl-7FeqJUpHWoo5bjjGpibEOHQ410Yjn",
    "object": "chat.completion",
    "created": 1683966275,
    "model": "gpt-3.5-turbo-0301",
    "usage": {
        "prompt_tokens": 9,
        "completion_tokens": 9,
        "total_tokens": 18
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "Hello! How can I assist you today?"
            },
            "finish_reason": "stop",
            "index": 0
        }
    ]
}
songquanpeng commented 1 year ago

Okay,那现在使用 Azure 通道进行请求,Postman 中的返回内容是什么呢?

aiastia commented 1 year ago
{
    "id": "chatcmpl-7FeuwyXuYsjrJHv17jN6z4k1o7t30",
    "object": "chat.completion",
    "created": 1683966562,
    "model": "gpt-3.5-turbo-0301",
    "usage": {
        "prompt_tokens": 9,
        "completion_tokens": 9,
        "total_tokens": 18
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "Hello! How can I assist you today?"
            },
            "finish_reason": "stop",
            "index": 0
        }
    ]
}

官网的

aiastia commented 1 year ago
{
    "id": "chatcmpl-7FeuQLPZxsNVAduoMqC2jjAnPOH0e",
    "object": "chat.completion",
    "created": 1683966530,
    "model": "gpt-35-turbo",
    "choices": [
        {
            "index": 0,
            "finish_reason": "stop",
            "message": {
                "role": "assistant",
                "content": "Hello! How may I assist you today?"
            }
        }
    ],
    "usage": {
        "completion_tokens": 9,
        "prompt_tokens": 9,
        "total_tokens": 18
    }
}

azure 的

aiastia commented 1 year ago

然后我测试了一下 openchat 里面 如果模型是有0301 的时候 就提示 上面的图片

如果模型是没有0301 的就先回房消息然后 在提示那个图片

aiastia commented 1 year ago

chatbox 就是 选择 没有0301后缀 的模型 就提示 Unexpected token 'D', "[DONE] " is not valid JSON

如果有 就是卡住不回复

songquanpeng commented 1 year ago

Azure 的模型列表里面并没有带 0301 后缀的,所以这个出错正常。

我感觉是因为 OpenAI 和 Azure 的 stream 模式下格式有差异。

aiastia commented 1 year ago

image 然后我发现我模型没有上面老哥那个模型多……

aiastia commented 1 year ago

Azure 的模型列表里面并没有带 0301 后缀的,所以这个出错正常。

我感觉是因为 OpenAI 和 Azure 的 stream 模式下格式有差异。

看来是没办法兼容了吗? 感觉现有的app 很少有支援azure 的ai

songquanpeng commented 1 year ago

肯定可以兼容的,我现在需要确定究竟是不是 stream 下格式的问题。

@how1ewu 请问你有遇到类似的情况吗?

aiastia commented 1 year ago

https://github.com/haibbo/cf-openai-azure-proxy/blob/main/cf-openai-azure-proxy.js 我看有个这个 项目 您看看?

songquanpeng commented 1 year ago

Okay,等我有 token 测试或者 @how1ewu 允许我继续用他那个 token 测试后再看一下这个问题。

aiastia commented 1 year ago

Okay,等我有 token 测试或者 @how1ewu 允许我继续用他那个 token 测试后再看一下这个问题。

目前用上面的cf 反代 然后 在open api 添加自定义 然后就曲线救国了

utopeadia commented 1 year ago

image

utopeadia commented 1 year ago

Okay,等我有 token 测试或者 @how1ewu 允许我继续用他那个 token 测试后再看一下这个问题。

image 我后台又部署了一个text ada模型供你参考

utopeadia commented 1 year ago

现在这种方式好像好多插件都不太兼容,我的vscode插件、utools插件、obsidian插件都会提示json错误Unexpected token ‘D’, "[DONE] " is not valid JSON。可以实现为类似cf-openai-azure-proxy.js这种代理模式吗

songquanpeng commented 1 year ago

当然可以,我现在调查一下原因。

songquanpeng commented 1 year ago

我已经定位到问题了,问题在于 Azure 的 stream 模式下,输出的结尾标识符 [DONE] 后面多了一个空格,而且他不会主动结束 stream。

songquanpeng commented 1 year ago

是多了一个换行符。

songquanpeng commented 1 year ago

v0.2.5-alpha 已推送。

我已经用 ChatGPT Next 测试过了,测试 Okay。

@aiastia @how1ewu

aiastia commented 1 year ago

高产……Opencat 正常 不过模型要选gpt-3.5-turbo

如果选择 gpt-3.5-turbo-0301 就报错

但是 azure 的open ai gpt-3.5-turbo 就是 gpt-3.5-turbo-0301 吧……

能否配置一个映射 像这样

const mapper = {
    'gpt-3.5-turbo': DEPLOY_NAME_GPT35,
    'gpt-4': DEPLOY_NAME_GPT4
};
aiastia commented 1 year ago

Okay,等我有 token 测试或者 @how1ewu 允许我继续用他那个 token 测试后再看一下这个问题。

image 我后台又部署了一个text ada模型供你参考

为啥你的可用模型这么多啊……

songquanpeng commented 1 year ago

映射这个简单,直接硬编码一个 map 完事。

aiastia commented 1 year ago

映射这个简单,直接硬编码一个 map 完事。

在渠道添加上面加一个 感觉会更好( 然后能给渠道添加一个备注选项吗

aiastia commented 1 year ago

v0.2.5-alpha 已推送。

我已经用 ChatGPT Next 测试过了,测试 Okay。

@aiastia @how1ewu

视乎引入的新的问题 就是使用open ai 的 api 的 就提示 ” 未能读取数据,因为它的格式不正确“

songquanpeng commented 1 year ago

不应该啊,我也测试了之前的。具体是什么软件的报的错?

aiastia commented 1 year ago

不应该啊,我也测试了之前的。具体是什么软件的报的错?

使用的是Openchat ios 的 发送消息 就提示 ” 未能读取数据,因为它的格式不正确“ 不过 他还是可以接受回复 。

aiastia commented 1 year ago

image

你看 回复的消息收到了。 但是会提示这个

aiastia commented 1 year ago

不应该啊,我也测试了之前的。具体是什么软件的报的错?

用open ai 官网的 api 的 他在接受所有的消息后 弹出上面这个提示…… 如果用azure 的 就不会……

aiastia commented 1 year ago

看了一下 非 azure 的 会回复

 [DONE

azure 的回复

[DONE
]

少了个 “]”