Skip to content

无法通过提示词指定JSON格式中某些字段按照固定格式输出 #125

@java-my-life

Description

@java-my-life

System Info / 系統信息

glm-ocr

Who can help? / 谁可以帮助到您?

No response

Information / 问题信息

  • The official example scripts / 官方的示例脚本
  • My own modified scripts / 我自己修改的脚本和任务

Reproduction / 复现过程

在GLM-OCR接口中提示词指定日期字段按照yyyy-MM-dd格式输出,以及金额统一使用double类型。
均无效果。
以下为原图以及请求报文:

Image

{ "model": "glm-ocr", "messages": [ { "role": "user", "content": [ { "type": "image_url", "image_url": { "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...." } }, { "type": "text", "text": "开票日期日期格式必须为yyyy-MM-dd,金额相关请输出标准double类型,请按下列JSON格式输出图中信息:{\"发票类型\":\"\",\"发票代码\":\"\",\"发票号码\":\"\",\"开票日期\":\"\",\"税前金额\":\"\",\"税额\":\"\",\"总金额\":\"\",\"发票状态\":\"\",\"购方名称\":\"\",\"购方税号\":\"\",\"购方开户行及帐户\":\"\",\"购方地址电话\":\"\",\"销售方名称\":\"\",\"销售方税号\":\"\",\"销售方开户行及帐户\":\"\",\"销售方地址电话\":\"\",\"备注\":\"\"}" } ] } ], "max_tokens": 8192 }

开票日期及金额均未按照预期结果执行
以下为输出结果:
{ "id": "chatcmpl-7d335e11-fd8f-45f0-b23d-04d0352e1698", "object": "chat.completion", "created": 1773302434, "model": "glm-ocr", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "```json\n{\n \"发票类型\": \"电子票\",\n \"发票代码\": \"1638316460899594\",\n \"发票号码\": \"5411254916\",\n \"开票日期\": \"2025年10月11日 20:02\",\n \"税前金额\": \"62,842.89\",\n \"税额\": \"16,872.21\",\n \"总金额\": \"62,842.89\",\n \"发票状态\": \"已收据\",\n \"购方名称\": \"凯图斯安卡拉科技有限公司\",\n \"购方税号\": \"\",\n \"购方开户行及帐户\": \"\",\n \"购方地址电话\": \"\",\n \"销售方名称\": \"刘焕文\",\n \"销售方税号\": \"\",\n \"销售方开户行及帐户\": \"\",\n \"销售方地址电话\": \"\"\n}\n```", "refusal": null, "annotations": null, "audio": null, "function_call": null, "tool_calls": [], "reasoning": null }, "logprobs": null, "finish_reason": "stop", "stop_reason": 59253, "token_ids": null } ], "service_tier": null, "system_fingerprint": null, "usage": { "prompt_tokens": 1771, "total_tokens": 1993, "completion_tokens": 222, "prompt_tokens_details": null }, "prompt_logprobs": null, "prompt_token_ids": null, "kv_transfer_params": null }

Expected behavior / 期待表现

开票日期 : 2025-10-11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions