Files
OpenCode 68a9071cf1 feat: reconcile local master with origin (exa/hot-platform hunters, leaks ledger, latest results)
Local branch had diverged from origin/master (sibling commits on the same base). Rewrote local history linearly on top of origin/master, folding in all local content: exa/hot-platform discovery hunters, leaks ledger, nightly sweep orchestrator, updated .gitignore and skill docs, plus the latest hunt output and vault state. Remote-only files (vault keys, channel scripts) were restored rather than dropped, so the resulting tree is a full union of both sides.
2026-08-07 12:53:47 +08:00

1 line
2.4 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "bobghugjkl/agentlearning", "files": {"langchain-learning/week1/day05/02_extract.py": {"37bc8a5edf2cb2ab7356d4268fa9dd9cb3b5f52f": {"t": 1786068240.7873046, "n": 1597, "h": "e7f52eb980cbad5d", "c": "import os\nfrom dotenv import load_dotenv\nfrom langchain.chat_models import init_chat_model\nfrom langchain_core.prompts import ChatPromptTemplate\nfrom pydantic import BaseModel, Field\nfrom typing import List\nfrom langchain_core.runnables import RunnableWithFallbacks\nload_dotenv()\n\nmodel = init_chat_model(\n \"deepseek-chat\",\n model_provider=\"deepseek\",\n api_key=os.getenv(\"DEEPSEEK_API_KEY\"),\n temperature=0,\n)\n\n# 定义要抽取的结构\nclass Person(BaseModel):\n name: str = Field(description=\"人物姓名\")\n role: str = Field(description=\"人物身份或职业\")\n fact: str = Field(description=\"关于这个人的一个关键事实\")\n\nclass ArticleInfo(BaseModel):\n topic: str = Field(description=\"文章主题,一句话概括\")\n persons: List[Person] = Field(description=\"文章中提到的人物列表\")\n key_takeaway: str = Field(description=\"最重要的结论,一句话\")\n\n# 构建 chain\nprompt = ChatPromptTemplate.from_messages([\n (\"system\", \"你是一个信息抽取助手,从文章中抽取结构化信息。\"),\n (\"human\", \"请从下面这段文字中抽取信息:\\n\\n{text}\"),\n])\n\nstructured_model = model.with_structured_output(ArticleInfo)\nchain = prompt | structured_model\n\n# 测试文章\narticle = \"\"\"\n乃木坂46成立于2011年,是AKB48的官方竞争对手。\n白石麻衣作为团队的顶尖成员,以超模级颜值著称,\n目前已转型为专业模特和演员。\n斋藤飞鸟是继白石麻衣之后的王牌成员,\n以清冷气质和强大的舞台表现力闻名,\n2023年从团体毕业后开始专注演员事业。\n\"\"\"\n\nresult = chain.invoke({\"text\": article})\n\nprint(f\"主题:{result.topic}\")\nprint(f\"\\n人物:\")\nfor person in result.persons:\n print(f\" - {person.name}({person.role}):{person.fact}\")\nprint(f\"\\n结论:{result.key_takeaway}\")\n\n# 加重试:失败最多重试2次\n\n\nreliable_chain = chain.with_retry(\n stop_after_attempt=3, # 最多试3次\n)\n\nresult2 = reliable_chain.invoke({\"text\": article})\nprint(f\"\\n=== 带重试的结果 ===\")\nprint(f\"主题:{result2.topic}\")"}}}}