PageSourceSearch

https://www.autoinfra.cn/assets/js/65fef2e1.b82c4dda.js

js autoinfra.cn collected 2026-10-03 21:16:18 UTC 10,709 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunklangchain_zh=self.webpackChunklangchain_zh||[]).push([[9446],{3905:(e,n,t)=>{t.d(n,{Zo:()=>m,kt:()=>h});var a=t(67294);function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,a)}return t}function l(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(Object(t),!0).forEach((function(n){r(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function p(e,n){if(null==e)return{};var t,a,r=function(e,n){if(null==e)return{};var t,a,r={},o=Object.keys(e);for(a=0;a<o.length;a++)t=o[a],n.indexOf(t)>=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)t=o[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var i=a.createContext({}),c=function(e){var n=a.useContext(i),t=n;return e&&(t="function"==typeof e?e(n):l(l({},n),e)),t},m=function(e){var n=c(e.components);return a.createElement(i.Provider,{value:n},e.children)},s="mdxType",u={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},d=a.forwardRef((function(e,n){var t=e.components,r=e.mdxType,o=e.originalType,i=e.parentName,m=p(e,["components","mdxType","originalType","parentName"]),s=c(t),d=r,h=s["".concat(i,".").concat(d)]||s[d]||u[d]||o;return t?a.createElement(h,l(l({ref:n},m),{},{components:t})):a.createElement(h,l({ref:n},m))}));function h(e,n){var t=arguments,r=n&&n.mdxType;if("string"==typeof e||r){var o=t.length,l=new Array(o);l[0]=d;var p={};for(var i in n)hasOwnProperty.call(n,i)&&(p[i]=n[i]);p.originalType=e,p[s]="string"==typeof e?e:r,l[1]=p;for(var c=2;c<o;c++)l[c]=t[c];return a.createElement.apply(null,l)}return a.createElement.apply(null,t)}d.displayName="MDXCreateElement"},81127:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>l,default:()=>u,frontMatter:()=>o,metadata:()=>p,toc:()=>c});var a=t(87462),r=(t(67294),t(3905));const o={sidebar_position:3},l="\u94fe Chains",p={unversionedId:"modules/chains/chains",id:"modules/chains/chains",title:"\u94fe Chains",description:"\u5728\u7b80\u5355\u5e94\u7528\u4e2d\uff0c\u5355\u72ec\u4f7f\u7528LLM\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u662f\u66f4\u590d\u6742\u7684\u5e94\u7528\u9700\u8981\u5c06LLM\u94fe\u63a5\u5728\u4e00\u8d77 - \u8981\u4e48\u4e0e\u5176\u4ed6LLM\u94fe\u63a5\u5728\u4e00\u8d77\uff0c\u8981\u4e48\u4e0e\u5176\u4ed6\u7ec4\u4ef6\u94fe\u63a5\u5728\u4e00\u8d77\u3002",source:"@site/docs/modules/chains/chains.md",sourceDirName:"modules/chains",slug:"/modules/chains/",permalink:"/docs/modules/chains/",draft:!1,tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3},sidebar:"docs",previous:{title:"\u7f51\u9875\u641c\u7d22\u68c0\u7d22\u5668 WebResearchRetriever",permalink:"/docs/modules/data_connection/retrievers/web_research"},next:{title:"\u57fa\u7840\u6982\u5ff5",permalink:"/docs/docs/modules/chains/foundational/"}},i={},c=[{value:"\u4e3a\u4ec0\u4e48\u6211\u4eec\u9700\u8981\u94fe\uff1f",id:"\u4e3a\u4ec0\u4e48\u6211\u4eec\u9700\u8981\u94fe",level:2},{value:"\u5165\u95e8",id:"\u5165\u95e8",level:2},{value:"\u4f7f\u7528<code>LLMChain</code>",id:"\u4f7f\u7528llmchain",level:4}],m={toc:c},s="wrapper";
1function u(e){let{components:n,...t}=e;return(0,r.kt)(s,(0,a.Z)({},m,t,{components:n,mdxType:"MDXLayout"}),(0,r.kt)("h1",{id:"\u94fe-chains"},"\u94fe Chains"),(0,r.kt)("p",null,"\u5728\u7b80\u5355\u5e94\u7528\u4e2d\uff0c\u5355\u72ec\u4f7f\u7528LLM\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u662f\u66f4\u590d\u6742\u7684\u5e94\u7528\u9700\u8981\u5c06LLM\u94fe\u63a5\u5728\u4e00\u8d77 - \u8981\u4e48\u4e0e\u5176\u4ed6LLM\u94fe\u63a5\u5728\u4e00\u8d77\uff0c\u8981\u4e48\u4e0e\u5176\u4ed6\u7ec4\u4ef6\u94fe\u63a5\u5728\u4e00\u8d77\u3002"),(0,r.kt)("p",null,"LangChain\u4e3a\u8fd9\u79cd\u201c\u94fe\u63a5\u201d\u5e94\u7528\u63d0\u4f9b\u4e86",(0,r.kt)("strong",{parentName:"p"},"Chain"),"\u63a5\u53e3\u3002\u6211\u4eec\u5c06\u94fe\u5b9a\u4e49\u4e3a\u4e00\u7cfb\u5217\u5bf9\u7ec4\u4ef6\u7684\u8c03\u7528\uff0c\u53ef\u4ee5\u5305\u62ec\u5176\u4ed6\u94fe\u3002\u57fa\u672c\u63a5\u53e3\u5f88\u7b80\u5355\uff1a"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-python"},'class Chain(BaseModel, ABC):  \n    """\u6240\u6709\u94fe\u90fd\u5e94\u8be5\u5b9e\u73b0\u7684\u57fa\u672c\u63a5\u53e3\u3002"""  \n    \n    memory: BaseMemory  \n    callbacks: Callbacks  \n    \n    def __call__(  \n        self,  \n        inputs: Any,  \n        return_only_outputs: bool = False,  \n        callbacks: Callbacks = None,  \n    ) -> Dict[str, Any]:  \n        ...  \n')),(0,r.kt)("p",null,"\u5c06\u7ec4\u4ef6\u7ec4\u5408\u5728\u4e00\u8d77\u5f62\u6210\u94fe\u7684\u601d\u60f3\u7b80\u5355\u800c\u5f3a\u5927\u3002\u5b83\u6781\u5927\u5730\u7b80\u5316\u4e86\u590d\u6742\u5e94\u7528\u7684\u5b9e\u73b0\uff0c\u5e76\u4f7f\u5e94\u7528\u66f4\u52a0\u6a21\u5757\u5316\uff0c\u4ece\u800c\u66f4\u5bb9\u6613\u8c03\u8bd5\u3001\u7ef4\u62a4\u548c\u6539\u8fdb\u5e94\u7528\u3002"),(0,r.kt)("p",null,"\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u67e5\u7
170b\uff1a"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"/docs/modules/chains/how_to/"},"How-to"),"\uff0c\u4e86\u89e3\u4e0d\u540c\u94fe\u7279\u6027\u7684\u6f14\u793a"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"/docs/modules/chains/foundational/"},"Foundational"),"\uff0c\u719f\u6089\u6838\u5fc3\u6784\u5efa\u5757\u94fe"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"/docs/modules/chains/document/"},"Document"),"\uff0c\u5b66\u4e60\u5982\u4f55\u5c06\u6587\u6863\u7eb3\u5165\u94fe\u4e2d"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"/docs/modules/chains/popular/"},"Popular"),"\uff0c\u5e38\u89c1\u7528\u4f8b\u7684\u94fe"),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"/docs/modules/chains/additional/"},"Additional"),"\uff0c\u67e5\u770b\u4e00\u4e9b\u66f4\u9ad8\u7ea7\u7684\u94fe\u548c\u96c6\u6210\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528")),(0,r.kt)("h2",{id:"\u4e3a\u4ec0\u4e48\u6211\u4eec\u9700\u8981\u94fe"},"\u4e3a\u4ec0\u4e48\u6211\u4eec\u9700\u8981\u94fe\uff1f"),(0,r.kt)("p",null,"\u94fe\u5141\u8bb8\u6211\u4eec\u5c06\u591a\u4e2a\u7ec4\u4ef6\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u521b\u5efa\u4e00\u4e2a\u5355\u4e00\u3001\u8fde\u8d2f\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u94fe\uff0c\u63a5\u6536\u7528\u6237\u8f93\u5165\uff0c\u4f7f\u7528PromptTemplate\u5bf9\u5176\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u7136\u540e\u5c06\u683c\u5f0f\u5316\u540e\u7684\u54cd\u5e94\u4f20\u9012\u7ed9LLM\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06\u591a\u4e2a\u94fe\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u6216\u5c06\u94fe\u4e0e\u5176\u4ed6\u7ec4\u4ef6\u7ec4\u5408\uff0c\u6784\u5efa\u66f4\u590d\u6742\u7684\u94fe\u3002"),(0,r.kt)("h2",{id:"\u5165\u95e8"},"\u5165\u95e8"),(0,r.kt)("h4",{id:"\u4f7f\u7528llmchain"},"\u4f7f\u7528",(0,r.kt)("inlineCode",{parentName:"h4"},"LLMChain")),(0,r.kt)("p",null,(0,r.kt)("inlineCode",{parentName:"p"},"LLMChain"),"\u662f\u6700\u57fa\u672c\u7684\u6784\u5efa\u5757\u94fe\u3002\u5b83\u63a5\u6536\u4e00\u4e2a\u63d0\u793a\u6a21\u677f\uff0c\u5c06\u5176\u4e0e\u7528\u6237\u8f93\u5165\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u5e76\u8fd4\u56deLLM\u7684\u54cd\u5e94\u3002"),(0,r.kt)("p",null,"\u8981\u4f7f\u7528",(0,r.kt)("inlineCode",{parentName:"p"},"LLMChain"),"\uff0c\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u63d0\u793a\u6a21\u677f\u3002"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-python"},'from langchain.llms import OpenAI  \nfrom langchain.prompts import PromptTemplate  \n\nllm = OpenAI(temperature=0.9)  \nprompt = PromptTemplate(  \n    input_variables=["product"],  \n    template="What is a good name for a company that makes {product}?",  \n)  \n')),(0,r.kt)("p",null,"\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u94fe\uff0c\u5b83\u5c06\u63a5\u6536\u7528\u6237\u8f93\u5165\uff0c\u4f7f\u7528\u63d0\u793a\u6a21\u677f\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u7136\u540e\u5c06\u5176\u53d1\u9001\u7ed9LLM\u3002"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-python"},'from langchain.chains import LLMChain  \nchain = LLMChain(llm=llm, prompt=prompt)  \n\n# \u4ec5\u6307\u5b9a\u8f93\u5165\u53d8\u91cf\u8fd0\u884c\u94fe\u3002\nprint(chain.run("colorful socks"))  \n')),(0,r.kt)("p",null,"\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"Colorful Toes Co.\n")),(0,r.kt)("p",null,"\u5982\u679c\u6709\u591a\u4e2a\u53d8\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u5178\u4e00\u6b21\u6027\u8f93\u5165\u5b83\u4eec\u3002"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-python"},'prompt = PromptTemplate(  \n    input_variables=["company", "product"],  \n    template="What is a good name for {company} that makes {product}?",  \n)  \nchain = LLMChain(llm=llm, prompt=prompt)  \nprint(chain.run({  \n    \'company\': "ABC Startup",  \n    \'product\': "colorful socks"  \n}))  \n')),(0,r.kt)("p",null,"\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"Socktopia Colourful Creations.\n")),(0,r.kt)("p",null,"\u60a8\u8fd8\u53ef\u4ee5\u5728",(0,r.kt)("inlineCode",{parentName:"p"},"LLMChain"),"\u4e2d\u4f7f\u7528\u804a\u5929\u6a21\u578b\uff1a"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-python"},'from langchain.chat_models import ChatOpenAI  \nfrom langchain.prompts.chat import (  \n    ChatPromptTemplate,  \n    HumanMessagePromptTemplate,  \n)  \nhuman_message_prompt = HumanMessagePromptTemplate(  \n        prompt=PromptTemplate(  \n            template="What is a good name for a company that makes {product}?",  \n            input_variables=["product"],  \n        )  \n    )  \nchat_prompt_template = ChatPromptTemplate.from_messages([human_message_prompt])  \nchat = ChatOpenAI(temperature=0.9)  \nchain = LLMChain(llm=chat, prompt=chat_prompt_template)  \nprint(chain.run("colorful socks"))  \n')),(0,r.kt)("p",null,"\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"Rainbow Socks Co.\n")))}u.isMDXComponent=!0}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.