api调用问题:api结构不是标准的openai兼容接口

最近在做一个AI集成工具,发现iflow的api调用时 stream输出的结构不是标准的openai兼容接口,另外输出结尾也没有[DONE]标记。然后在xcode上集成上时,xcode无法解析输出。

以下是用阿里云兼容openai的输出和iflow api输出两个对比输出。
bash aliyun-openai.sh

data: {“choices”:[{“delta”:{“content”:“”,“role”:“assistant”},“index”:0,“logprobs”:null,“finish_reason”:null}],“object”:“chat.completion.chunk”,“usage”:null,“created”:1764124490,"

system_fingerprint":null,“model”:“qwen3-max”,“id”:“chatcmpl-152e4edf-8b02-4db3-93e7-35ba6c4bef18”}

data: {“choices”:[{“finish_reason”:null,“logprobs”:null,“delta”:{“content”:“Hello”},“index”:0}],“object”:“chat.completion.chunk”,“usage”:null,“created”:1764124490,"system_fingerp

rint":null,“model”:“qwen3-max”,“id”:“chatcmpl-152e4edf-8b02-4db3-93e7-35ba6c4bef18”}

data: {“choices”:[{“delta”:{“content”:“! How can”},“finish_reason”:null,“index”:0,“logprobs”:null}],“object”:“chat.completion.chunk”,“usage”:null,“created”:1764124490,"system_fin

gerprint":null,“model”:“qwen3-max”,“id”:“chatcmpl-152e4edf-8b02-4db3-93e7-35ba6c4bef18”}

data: {“choices”:[{“delta”:{“content”:" I help"},“finish_reason”:null,“index”:0,“logprobs”:null}],“object”:“chat.completion.chunk”,“usage”:null,“created”:1764124490,"system_finge

rprint":null,“model”:“qwen3-max”,“id”:“chatcmpl-152e4edf-8b02-4db3-93e7-35ba6c4bef18”}

data: {“choices”:[{“delta”:{“content”:" you today?"},“finish_reason”:null,“index”:0,“logprobs”:null}],“object”:“chat.completion.chunk”,“usage”:null,“created”:1764124490,"system_f

ingerprint":null,“model”:“qwen3-max”,“id”:“chatcmpl-152e4edf-8b02-4db3-93e7-35ba6c4bef18”}

data: {“choices”:[{“delta”:{“content”:" 😊"},“finish_reason”:null,“index”:0,“logprobs”:null}],“object”:“chat.completion.chunk”,“usage”:null,“created”:1764124490,"system_fingerpri

nt":null,“model”:“qwen3-max”,“id”:“chatcmpl-152e4edf-8b02-4db3-93e7-35ba6c4bef18”}

data: {“choices”:[{“finish_reason”:“stop”,“delta”:{“content”:“”},“index”:0,“logprobs”:null}],“object”:“chat.completion.chunk”,“usage”:null,“created”:1764124490,"system_fingerprin

t":null,“model”:“qwen3-max”,“id”:“chatcmpl-152e4edf-8b02-4db3-93e7-35ba6c4bef18”}

data: [DONE]

(base) [root@bare test]# bash iflow.sh

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“role”:“assistant”,“content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“content”:“Hello”,“reasoning_content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“content”:“! How”,“reasoning_content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“content”:" can",“reasoning_content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“content”:" I help",“reasoning_content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“content”:" you today",“reasoning_content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“content”:“?”,“reasoning_content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”

},“choices”:[{“index”:0,“delta”:{“content”:“”}}],“model”:“tstars2.0”}

data:{“id”:“chat”,“object”:“chat.completion.chunk”,“created”:1764124495,“usage”:{“prompt_tokens”:21,“completion_tokens”:10,“total_tokens”:31,“prompt_tokens_details”:{"cached_toke

ns":29}},“extend_fields”:{“traceId”:“2104cabb17641244950146849e256e”,“requestId”:“1f93ea1932134414c701305e88116d10”},“choices”:[{“index”:0,“finish_reason”:“stop”,“delta”:{"conten

t":“”}}],“model”:“tstars2.0”}

针对openAI协议在流式输出上,有没有完整的[DONE]标记,目前我们没有拿到特别明确的结论,现在各模型厂商虽然按照openAI协议做了input/output的输出,但是不同厂商在入参和出参的结构上还是会有些许差异,比如kimi模型在流式返回上是没有[DONE]标记的。

建议使用非流式输出,或是手动去兼容一些逻辑

1 个赞