vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
9.93k stars 1.46k forks source link

I hope that when verifying the schema of the chunk, the object field allows for undefined #1488

Closed liuhuapiaoyuan closed 5 months ago

liuhuapiaoyuan commented 6 months ago

Feature Description

const openaiChatChunkSchema = z.object({ object: z.enum([ 'chat.completion.chunk', 'chat.completion', support for OpenAI-compatible providers such as Perplexity ]),

Because some third-party LLM are not fully standardized when they are compatible with OpenAI's interface, such as missing object, I hope this field can be selected

Use Case

No response

Additional context

No response

lgrammel commented 5 months ago

@liuhuapiaoyuan can you provide an example of a provider that does not support the object field?

liuhuapiaoyuan commented 5 months ago

For example, like Zhipu, there is no "object" field in its stream chunk. I believe this is an unnecessary validation field.

liuhuapiaoyuan commented 5 months ago
data: {"id":"8313807536837492492","created":1706092316,"model":"glm-4","choices":[{"index":0,"delta":{"role":"assistant","content":"土"}}]}
data: {"id":"8313807536837492492","created":1706092316,"model":"glm-4","choices":[{"index":0,"delta":{"role":"assistant","content":"星"}}]}

....

data: {"id":"8313807536837492492","created":1706092316,"model":"glm-4","choices":[{"index":0,"delta":{"role":"assistant","content":","}}]}
data: {"id":"8313807536837492492","created":1706092316,"model":"glm-4","choices":[{"index":0,"delta":{"role":"assistant","content":"主要由"}}]}
data: {"id":"8313807536837492492","created":1706092316,"model":"glm-4","choices":[{"index":0,"finish_reason":"length","delta":{"role":"assistant","content":""}}],"usage":{"prompt_tokens":60,"completion_tokens":100,"total_tokens":160}}
data: [DONE]
lgrammel commented 5 months ago

https://github.com/vercel/ai/pull/1702