惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
A
Arctic Wolf
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threatpost
P
Proofpoint News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Vulnerabilities – Threatpost
V
V2EX
Webroot Blog
Webroot Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
T
Tor Project blog
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Vercel News
Vercel News
Security Archives - TechRepublic
Security Archives - TechRepublic
MongoDB | Blog
MongoDB | Blog
T
Troy Hunt's Blog
Google DeepMind News
Google DeepMind News
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
W
WeLiveSecurity
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
Y
Y Combinator Blog
T
Threat Research - Cisco Blogs
S
Security Affairs
Google Online Security Blog
Google Online Security Blog
S
Securelist
Spread Privacy
Spread Privacy
Recent Announcements
Recent Announcements
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
爱范儿
爱范儿
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
AWS News Blog
AWS News Blog

博客园 - ExplorerMan

大模型sft微调参数优化2 大模型RAG实战,从被骂不靠谱到成为部门MVP,这是我的踩坑全记录【转】 渐进式SFT内化 [推荐]双塔模型(介绍) Agno - 轻量级Python多智能体系统框架 Open WebUI:打造友好且强大的自托管 AI 平台 【gradio】使用Gradio快速开发前端界面:基础知识 文本切割方案进化概览:从“机械切割”到“智能解构” 大模型RAG的上下文压缩与过滤 SemanticChunker 语义相似拆分 基于LangChain 实现 Advanced RAG-后检索优化(上)-Reranker 基于LangChain 实现 Advanced RAG-后检索优化(下)-上下文压缩与过滤 多Agent协作入门:基于A2A协议的Agent通信(中) ollama部署与open-webui 0基础也能看懂!从0到1手把手教你本地部署大模型Ollama 什么是 AutoModel 大模型基础应用框架(ReACT\SFT\RAG)技术创新及零售业务落地应用 - ExplorerMan - 博客园 多模态Embedding模型:从文本到多模态的全面选型指南! rag 查询检索轮换
推荐 Prompt 模板(大幅提升 JSON 质量)
ExplorerMan · 2026-01-28 · via 博客园 - ExplorerMan

请严格按照以下要求输出:

1. 输出必须是**严格合法的 JSON**,可直接被 Python json.loads() 解析
2. 所有键和字符串值必须用**英文双引号**包围
3. 不要包含任何 JSON 之外的文本(如"```json"或解释)
4. 遵循以下 Schema:
{
"type": "object",
"properties": {
"name": {"type": "string"},
"score": {"type": "number", "minimum": 0, "maximum": 100}
},
"required": ["name", "score"]
}

现在请输出:

方案1:JSON + JSON Schema(90% 场景)

# 使用 OpenAI JSON Mode(自动保证合法性)

response = client.chat.completions.create(

    model="gpt-4o",

    messages=[{"role": "user", "content": "提取用户姓名和年龄"}],

    response_format={ "type": "json_object" },  # ← 关键!

    temperature=0.0

)

data = json.loads(response.choices[0].message.content)

方案2:JSON + 后处理校验(开源模型必备)

def safe_parse_json(text):

    # 尝试1:直接解析

    try:

        return json.loads(text)

    except:

        pass

    # 尝试2:提取首尾花括号间内容

    match = re.search(r'\{.*\}', text, re.DOTALL)

    if match:

        try:

            return json.loads(match.group())

        except:

            pass

    # 尝试3:用大模型修复

    fix_prompt = f"修复以下JSON错误,只输出合法JSON:\n{text}"

    # ... 调用模型修复

    raise ValueError("JSON 无法修复")