请问哪个大模型 api 能支持输出标准严谨的 json 格式

查看 229|回复 18
varxo   
我使用文心提示返回信息“必须返回 Json 格式”, 不加必须有时候返回的就不是 json
LeslieLeung   
可以尝试给 prompt 里加上 JSON schema ,我写了一篇文章可以看看 https://ameow.xyz/archives/llm-structural-output
另外,据说 finetuning 给他几个 JSON 的例子也能让它更稳定地输出。
DjvuLee   
@matrix1010 flash 啥时候支持 JSON Mode 了?只有 pro 支持。
DjvuLee   
实测最好是是 GPT 系列,其他的都不稳定。指定 json mode 就可以。
RaftingPoint
OP
  
@varxo 我也加了,返回的 json 字符串是放在 markdown 格式里的,不知道是否和编码有关系
matrix1010   
@DjvuLee https://ai.google.dev/gemini-api/docs/json-mode?lang=python "This approach works with both Gemini 1.5 Flash and Gemini 1.5 Pro. Since the model gets the format specification from text in the prompt, you may have some flexibility in how you represent the specification. Any reasonable format for representing a JSON schema may work."
DjvuLee   
@matrix1010 我看到的是下面原文开头是这样说的。我认为的是在 model 层面可以直接指定的这种。不过可能你说的是对的,实际上 flash 可以 work 。
> In your prompt, you can ask Gemini to produce JSON-formatted output, but note that Google can't guarantee that it will produce JSON and nothing but JSON. However, if you use Gemini 1.5 Pro, you can pass a specific JSON schema in a response_schema field so that Gemini always responds with an expected structure.
> As a structured schema supplied through model configuration. This approach works with Gemini 1.5 Pro but not Gemini 1.5 Flash.
qweruiop   
最好是用 function call ,实在不行就重试,目前是这样解决的。。。
winterbells   
openai 的用过一段时间,很稳定,但还是得加校验
您需要登录后才可以回帖 登录 | 立即注册

返回顶部