14 条回复  ·  1580 次点击
iyaozhen 初学 2025-8-14 13:13:47
@maemual +1 火山上的 deepseek 、doubao 都支持,kimi-k2 也在支持的路上了
iyaozhen 初学 2025-8-14 13:20:52
@neteroster #9 我理解不是给一个 schema 让模型去生成一个 json 再修语法。而是使用已有的数据(非 json 的 output ),往 schema 上填。 因为按火山引擎的文档以及 openai 的文档,有提到“结合结构化信息写业务内容,而不是格式引导” https://i.imgur.com/7Q7I1tI.png 当然我对模型训练不了解。但工程经验来看,用 json schema 就不要想着你的 prompt 要输出 json ,更多是关注自己的业务逻辑,输出更有条理、结构化
neteroster 小成 2025-8-14 13:58:36
@iyaozhen > 不是给一个 schema 让模型去生成一个 json 再修语法。而是使用已有的数据(非 json 的 output ),往 schema 上填。 可以很明确的说并不是这样的,各大开源推理引擎都有相关实现可以参考。 --- 来具体捋一下: guided decode 可以确保模型生成的内容满足 json schema (前提是生成会终止),但是“让模型知道我要按某个 schema 输出 json” 是提示词(或者说上下文)做的事。 有的厂商,例如 OpenAI 和火山,他会告诉你:你直接在参数里给我传 schema 就行了,prompt 里不用说我要这个 json ,关注业务就好。这里,它们实际做的事是:在你的 prompt 后面或者在系统提示词里,按一定格式(可能有针对训练固定格式,也可能是直接拼接 prompt )告诉模型:下面这个是 schema ,你要按照这个生成,最后在 decode 时候由采样器强制规范,完成整个过程。实际上输入给模型的大多是这样的东西(示意) <|user|>{你的 prompt} <|output_format|>JSON: {schema} <|assistant> 也可以参考 OpenAI 最近的开源模型,它的聊天模板里明确说了 Structured output To control the output behavior of the model, you can define a response format at the end of the developer message with the following structure: ``` # Response Formats ## {format name} // {description or context} {schema}<|end|> ``` 是加在系统提示里面的。最后结合推理引擎的 guided decode 生成。
liuzhedash 小成 2025-8-14 14:31:26
@musi 差不多,现在的大模型不能百分之百保证返回的 schema 符合指令,所以必须检查返回内容
wx497657341 初学 2025-8-14 14:45:38
我们有一个后端将图片给 google ocr 获取图片文本内容,然后将文本内容给 deepseek 提取程序可用的 json 数据。运行良好 $response = $client->post($url, [ 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => "Bearer {$token}", ], 'timeout' => 30, 'json' => [ 'model' => 'deepseek-chat', 'messages' => [ [ 'role' => 'system', 'content' => 'You are a Singapore vocational skills certificate expert and PHP developer. Your task is to extract key information about the certificate from the given text and return it in JSON format. so long as recipient.id 、recipient.name 、competency.code 、competency.description 、date_issued 、certificate_number field', ], [ 'role' => 'user', 'content' => $this->text, ], ], ], ]);
12
返回顶部