首先,我们来整理一下上述的请求和响应:
Azure OpenAI资源请求:
curl https://xx.openai.azure.com/openai/deployments/gpt35/chat/completions\?api-version\=2023-03-15-preview \ -H "Content-Type: application/json" \ -H "api-key: xxxx" \ -d '{"messages":[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "1+1=?"}],"stream":true}'
Azure OpenAI资源响应:
这是一个流式响应,每个data
字段都是一个独立的响应块。这里只列出了一部分响应块,每个响应块都包含一个delta
字段,表示从上一个响应块到这个响应块的变化。
{ "id": "chatcmpl-7OKEqlM4l1BJzBQ2vmoWhqxZiNC8W", "object": "chat.completion.chunk", "created": 1686032024, "model": "gpt-35-turbo", "choices": [ { "index": 0, "finish_reason": null, "delta": { "role": "assistant" } }, { "index": 0, "finish_reason": null, "delta": { "content": "1" } }, { "index": 0, "finish_reason": null, "delta": { "content": "+" } }, { "index": 0, "finish_reason": null, "delta": { "content": "1" } }, { "index": 0, "finish_reason": null, "delta": { "content": "=" } }, { "index": 0, "finish_reason": null, "delta": { "content": "2" } }, { "index": 0, "finish_reason": null, "delta": { "content": "." } }, { "index": 0, "finish_reason": "stop", "delta": {} } ], "usage": null }
OpenAI API请求:
curl 'https://api.openai.com/v1/chat/completions' \ -H 'authorization: Bearer sk-xxxxx' \ --data-raw '{"model":"gpt-3.5-turbo","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"以中文解释:从难易度和waitlist"}],"stream":true}'
OpenAI API响应:
这是一个流式响应,每个data
字段都是一个独立的响应块。这里只列出了一部分响应块,每个响应块都包含一个
delta
字段,表示从上一个响应块到这个响应块的变化。
{ "id": "chatcmpl-7OK7qBT9eL6PlyDwdAl7lnnhqllDM", "object": "chat.completion.chunk", "created": 1686031590, "model": "gpt-3.5-turbo-0301", "choices": [ { "delta": { "role": "assistant" }, "index": 0, "finish_reason": null }, { "delta": { "content": "\"" }, "index": 0, "finish_reason": null }, { "delta": { "content": "从" }, "index": 0, "finish_reason": null }, { "delta": { "content": "难" }, "index": 0, "finish_reason": null }, { "delta": {}, "index": 0, "finish_reason": "stop" } ] }
现在,我们来比较这两个请求和响应的异同:
OpenAI API | Azure OpenAI资源 | |
---|---|---|
请求URL | https://api.openai.com/v1/chat/completions | https://xxx.openai.azure.com/openai/deployments/gpt35/chat/completions?api-version=2023-03-15-preview |
请求头 | 'authorization: Bearer sk-xxxx' | "api-key: xxxxx" |
请求体 | '{"model":"gpt-3.5-turbo","messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"以中文解释:从难易度和waitlist 的等"}],"stream":true}' | '{"messages":[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "1+1=?"}],"stream":true}' |
响应体 | 流式响应,每个响应块都包含一个delta 字段,表示从上一个响应块到这个响应块的变化。 |
流式响应,每个响应块都包含一个delta 字段,表示从上一个响应块到这个响应块的变化。 |
响应内容 | 返回的是分块的响应,每个块包含一个delta字段,表示从上一个响应块到这个响应块的变化。 | 返回的是分块的响应,每个块包含一个delta字段,表示从上一个响应块到这个响应块的变化。 |
总的来说,这两个请求和响应在请求URL、请求头、请求体以及响应体方面都非常相似
主要的区别在于请求的URL和请求头的认证方式。OpenAI API使用的是Bearer Token,而Azure OpenAI资源使用的是API Key。另一个区别是在请求体中,OpenAI API使用的是模型的名称,而Azure OpenAI资源使用的是部署的名称。在响应体方面,两者都使用了流式响应,这意味着你可以在模型生成输出的同时接收输出,而不需要等待模型生成完所有输出。