12 - Validation & Retry (验证和重试)核心概念验证和重试 = 确保 LLM 应用的可靠性和数据质量在生产环境中,需要处理三类问题:网络错误 - 临时性连接问题(用 with_retry())模型故障 - 主模型不可用(用 with_fallbacks())输出质量 - LLM 输出不符合要求(用验证 + 重试循环)基本用法1. wit...
Structured Output.py
# 核心概念
# Structured Output = 将 LLM 的自然语言输出转为结构化 Python 对象
# 在 LangChain 1.0 中,使用 with_structured_output() 方法结合 Pydantic 模型,可以确保 LLM 返回符合预定义模式的数据。
# 基本用法
# 定义 Pydantic 模型
from ty...
11 - Structured Output (结构化输出).md
11 - Structured Output (结构化输出)核心概念Structured Output = 将 LLM 的自然语言输出转为结构化 Python 对象在 LangChain 1.0 中,使用 with_structured_output() 方法结合 Pydantic 模型,可以确保 LLM 返回符合预定义模式的数据。基本用法定义 Pydant...
Middleware Basics -main.py
"""
LangChain 1.0 - Middleware Basics (中间件基础)
==============================================
本模块重点讲解:
1. 什么是中间件(Middleware)
2. before_model 和 after_model 钩子
3. 自定义中...
Middleware Basics.py
# Middleware(中间件)= Agent 执行过程中的钩子函数
# 在 LangChain 1.0 中,中间件是处理 Agent 生命周期的标准方式。
# 基本用法
# 创建自定义中间件
import sys
import os
from openai import chat
sys.path.append(os.path.dirname(os...