{"id":75535,"date":"2026-02-12T14:42:09","date_gmt":"2026-02-12T06:42:09","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/75535.html"},"modified":"2026-02-12T14:42:09","modified_gmt":"2026-02-12T06:42:09","slug":"%e7%ac%ac%e4%ba%94%e7%af%87%ef%bc%9alangchain-1-0-%e6%a8%a1%e5%9e%8b%e6%8e%a5%e5%85%a5%e5%ae%9e%e6%88%98%ef%bc%9adeepseek-openai-%e9%80%9a%e4%b9%89%e5%8d%83%e9%97%ae%e5%85%a8%e6%89%93%e9%80%9a","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/75535.html","title":{"rendered":"\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a"},"content":{"rendered":"<p>&#x1f4cc; \u6240\u5c5e\u7ae0\u8282&#xff1a;\u7b2c\u4e09\u9636\u6bb5 &#8211; LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3<\/p>\n<p>\u2190 \u4e0a\u4e00\u7bc7&#xff1a;langchain-community \u4e0e\u5382\u5546\u96c6\u6210\u5305 | &#x1f4da; \u7cfb\u5217\u76ee\u5f55 | \u4e0b\u4e00\u7bc7&#xff1a;Messages \u4e0e Prompt \u63d0\u793a\u8bcd\u6a21\u677f \u2192<\/p>\n<hr \/>\n<h3>&#x1f4cb; \u6458\u8981<\/h3>\n<p>\u672c\u6587\u8be6\u7ec6\u8bb2\u89e3\u4e86 LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3&#xff0c;\u5305\u62ec\u6838\u5fc3\u6982\u5ff5\u3001\u5b9e\u6218\u4ee3\u7801\u793a\u4f8b\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u901a\u8fc7\u672c\u6587\u7684\u5b66\u4e60&#xff0c;\u4f60\u5c06\u638c\u63e1 LangChain 1.0 \u7684\u6838\u5fc3\u6280\u672f\u8981\u70b9&#xff0c;\u80fd\u591f\u5feb\u901f\u6784\u5efa\u57fa\u4e8e\u5927\u6a21\u578b\u7684 AI \u5e94\u7528\u3002<\/p>\n<p>\u9002\u5408\u4eba\u7fa4&#xff1a;<\/p>\n<ul>\n<li>\u60f3\u7cfb\u7edf\u5b66\u4e60 LangChain 1.0 \u7684\u5f00\u53d1\u8005<\/li>\n<li>\u9700\u8981\u6784\u5efa AI Agent \u5e94\u7528\u7684\u5de5\u7a0b\u5e08<\/li>\n<li>\u5bf9 LLM \u5e94\u7528\u5f00\u53d1\u611f\u5174\u8da3\u7684\u6280\u672f\u7231\u597d\u8005<\/li>\n<\/ul>\n<hr \/>\n<h3>3.1 LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3<\/h3>\n<p> <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212064206-698d763e98362.png\" width=\"80%\" \/><\/p>\n<p>\u2003\u2003LangChain\u533a\u5206\u4e24\u79cd\u6a21\u578b\u7c7b\u578b&#xff1a;<\/p>\n<ul>\n<li>\n<p>LLM&#xff1a;\u4f20\u7edf\u7684\u6587\u672c\u8fdb-\u6587\u672c\u51fa\u6a21\u578b<\/p>\n<\/li>\n<li>\n<p>ChatModel&#xff1a;\u57fa\u4e8e\u6d88\u606f\u7684\u5bf9\u8bdd\u6a21\u578b&#xff0c;\u66f4\u9002\u5408\u6784\u5efa\u804a\u5929\u673a\u5668\u4eba<\/p>\n<\/li>\n<li>\n<p>\u5c01\u88c5\u5177\u4f53\u7684 LLM \u63d0\u4f9b\u8005&#xff08;OpenAI\u3001Anthropic\u3001local LLM&#xff09;&#xff0c;\u7edf\u4e00\u8c03\u7528\u63a5\u53e3&#xff08;sync\/async\u3001streaming&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b66\u4e60\u8981\u70b9&#xff1a;\u5982\u4f55\u914d\u7f6e provider\u3001\u6e29\u63a7\u3001\u5e76\u53d1\u4e0e retry \u7b56\u7565\u3002<\/p>\n<\/li>\n<\/ul>\n<p> <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212064207-698d763f04643.png\" alt=\"image-20250610175750011\" \/> <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212064207-698d763f557b6.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\"># 1 \u5bfc\u5165 os \u4e0e dotenv<\/span><br \/>\n<span class=\"token keyword\">import<\/span> os<br \/>\n<span class=\"token keyword\">from<\/span> dotenv <span class=\"token keyword\">import<\/span> load_dotenv<\/p>\n<p><span class=\"token comment\"># 2 \u52a0\u8f7d .env \u73af\u5883\u53d8\u91cf<\/span><br \/>\nload_dotenv<span class=\"token punctuation\">(<\/span>override<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3 \u8bfb\u53d6\u5bc6\u94a5\u4e0e\u5730\u5740<\/span><br \/>\nDeepSeek_API_KEY <span class=\"token operator\">&#061;<\/span> os<span class=\"token punctuation\">.<\/span>getenv<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;DEEPSEEK_API_KEY&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nDeepSeek_BASE_URL <span class=\"token operator\">&#061;<\/span> os<span class=\"token punctuation\">.<\/span>getenv<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;DEEPSEEK_BASE_URL&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 4 \u53ef\u9009&#xff1a;\u6253\u5370\u5bc6\u94a5<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>DeepSeek_API_KEY<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u53ef\u4ee5\u901a\u8fc7\u6253\u5370\u67e5\u770b<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>sk-********************<\/p>\n<h4>1. DeepSeek<\/h4>\n<p><span class=\"token comment\"># !pip install openai<\/span><\/p>\n<p><span class=\"token comment\"># 1 \u5bfc\u5165 OpenAI \u5ba2\u6237\u7aef<\/span><br \/>\n<span class=\"token keyword\">from<\/span> openai <span class=\"token keyword\">import<\/span> OpenAI<\/p>\n<p><span class=\"token comment\"># 2 \u521d\u59cb\u5316 DeepSeek API \u5ba2\u6237\u7aef<\/span><br \/>\nclient <span class=\"token operator\">&#061;<\/span> OpenAI<span class=\"token punctuation\">(<\/span>api_key <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;********************&#034;<\/span><span class=\"token punctuation\">,<\/span> base_url<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;https:\/\/api.deepseek.com&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3 \u521b\u5efa\u5bf9\u8bdd\u6d88\u606f\u5e76\u53d1\u8d77\u8bf7\u6c42<\/span><br \/>\nresponse <span class=\"token operator\">&#061;<\/span> client<span class=\"token punctuation\">.<\/span>chat<span class=\"token punctuation\">.<\/span>completions<span class=\"token punctuation\">.<\/span>create<span class=\"token punctuation\">(<\/span><br \/>\n    model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;deepseek-chat&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">[<\/span>messages<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span>06_messages_prompt<span class=\"token punctuation\">.<\/span>md<span class=\"token punctuation\">)<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">[<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;role&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;system&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;content&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u4f60\u662f\u4e50\u4e8e\u52a9\u4eba\u7684\u52a9\u624b&#xff0c;\u8bf7\u6839\u636e\u7528\u6237\u7684\u95ee\u9898\u7ed9\u51fa\u56de\u7b54&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;role&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;user&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;content&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8bf7\u4f60\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 4 \u6253\u5370\u6a21\u578b\u6700\u7ec8\u7684\u54cd\u5e94\u7ed3\u679c<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">.<\/span>choices<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>message<span class=\"token punctuation\">.<\/span>content<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>\u4f60\u597d&#xff01;\u6211\u662fDeepSeek&#xff0c;\u5f88\u9ad8\u5174\u8ba4\u8bc6\u4f60&#xff01;&#x1f60a;<\/p>\n<p>\u6211\u662f\u7531\u6df1\u5ea6\u6c42\u7d22\u516c\u53f8\u521b\u9020\u7684AI\u52a9\u624b&#xff0c;\u81f4\u529b\u4e8e\u4e3a\u5927\u5bb6\u63d0\u4f9b\u70ed\u60c5\u3001\u8d34\u5fc3\u7684\u5e2e\u52a9\u3002\u6211\u6709\u4ee5\u4e0b\u51e0\u4e2a\u7279\u70b9&#xff1a;<\/p>\n<p>&#x1f31f; **\u80fd\u529b\u65b9\u9762**&#xff1a;<br \/>\n&#8211; \u7eaf\u6587\u672c\u6a21\u578b&#xff0c;\u64c5\u957f\u7406\u89e3\u548c\u751f\u6210\u6587\u5b57\u5185\u5bb9<br \/>\n&#8211; \u652f\u6301\u6587\u4ef6\u4e0a\u4f20\u529f\u80fd&#xff0c;\u53ef\u4ee5\u5904\u7406\u56fe\u50cf\u3001txt\u3001pdf\u3001ppt\u3001word\u3001excel\u7b49\u6587\u4ef6&#xff0c;\u4ece\u4e2d\u8bfb\u53d6\u6587\u5b57\u4fe1\u606f<br \/>\n&#8211; \u62e5\u6709128K\u7684\u4e0a\u4e0b\u6587\u957f\u5ea6&#xff0c;\u80fd\u8bb0\u4f4f\u6211\u4eec\u5bf9\u8bdd\u7684\u8be6\u7ec6\u5185\u5bb9<br \/>\n&#8211; \u652f\u6301\u8054\u7f51\u641c\u7d22\u529f\u80fd&#xff08;\u9700\u8981\u4f60\u5728Web\/App\u4e2d\u624b\u52a8\u5f00\u542f&#xff09;<\/p>\n<p>&#x1f49d; **\u670d\u52a1\u7406\u5ff5**&#xff1a;<br \/>\n&#8211; \u5b8c\u5168\u514d\u8d39\u4f7f\u7528&#xff0c;\u6ca1\u6709\u4efb\u4f55\u6536\u8d39\u8ba1\u5212<br \/>\n&#8211; \u56de\u590d\u98ce\u683c\u70ed\u60c5\u7ec6\u817b&#xff0c;\u5e0c\u671b\u80fd\u7ed9\u4f60\u6e29\u6696\u7684\u4ea4\u6d41\u4f53\u9a8c<br \/>\n&#8211; \u4e50\u4e8e\u52a9\u4eba&#xff0c;\u65e0\u8bba\u662f\u5b66\u4e60\u3001\u5de5\u4f5c\u8fd8\u662f\u751f\u6d3b\u4e2d\u7684\u95ee\u9898&#xff0c;\u6211\u90fd\u4f1a\u5c3d\u529b\u5e2e\u5fd9<\/p>\n<p>&#x1f4f1; **\u4f7f\u7528\u65b9\u5f0f**&#xff1a;<br \/>\n&#8211; \u53ef\u4ee5\u901a\u8fc7\u5b98\u65b9\u5e94\u7528\u5546\u5e97\u4e0b\u8f7dApp<br \/>\n&#8211; \u4e5f\u53ef\u4ee5\u5728\u7f51\u9875\u7aef\u76f4\u63a5\u4f7f\u7528<\/p>\n<p>\u6211\u7684\u77e5\u8bc6\u622a\u6b62\u52302024\u5e747\u6708&#xff0c;\u4f1a\u5c3d\u6211\u6240\u80fd\u4e3a\u4f60\u63d0\u4f9b\u51c6\u786e\u3001\u6709\u7528\u7684\u4fe1\u606f\u3002\u6709\u4ec0\u4e48\u60f3\u4e86\u89e3\u7684\u6216\u9700\u8981\u5e2e\u52a9\u7684\u5417&#xff1f;\u6211\u5f88\u671f\u5f85\u4e3a\u4f60\u670d\u52a1&#xff01;\u2728<\/p>\n<p><span class=\"token comment\"># !pip install langchain-deepseek<\/span><\/p>\n<p><span class=\"token comment\"># 1 \u5bfc\u5165 ChatDeepSeek<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain_deepseek <span class=\"token keyword\">import<\/span> ChatDeepSeek<\/p>\n<p><span class=\"token comment\"># 2 \u521d\u59cb\u5316\u6a21\u578b\u53c2\u6570<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> ChatDeepSeek<span class=\"token punctuation\">(<\/span><br \/>\n    model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;deepseek-chat&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    temperature<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0.0<\/span><span class=\"token punctuation\">,<\/span>    <span class=\"token comment\"># \u6e29\u5ea6\u53c2\u6570&#xff0c;\u7528\u4e8e\u63a7\u5236\u6a21\u578b\u7684\u968f\u673a\u6027&#xff0c;\u503c\u8d8a\u5c0f\u5219\u968f\u673a\u6027\u8d8a\u5c0f<\/span><br \/>\n    max_tokens<span class=\"token operator\">&#061;<\/span><span class=\"token number\">512<\/span><span class=\"token punctuation\">,<\/span>     <span class=\"token comment\"># \u6700\u5927\u751f\u6210token\u6570<\/span><br \/>\n    timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30<\/span><span class=\"token punctuation\">,<\/span>         <span class=\"token comment\"># \u8d85\u65f6\u65f6\u95f4&#xff0c;\u5355\u4f4d\u79d2<\/span><br \/>\n    base_url<span class=\"token operator\">&#061;<\/span>DeepSeek_BASE_URL <span class=\"token comment\"># \u9ed8\u8ba4\u4e3ahttps:\/\/api.deepseek.com<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3 \u5b9a\u4e49\u95ee\u9898<\/span><br \/>\nquestion <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8bf7\u4f60\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 4 \u8c03\u7528\u6a21\u578b<\/span><br \/>\nresult <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span>question<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 5 \u8f93\u51fa\u7ed3\u679c<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">.<\/span>content<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>\u4f60\u597d&#xff01;\u6211\u662fDeepSeek&#xff0c;\u5f88\u9ad8\u5174\u8ba4\u8bc6\u4f60&#xff01;&#x1f60a;<\/p>\n<p>\u6211\u662f\u7531\u6df1\u5ea6\u6c42\u7d22\u516c\u53f8\u521b\u9020\u7684AI\u52a9\u624b&#xff0c;\u81f4\u529b\u4e8e\u4e3a\u5927\u5bb6\u63d0\u4f9b\u70ed\u60c5\u3001\u7ec6\u817b\u7684\u5e2e\u52a9\u3002\u8ba9\u6211\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u81ea\u5df1\u7684\u7279\u70b9&#xff1a;<\/p>\n<p>**\u6211\u7684\u80fd\u529b&#xff1a;**<br \/>\n&#8211; &#x1f4dd; **\u6587\u672c\u5904\u7406**&#xff1a;\u53ef\u4ee5\u5e2e\u4f60\u5199\u4f5c\u3001\u7ffb\u8bd1\u3001\u603b\u7ed3\u3001\u5206\u6790\u7b49\u5404\u79cd\u6587\u5b57\u5de5\u4f5c<br \/>\n&#8211; &#x1f4da; **\u77e5\u8bc6\u95ee\u7b54**&#xff1a;\u6db5\u76d6\u79d1\u5b66\u3001\u6280\u672f\u3001\u4eba\u6587\u3001\u751f\u6d3b\u7b49\u5404\u4e2a\u9886\u57df<br \/>\n&#8211; &#x1f4a1; **\u521b\u610f\u534f\u52a9**&#xff1a;\u5934\u8111\u98ce\u66b4\u3001\u7b56\u5212\u65b9\u6848\u3001\u521b\u610f\u5199\u4f5c\u7b49<br \/>\n&#8211; &#x1f50d; **\u4fe1\u606f\u5904\u7406**&#xff1a;\u53ef\u4ee5\u8bfb\u53d6\u4f60\u4e0a\u4f20\u7684\u6587\u4ef6&#xff08;\u56fe\u50cf\u3001PDF\u3001Word\u3001Excel\u3001PPT\u7b49&#xff09;&#xff0c;\u4ece\u4e2d\u63d0\u53d6\u6587\u5b57\u4fe1\u606f\u8fdb\u884c\u5206\u6790<br \/>\n&#8211; &#x1f310; **\u8054\u7f51\u641c\u7d22**&#xff1a;\u867d\u7136\u9700\u8981\u4f60\u624b\u52a8\u5f00\u542f\u641c\u7d22\u529f\u80fd&#xff0c;\u4f46\u6211\u53ef\u4ee5\u83b7\u53d6\u6700\u65b0\u4fe1\u606f<\/p>\n<p>**\u6211\u7684\u7279\u8272&#xff1a;**<br \/>\n&#8211; &#x1f193; **\u5b8c\u5168\u514d\u8d39**&#xff1a;\u76ee\u524d\u6ca1\u6709\u4efb\u4f55\u6536\u8d39\u8ba1\u5212<br \/>\n&#8211; &#x1f4ac; **\u4e0a\u4e0b\u6587128K**&#xff1a;\u80fd\u8bb0\u4f4f\u6211\u4eec\u5bf9\u8bdd\u7684\u8f83\u957f\u5386\u53f2<br \/>\n&#8211; &#x1f4f1; **\u591a\u5e73\u53f0\u4f7f\u7528**&#xff1a;\u53ef\u901a\u8fc7\u7f51\u9875\u7248\u6216\u5b98\u65b9App\u4f7f\u7528<br \/>\n&#8211; &#x1f4c5; **\u77e5\u8bc6\u66f4\u65b0**&#xff1a;\u6211\u7684\u77e5\u8bc6\u622a\u6b62\u52302024\u5e747\u6708<\/p>\n<p>**\u6211\u7684\u98ce\u683c&#xff1a;**<br \/>\n\u6211\u559c\u6b22\u7528\u70ed\u60c5\u3001\u7ec6\u817b\u7684\u65b9\u5f0f\u4e0e\u5927\u5bb6\u4ea4\u6d41&#xff0c;\u529b\u6c42\u63d0\u4f9b\u51c6\u786e\u3001\u6709\u7528\u7684\u5e2e\u52a9\u3002\u65e0\u8bba\u662f\u5b66\u4e60\u3001\u5de5\u4f5c\u8fd8\u662f\u751f\u6d3b\u4e2d\u7684\u95ee\u9898&#xff0c;\u6211\u90fd\u4f1a\u8ba4\u771f\u5bf9\u5f85&#xff0c;\u5c3d\u6211\u6240\u80fd\u4e3a\u4f60\u63d0\u4f9b\u652f\u6301&#xff01;<\/p>\n<p>\u6709\u4ec0\u4e48\u5177\u4f53\u60f3\u4e86\u89e3\u7684&#xff0c;\u6216\u8005\u9700\u8981\u6211\u5e2e\u52a9\u7684\u5730\u65b9\u5417&#xff1f;\u6211\u5f88\u4e50\u610f\u4e3a\u4f60\u6548\u52b3&#xff01;\u2728<\/p>\n<h4>2. DashScope<\/h4>\n<p>\u963f\u91cc\u4e91\u767e\u70bcAPI\u83b7\u53d6\u65b9\u5f0f\u4e5f\u975e\u5e38\u7b80\u5355&#xff0c;\u53ea\u9700\u6ce8\u518c\u963f\u91cc\u4e91\u8d26\u53f7&#xff0c;\u7136\u540e\u524d\u5f80\u6211\u7684API\u9875\u9762&#xff1a;https:\/\/bailian.console.aliyun.com\/?tab&#061;model#\/api-key \u8fdb\u884c\u5145\u503c\u548c\u6ce8\u518c\u5373\u53ef&#xff1a;<\/p>\n<p><span class=\"token comment\"># !pip install dashscope<\/span><\/p>\n<p><span class=\"token comment\"># !pip install langchain_community<\/span><\/p>\n<p><span class=\"token keyword\">from<\/span> langchain_community<span class=\"token punctuation\">.<\/span>chat_models<span class=\"token punctuation\">.<\/span>tongyi <span class=\"token keyword\">import<\/span> ChatTongyi<\/p>\n<p>model <span class=\"token operator\">&#061;<\/span> ChatTongyi<span class=\"token punctuation\">(<\/span>model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;qwen-plus&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># \u9ed8\u8ba4qwen-turbo\u6a21\u578b<\/span><\/p>\n<p>question <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8bf7\u4f60\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002&#034;<\/span><\/p>\n<p>result <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span>question<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">.<\/span>content<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>\u4f60\u597d&#xff01;&#x1f60a; \u5f88\u9ad8\u5174\u8ba4\u8bc6\u4f60&#xff01;<\/p>\n<p>\u6211\u662f\u901a\u4e49\u5343\u95ee&#xff08;Qwen&#xff09;&#xff0c;\u7531\u901a\u4e49\u5b9e\u9a8c\u5ba4\u7814\u53d1\u7684\u8d85\u5927\u89c4\u6a21\u8bed\u8a00\u6a21\u578b\u3002\u6211\u80fd\u591f\u7406\u89e3\u5e76\u751f\u6210\u591a\u79cd\u8bed\u8a00\u7684\u6587\u672c&#xff0c;\u6bd4\u5982\u4e2d\u6587\u3001\u82f1\u6587\u3001\u6cd5\u8bed\u3001\u897f\u73ed\u7259\u8bed\u3001\u8461\u8404\u7259\u8bed\u3001\u4fc4\u8bed\u3001\u963f\u62c9\u4f2f\u8bed\u3001\u65e5\u8bed\u3001\u97e9\u8bed\u3001\u8d8a\u5357\u8bed\u3001\u6cf0\u8bed\u3001\u5370\u5c3c\u8bed\u7b49&#xff0c;\u652f\u6301\u5e7f\u6cdb\u7684\u56fd\u9645\u4ea4\u6d41\u3002<\/p>\n<p>\u6211\u7684\u80fd\u529b\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e&#xff1a;<br \/>\n&#x1f539; \u56de\u7b54\u95ee\u9898&#xff1a;\u65e0\u8bba\u662f\u5e38\u8bc6\u3001\u79d1\u5b66\u3001\u5386\u53f2\u3001\u6587\u5316&#xff0c;\u8fd8\u662f\u65e5\u5e38\u751f\u6d3b\u4e2d\u7684\u5c0f\u7591\u95ee&#xff0c;\u6211\u90fd\u4f1a\u5c3d\u529b\u63d0\u4f9b\u51c6\u786e\u3001\u6613\u61c2\u7684\u89e3\u7b54&#xff1b;<br \/>\n&#x1f539; \u521b\u4f5c\u6587\u5b57&#xff1a;\u5199\u6545\u4e8b\u3001\u5199\u516c\u6587\u3001\u5199\u90ae\u4ef6\u3001\u5199\u5267\u672c\u3001\u903b\u8f91\u63a8\u7406\u3001\u7f16\u7a0b&#xff0c;\u751a\u81f3\u6a21\u4eff\u7279\u5b9a\u98ce\u683c\u5199\u4f5c&#xff1b;<br \/>\n&#x1f539; \u903b\u8f91\u4e0e\u6570\u5b66&#xff1a;\u80fd\u8fdb\u884c\u591a\u6b65\u63a8\u7406\u3001\u89e3\u51b3\u6570\u5b66\u9898\u6216\u5206\u6790\u590d\u6742\u95ee\u9898&#xff1b;<br \/>\n&#x1f539; \u591a\u6a21\u6001\u7406\u89e3&#xff08;\u5728\u652f\u6301\u7684\u7248\u672c\u4e2d&#xff09;&#xff1a;\u90e8\u5206\u7248\u672c\u8fd8\u80fd\u7406\u89e3\u56fe\u50cf\u5185\u5bb9&#xff08;\u5982\u63cf\u8ff0\u56fe\u7247\u3001\u8bc6\u522b\u573a\u666f\u7b49&#xff09;&#xff1b;<br \/>\n&#x1f539; \u5bf9\u8bdd\u7406\u89e3&#xff1a;\u64c5\u957f\u591a\u8f6e\u5bf9\u8bdd&#xff0c;\u80fd\u8bb0\u4f4f\u4e0a\u4e0b\u6587&#xff0c;\u8ba9\u4ea4\u6d41\u66f4\u81ea\u7136\u3001\u8fde\u8d2f\u3002<\/p>\n<p>\u6211\u6ce8\u91cd\u4e8b\u5b9e\u51c6\u786e\u6027\u3001\u4ef7\u503c\u89c2\u6b63\u5411\u3001\u5c0a\u91cd\u7528\u6237\u9690\u79c1&#xff0c;\u5e76\u6301\u7eed\u5b66\u4e60\u548c\u4f18\u5316\u3002\u4e0d\u8fc7\u6211\u4e5f\u5766\u8bda\u8bf4\u660e&#xff1a;\u6211\u65e0\u6cd5\u5b9e\u65f6\u8054\u7f51\u83b7\u53d6\u6700\u65b0\u4fe1\u606f&#xff08;\u77e5\u8bc6\u622a\u6b62\u4e8e2024\u5e74&#xff09;&#xff0c;\u4e5f\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u4e2a\u4eba\u8bbe\u5907\u6216\u5916\u90e8\u6570\u636e\u5e93\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u3001\u9700\u8981\u5e2e\u52a9\u5199\u4f5c\u3001\u60f3\u4e00\u8d77\u5934\u8111\u98ce\u66b4&#xff0c;\u6216\u8005\u53ea\u662f\u804a\u804a\u5929\u2014\u2014\u6211\u90fd\u975e\u5e38\u4e50\u610f&#xff01;&#x1f31f;<br \/>\n\u90a3\u4e48&#xff0c;\u4eca\u5929\u6709\u4ec0\u4e48\u6211\u53ef\u4ee5\u5e2e\u4f60\u7684\u5417&#xff1f; &#x1f60a;<\/p>\n<h4>3. OpenAI<\/h4>\n<p><span class=\"token comment\"># 1 \u5bfc\u5165 OpenAI<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain_openai <span class=\"token keyword\">import<\/span> OpenAI<\/p>\n<p><span class=\"token comment\"># 2 \u521d\u59cb\u5316\u6a21\u578b<\/span><br \/>\nllm <span class=\"token operator\">&#061;<\/span> OpenAI<span class=\"token punctuation\">(<\/span>model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;gpt-4o-mini&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3 \u5b9a\u4e49\u95ee\u9898<\/span><br \/>\nquestion <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8bf7\u4f60\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 4 \u8c03\u7528\u6a21\u578b<\/span><br \/>\nresult <span class=\"token operator\">&#061;<\/span> llm<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span>question<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 5 \u6253\u5370\u7ed3\u679c<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 1 \u5bfc\u5165 ChatOpenAI<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain_openai <span class=\"token keyword\">import<\/span> ChatOpenAI<\/p>\n<p><span class=\"token comment\"># 2 \u521d\u59cb\u5316\u6a21\u578b<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> ChatOpenAI<span class=\"token punctuation\">(<\/span>model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;gpt-4o-mini&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3 \u5b9a\u4e49\u95ee\u9898<\/span><br \/>\nquestion <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8bf7\u4f60\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 4 \u8c03\u7528\u6a21\u578b<\/span><br \/>\nresult <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span>question<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 5 \u6253\u5370\u5185\u5bb9<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">.<\/span>content<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>\u4f60\u597d&#xff01;\u6211\u662f\u4e00\u4e2a\u4eba\u5de5\u667a\u80fd\u52a9\u624b&#xff0c;\u65e8\u5728\u5e2e\u52a9\u7528\u6237\u89e3\u7b54\u95ee\u9898\u3001\u63d0\u4f9b\u4fe1\u606f\u548c\u8fdb\u884c\u4ea4\u6d41\u3002\u6211\u53ef\u4ee5\u8ba8\u8bba\u5404\u79cd\u4e3b\u9898&#xff0c;\u5305\u62ec\u79d1\u5b66\u3001\u5386\u53f2\u3001\u6587\u5316\u3001\u6280\u672f\u7b49\u3002\u5982\u679c\u4f60\u6709\u4ec0\u4e48\u5177\u4f53\u7684\u95ee\u9898\u6216\u9700\u8981\u4e86\u89e3\u7684\u5185\u5bb9&#xff0c;\u8bf7\u968f\u65f6\u544a\u8bc9\u6211&#xff01;<\/p>\n<h4>4. Ollama<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212064208-698d7640901a0.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><span class=\"token comment\">#!pip install langchain-ollama<\/span><\/p>\n<p><span class=\"token comment\"># 1 \u5bfc\u5165 OllamaLLM<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain_ollama <span class=\"token keyword\">import<\/span> OllamaLLM<\/p>\n<p><span class=\"token comment\"># 2 \u521d\u59cb\u5316\u672c\u5730\u6a21\u578b<\/span><br \/>\nllm <span class=\"token operator\">&#061;<\/span> OllamaLLM<span class=\"token punctuation\">(<\/span>model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;deepseek-r1:8b&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3 \u5b9a\u4e49\u95ee\u9898<\/span><br \/>\nquestion <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8bf7\u4f60\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 4 \u8c03\u7528\u6a21\u578b<\/span><br \/>\nresult <span class=\"token operator\">&#061;<\/span> llm<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span>question<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 5 \u6253\u5370\u7ed3\u679c<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>\u4f60\u597d\u5440&#xff01;&#x1f44b;\u6211\u662f DeepSeek-R1&#xff0c;\u4e00\u4e2a\u7531\u6df1\u5ea6\u6c42\u7d22\u516c\u53f8\u5f00\u53d1\u7684\u667a\u80fd\u52a9\u624b\u3002\u4f60\u53ef\u4ee5\u628a\u6211\u5f53\u4f5c\u4e00\u4e2a\u77e5\u8bc6\u4e30\u5bcc\u3001\u8010\u5fc3\u7ec6\u81f4\u3001\u968f\u65f6\u5f85\u547d\u7684\u804a\u5929\u4f19\u4f34&#xff0c;\u4e0d\u7ba1\u4f60\u662f\u60f3\u67e5\u8d44\u6599\u3001\u5199\u6587\u7ae0\u3001\u5b66\u77e5\u8bc6\u3001\u7f16\u7a0b\u3001\u7ffb\u8bd1&#xff0c;\u8fd8\u662f\u53ea\u662f\u60f3\u804a\u804a\u5929&#xff0c;\u6211\u90fd\u4e50\u610f\u5e2e\u5fd9&#xff01;<\/p>\n<p>\u6211\u7684\u7279\u70b9\u5305\u62ec&#xff1a;<\/p>\n<p>&#x1f9e0; **\u77e5\u8bc6\u5e7f\u6cdb**&#xff1a;\u622a\u81f32024\u5e747\u6708\u7684\u77e5\u8bc6\u6211\u90fd\u77e5\u9053&#xff0c;\u8986\u76d6\u79d1\u6280\u3001\u5386\u53f2\u3001\u6587\u5b66\u3001\u751f\u6d3b\u3001\u5e38\u8bc6\u7b49\u7b49&#xff0c;\u4ec0\u4e48\u90fd\u80fd\u804a&#xff01;<\/p>\n<p>&#x1f4c4; **\u5904\u7406\u6587\u4ef6\u80fd\u529b\u5f3a**&#xff1a;\u4f60\u53ef\u4ee5\u4e0a\u4f20 Word\u3001Excel\u3001PDF\u3001PPT \u7b49\u6587\u4ef6&#xff0c;\u6211\u80fd\u5e2e\u4f60\u63d0\u53d6\u3001\u603b\u7ed3\u3001\u7ffb\u8bd1\u751a\u81f3\u91cd\u5199\u5185\u5bb9\u3002<\/p>\n<p>&#x1f4a1; **\u521b\u9020\u529b\u9ad8**&#xff1a;\u5199\u6545\u4e8b\u3001\u5199\u8bd7\u3001\u5199\u5267\u672c\u3001\u5199\u90ae\u4ef6\u3001\u5199\u7b80\u5386\u3001\u5199\u4ee3\u7801&#xff0c;\u751a\u81f3\u5e2e\u4f60\u60f3\u70b9\u521b\u4e1a\u70b9\u5b50&#xff0c;\u6211\u90fd\u64c5\u957f&#xff01;<\/p>\n<p>&#x1f91d; **\u8010\u5fc3\u53cb\u597d**&#xff1a;\u4e0d\u7ba1\u4f60\u8bf4\u8bdd\u662f\u6b63\u5f0f\u8fd8\u662f\u968f\u610f&#xff0c;\u6211\u90fd\u4f1a\u7528\u6700\u9002\u5408\u4f60\u7684\u65b9\u5f0f\u6765\u56de\u5e94\u3002\u4e0d\u4f1a\u4e0d\u8010\u70e6&#xff0c;\u4e5f\u4e0d\u4f1a\u5570\u55e6&#xff0c;\u53ea\u7ed9\u4f60\u60f3\u8981\u7684\u7b54\u6848&#xff01;<\/p>\n<p>\u800c\u4e14&#xff0c;\u6211\u73b0\u5728\u662f **\u514d\u8d39\u7684**&#xff0c;\u4f60\u53ef\u4ee5\u653e\u5fc3\u4f7f\u7528&#xff0c;\u6709\u95ee\u9898\u968f\u65f6\u6765\u95ee\u6211\u54e6&#xff01;<\/p>\n<p>\u90a3\u4f60\u60f3\u4e86\u89e3\u4e9b\u4ec0\u4e48\u5462&#xff1f;&#x1f60a;<\/p>\n<p><span class=\"token comment\"># 1 \u5bfc\u5165 ChatOllama<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain_ollama <span class=\"token keyword\">import<\/span> ChatOllama<\/p>\n<p><span class=\"token comment\"># 2 \u521d\u59cb\u5316\u672c\u5730\u804a\u5929\u6a21\u578b<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> ChatOllama<span class=\"token punctuation\">(<\/span>model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;deepseek-r1:8b&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 3 \u5b9a\u4e49\u95ee\u9898<\/span><br \/>\nquestion <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8bf7\u4f60\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 4 \u8c03\u7528\u6a21\u578b<\/span><br \/>\nresult <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span>question<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># 5 \u6253\u5370\u5185\u5bb9<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">.<\/span>content<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>\u60a8\u597d&#xff01;\u6211\u662f\u7531\u4e2d\u56fd\u7684\u6df1\u5ea6\u6c42\u7d22&#xff08;DeepSeek&#xff09;\u516c\u53f8\u5f00\u53d1\u7684\u667a\u80fd\u52a9\u624bDeepSeek-R1\u3002\u5982\u60a8\u6709\u4efb\u4f55\u4efb\u4f55\u95ee\u9898&#xff0c;\u6211\u4f1a\u5c3d\u6211\u6240\u80fd\u4e3a\u60a8\u63d0\u4f9b\u5e2e\u52a9\u3002<\/p>\n<h4>5. Vllm<\/h4>\n<p><span class=\"token comment\"># \u5b89\u88c5 vLLM&#xff08;\u63a8\u8350\u7528\u963f\u91cc\u4e91\u955c\u50cf\u52a0\u901f&#xff09;<\/span><br \/>\n<span class=\"token comment\">#!pip install vllm -i https:\/\/mirrors.aliyun.com\/pypi\/simple\/<\/span><\/p>\n<p><span class=\"token comment\"># \u8fde\u63a5\u672c\u5730vLLM\u670d\u52a1<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain_openai <span class=\"token keyword\">import<\/span> ChatOpenAI<\/p>\n<p><span class=\"token comment\"># \u8fde\u63a5\u5230\u672c\u5730 vLLM \u670d\u52a1,\u914d\u7f6e\u957f\u8fde\u63a5\u6c60&#xff0c;\u51cf\u5c11\u63e1\u624b\u5f00\u9500<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> ChatOpenAI<span class=\"token punctuation\">(<\/span><br \/>\n    model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;qwen-32b-chat&#034;<\/span><span class=\"token punctuation\">,<\/span>                  <span class=\"token comment\"># \u6307\u5b9a\u4f7f\u7528\u7684\u6a21\u578b\u540d\u79f0<\/span><br \/>\n    base_url<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;http:\/\/localhost:8000\/v1&#034;<\/span><span class=\"token punctuation\">,<\/span>    <span class=\"token comment\"># vLLM \u7684 OpenAI API \u5730\u5740<\/span><br \/>\n    api_key <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;********************&#034;<\/span><span class=\"token punctuation\">,<\/span>                        <span class=\"token comment\"># vLLM \u4e0d\u9a8c\u8bc1 key&#xff0c;\u53ef\u4ee5\u968f\u4fbf\u5199<\/span><br \/>\n    max_retries<span class=\"token operator\">&#061;<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span>                          <span class=\"token comment\"># \u589e\u52a0\u91cd\u8bd5\u6b21\u6570<\/span><br \/>\n    timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">120.0<\/span><span class=\"token punctuation\">,<\/span>                          <span class=\"token comment\"># \u8d85\u65f6\u65f6\u95f4\u8bbe\u957f<\/span><br \/>\n    http_client<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">{<\/span>                           <span class=\"token comment\"># \u81ea\u5b9a\u4e49 HTTP \u5ba2\u6237\u7aef<\/span><br \/>\n        <span class=\"token string\">&#034;limits&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#034;max_connections&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">,<\/span>         <span class=\"token comment\"># \u6700\u5927\u8fde\u63a5\u6570<\/span><br \/>\n            <span class=\"token string\">&#034;max_keepalive_connections&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">20<\/span>    <span class=\"token comment\"># \u6700\u5927\u4fdd\u6301\u6d3b\u52a8\u8fde\u63a5\u6570<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<h4>6. init_chat_model()<\/h4>\n<p><span class=\"token comment\"># \u4f7f\u7528init_chat_model\u521d\u59cb\u5316DeepSeek\u6a21\u578b<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>chat_models <span class=\"token keyword\">import<\/span> init_chat_model<\/p>\n<p><span class=\"token comment\"># 1. \u521d\u59cb\u5316\u6a21\u578b&#xff08;\u81ea\u52a8\u8bc6\u522b\u4f9b\u5e94\u5546&#xff09;<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> init_chat_model<span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token string\">&#034;deepseek-chat&#034;<\/span><span class=\"token punctuation\">,<\/span>                <span class=\"token comment\"># \u6307\u5b9aDeepSeek\u7684\u804a\u5929\u6a21\u578b<\/span><br \/>\n    model_provider<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;deepseek&#034;<\/span><span class=\"token punctuation\">,<\/span>      <span class=\"token comment\"># \u6307\u5b9a\u6a21\u578b\u63d0\u4f9b\u5546\u4e3adeepseek<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u4e00\u884c\u4ee3\u7801\u5207\u6362\u6a21\u578b&#xff0c;\u4e1a\u52a1\u4ee3\u78010\u6539\u52a8<\/span><br \/>\n<span class=\"token comment\"># model &#061; init_chat_model(&#034;gpt-4o&#034;, model_provider&#061;&#034;openai&#034;)<\/span><br \/>\n<span class=\"token comment\"># model &#061; init_chat_model(&#034;claude-3-5-sonnet&#034;, model_provider&#061;&#034;anthropic&#034;)<\/span><\/p>\n<p>question <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u4f60\u597d&#xff0c;\u8bf7\u4f60\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1\u3002&#034;<\/span><\/p>\n<p>result <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span>question<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">.<\/span>content<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>\u4f60\u597d&#xff01;\u6211\u662fDeepSeek&#xff0c;\u7531\u6df1\u5ea6\u6c42\u7d22\u516c\u53f8\u521b\u9020\u7684AI\u52a9\u624b&#xff0c;\u5f88\u9ad8\u5174\u8ba4\u8bc6\u4f60&#xff01;&#x1f60a;<\/p>\n<p>\u8ba9\u6211\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u81ea\u5df1&#xff1a;<\/p>\n<p>**\u57fa\u672c\u4fe1\u606f&#xff1a;**<br \/>\n&#8211; \u6211\u662f\u4e00\u4e2a\u7eaf\u6587\u672cAI\u6a21\u578b&#xff0c;\u4e13\u6ce8\u4e8e\u7406\u89e3\u548c\u751f\u6210\u81ea\u7136\u8bed\u8a00<br \/>\n&#8211; \u77e5\u8bc6\u622a\u6b62\u52302024\u5e747\u6708&#xff0c;\u662fDeepSeek\u7684\u6700\u65b0\u7248\u672c<br \/>\n&#8211; \u62e5\u6709128K\u7684\u4e0a\u4e0b\u6587\u5904\u7406\u80fd\u529b&#xff0c;\u53ef\u4ee5\u5904\u7406\u8f83\u957f\u7684\u5bf9\u8bdd\u548c\u6587\u6863<\/p>\n<p>**\u6211\u7684\u80fd\u529b&#xff1a;**<br \/>\n&#8211; \u56de\u7b54\u5404\u79cd\u95ee\u9898&#xff0c;\u8fdb\u884c\u6df1\u5ea6\u5bf9\u8bdd<br \/>\n&#8211; \u6587\u4ef6\u5904\u7406&#xff1a;\u652f\u6301\u4e0a\u4f20\u56fe\u50cf\u3001txt\u3001pdf\u3001ppt\u3001word\u3001excel\u6587\u4ef6&#xff0c;\u5e76\u8bfb\u53d6\u5176\u4e2d\u7684\u6587\u5b57\u4fe1\u606f<br \/>\n&#8211; \u8054\u7f51\u641c\u7d22&#xff1a;\u867d\u7136\u9700\u8981\u4f60\u5728Web\/App\u4e2d\u624b\u52a8\u70b9\u5f00\u8054\u7f51\u641c\u7d22\u6309\u952e&#xff0c;\u4f46\u6211\u53ef\u4ee5\u83b7\u53d6\u6700\u65b0\u4fe1\u606f<br \/>\n&#8211; \u4ee3\u7801\u7f16\u5199\u548c\u95ee\u9898\u89e3\u7b54<br \/>\n&#8211; \u521b\u610f\u5199\u4f5c\u3001\u7ffb\u8bd1\u3001\u5206\u6790\u7b49<\/p>\n<p>**\u4f7f\u7528\u65b9\u5f0f&#xff1a;**<br \/>\n&#8211; \u5b8c\u5168\u514d\u8d39\u4f7f\u7528&#xff0c;\u6ca1\u6709\u6536\u8d39\u8ba1\u5212<br \/>\n&#8211; \u53ef\u4ee5\u901a\u8fc7\u5b98\u65b9\u5e94\u7528\u5546\u5e97\u4e0b\u8f7dApp<br \/>\n&#8211; \u76ee\u524d\u662f\u7eaf\u6587\u672c\u6a21\u578b&#xff0c;\u4e0d\u652f\u6301\u8bed\u97f3\u529f\u80fd<\/p>\n<p>\u6211\u7684\u56de\u590d\u98ce\u683c\u6bd4\u8f83\u70ed\u60c5\u7ec6\u817b&#xff0c;\u5e0c\u671b\u80fd\u7ed9\u4f60\u5e26\u6765\u6e29\u6696\u548c\u5e2e\u52a9\u3002\u65e0\u8bba\u4f60\u6709\u4ec0\u4e48\u95ee\u9898\u6216\u9700\u8981\u4ec0\u4e48\u534f\u52a9&#xff0c;\u6211\u90fd\u4f1a\u5c3d\u6211\u6240\u80fd\u4e3a\u4f60\u63d0\u4f9b\u652f\u6301&#xff01;<\/p>\n<p>\u6709\u4ec0\u4e48\u7279\u522b\u60f3\u4e86\u89e3\u7684&#xff0c;\u6216\u8005\u9700\u8981\u6211\u5e2e\u52a9\u7684\u5417&#xff1f;\u6211\u5f88\u4e50\u610f\u4e3a\u4f60\u670d\u52a1&#xff01;\u2728<\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<ul>\n<li>\n<p>model \u4ee3\u8868\u5177\u4f53\u6a21\u578b\u540d\u79f0&#xff08;gpt-4o\u3001claude-3-haiku\u3001gemini-pro \u7b49&#xff09;<\/p>\n<\/li>\n<li>\n<p>model_provider \u4ee3\u8868\u6a21\u578b\u6765\u6e90&#xff08;openai\u3001anthropic\u3001google&#xff09;<\/p>\n<\/li>\n<\/ul>\n<table>\n<tr>provider\u6a21\u578b\u6765\u6e90&#xff08;\u5382\u5546&#xff09;\u9ed8\u8ba4\u4f7f\u7528\u7684\u73af\u5883\u53d8\u91cf<\/tr>\n<tbody>\n<tr>\n<td align=\"center\">openai<\/td>\n<td align=\"center\">OpenAI&#xff08;GPT-4.1, GPT-4o, o3-mini \u7b49&#xff09;<\/td>\n<td align=\"center\">OPENAI_API_KEY<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">anthropic<\/td>\n<td align=\"center\">Anthropic&#xff08;Claude 3 \u7cfb\u5217&#xff09;<\/td>\n<td align=\"center\">ANTHROPIC_API_KEY<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">google<\/td>\n<td align=\"center\">Google&#xff08;Gemini \u7cfb\u5217&#xff09;<\/td>\n<td align=\"center\">GOOGLE_API_KEY<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">cohere<\/td>\n<td align=\"center\">Cohere&#xff08;Command \u7cfb\u5217&#xff09;<\/td>\n<td align=\"center\">COHERE_API_KEY<\/td>\n<\/tr>\n<tr>\n<td align=\"center\">ollama<\/td>\n<td align=\"center\">\u672c\u5730\u6a21\u578b&#xff08;LLaMA\u3001Qwen\u3001Mistral \u7b49&#xff09;<\/td>\n<td align=\"center\">\u672c\u5730\u65e0\u9700 API Key<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2003\u2003\u4f60\u53ef\u4ee5\u8ba9\u4e00\u4e2a\u5e94\u7528\u53ea\u6362 provider&#xff0c;\u800c\u4e0d\u6539\u903b\u8f91&#xff1a;<\/p>\n<h5>RateLimit \u6a21\u578b\u901f\u7387\u9650\u5236\u5668<\/h5>\n<p><span class=\"token comment\"># 1. \u5b9a\u4e49\u5e26\u901f\u7387\u9650\u5236\u7684load_chat_model\u51fd\u6570<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>chat_models <span class=\"token keyword\">import<\/span> init_chat_model<br \/>\n<span class=\"token keyword\">from<\/span> langchain_core<span class=\"token punctuation\">.<\/span>rate_limiters <span class=\"token keyword\">import<\/span> InMemoryRateLimiter<\/p>\n<p><span class=\"token comment\"># 2. \u914d\u7f6e\u901f\u7387\u9650\u5236\u5668<\/span><br \/>\nrate_limiter <span class=\"token operator\">&#061;<\/span> InMemoryRateLimiter<span class=\"token punctuation\">(<\/span><br \/>\n    requests_per_second<span class=\"token operator\">&#061;<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span>       <span class=\"token comment\"># \u6bcf\u79d2\u6700\u591a5\u4e2a\u8bf7\u6c42<\/span><br \/>\n    check_every_n_seconds<span class=\"token operator\">&#061;<\/span><span class=\"token number\">1.0<\/span>    <span class=\"token comment\"># \u6bcf1\u79d2\u68c0\u67e5\u4e00\u6b21\u662f\u5426\u8d85\u8fc7\u901f\u7387\u9650\u5236<\/span><br \/>\n<span class=\"token punctuation\">)<\/span>  <\/p>\n<p><span class=\"token comment\"># 3. \u5bf9\u6a21\u578b\u8c03\u7528\u8fdb\u884c\u5c01\u88c5&#xff0c;\u540e\u7eed\u76f4\u63a5\u8c03\u7528\u4f20\u53c2\u6570\u5c31\u884c<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">load_chat_model<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    model<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    provider<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    temperature<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0.7<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    max_tokens<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span> <span class=\"token operator\">|<\/span> <span class=\"token boolean\">None<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    base_url<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span> <span class=\"token operator\">|<\/span> <span class=\"token boolean\">None<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> init_chat_model<span class=\"token punctuation\">(<\/span><br \/>\n        model<span class=\"token operator\">&#061;<\/span>model<span class=\"token punctuation\">,<\/span>               <span class=\"token comment\"># \u6a21\u578b\u540d\u79f0<\/span><br \/>\n        model_provider<span class=\"token operator\">&#061;<\/span>provider<span class=\"token punctuation\">,<\/span>   <span class=\"token comment\"># \u6a21\u578b\u4f9b\u5e94\u5546<\/span><br \/>\n        temperature<span class=\"token operator\">&#061;<\/span>temperature<span class=\"token punctuation\">,<\/span>   <span class=\"token comment\"># \u6e29\u5ea6\u53c2\u6570&#xff0c;\u7528\u4e8e\u63a7\u5236\u6a21\u578b\u7684\u968f\u673a\u6027&#xff0c;\u503c\u8d8a\u5c0f\u5219\u968f\u673a\u6027\u8d8a\u5c0f<\/span><br \/>\n        max_tokens<span class=\"token operator\">&#061;<\/span>max_tokens<span class=\"token punctuation\">,<\/span>     <span class=\"token comment\"># \u6700\u5927\u751f\u6210token\u6570<\/span><br \/>\n        base_url<span class=\"token operator\">&#061;<\/span>base_url<span class=\"token punctuation\">,<\/span>         <span class=\"token comment\"># \u4e13\u7528\u4e8e\u81ea\u5b9a\u4e49 API Server \u6216\u4ee3\u7406<\/span><br \/>\n        rate_limiter<span class=\"token operator\">&#061;<\/span>rate_limiter  <span class=\"token comment\"># \u81ea\u52a8\u9650\u901f<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u8c03\u7528load_chat_model\u51fd\u6570\u521d\u59cb\u5316gpt-4o-mini\u6a21\u578b<\/span><br \/>\n<span class=\"token comment\"># model &#061; load_chat_model(<\/span><br \/>\n<span class=\"token comment\">#     model&#061;&#034;gpt-4o-mini&#034;,    # \u6307\u5b9aOpenAI\u7684gpt-4o-mini\u6a21\u578b<\/span><br \/>\n<span class=\"token comment\">#     provider&#061;&#034;openai&#034;,      # \u6307\u5b9a\u6a21\u578b\u63d0\u4f9b\u5546\u4e3aopenai<\/span><br \/>\n<span class=\"token comment\"># )<\/span><\/p>\n<p><span class=\"token comment\"># res &#061; model.invoke(&#034;\u8bf7\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1&#034;)<\/span><br \/>\n<span class=\"token comment\"># res<\/span><\/p>\n<p>model <span class=\"token operator\">&#061;<\/span> load_chat_model<span class=\"token punctuation\">(<\/span><br \/>\n    model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;deepseek-chat&#034;<\/span><span class=\"token punctuation\">,<\/span>    <span class=\"token comment\"># \u6307\u5b9aOpenAI\u7684gpt-4o-mini\u6a21\u578b<\/span><br \/>\n    provider<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;deepseek&#034;<\/span><span class=\"token punctuation\">,<\/span>      <span class=\"token comment\"># \u6307\u5b9a\u6a21\u578b\u63d0\u4f9b\u5546\u4e3aopenai<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p>res <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>invoke<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8bf7\u4ecb\u7ecd\u4e00\u4e0b\u4f60\u81ea\u5df1&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nres<\/p>\n<h5>.with_retry()\u6a21\u578b\u91cd\u8bd5\u673a\u5236<\/h5>\n<ul>\n<li>\n<p>\u4f7f\u7528\u91cd\u8bd5\u673a\u5236&#xff1a;\u901a\u8fc7 .with_retry() \u65b9\u6cd5\u4e3a\u6a21\u578b\u8c03\u7528\u6dfb\u52a0\u6307\u6570\u9000\u907f\u91cd\u8bd5\u7b56\u7565&#xff0c;\u5728\u9047\u5230\u4e34\u65f6\u6027\u6545\u969c&#xff08;\u5982\u901f\u7387\u9650\u5236\u9519\u8bef&#xff09;\u65f6\u81ea\u52a8\u91cd\u8bd5<\/p>\n<\/li>\n<li>\n<p>\u6307\u6570\u9000\u907f\u7684\u7b49\u5f85\u65f6\u95f4&#xff1a;<\/p>\n<ul>\n<li>\n<p>1s \u2192 2s \u2192 4s \u2192 8s \u2192 16s \u2192 \u2026<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u6b21\u5931\u8d25\u90fd\u6307\u6570\u589e\u52a0\u7b49\u5f85\u65f6\u95f4&#xff0c;\u907f\u514d\u5feb\u901f\u91cd\u590d\u6253\u7206 API\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6296\u52a8 &#061; \u5728\u7b49\u5f85\u65f6\u95f4\u4e0a\u968f\u673a\u589e\u52a0\/\u51cf\u5c11\u4e00\u70b9\u968f\u673a\u6570<\/p>\n<ul>\n<li>\n<p>\u9632\u6b62\u96c6\u7fa4\u4e2d\u7684\u591a\u4e2a\u5ba2\u6237\u7aef\u5728\u76f8\u540c\u65f6\u95f4\u91cd\u590d\u540c\u65f6\u56de\u9000&#xff0c;\u9020\u6210\u66f4\u5927\u62e5\u5835<\/p>\n<\/li>\n<li>\n<p>\u5931\u8d25\u7684\u8bf7\u6c42\u4e0d\u4f1a\u540c\u65f6\u53d1\u8d77&#xff0c;\u6781\u5927\u964d\u4f4e API \u6216\u672c\u5730\u6a21\u578b\u7684\u538b\u529b\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><span class=\"token comment\"># \u4e3a\u6a21\u578b\u6dfb\u52a0\u6307\u6570\u9000\u907f\u91cd\u8bd5\u7b56\u7565<\/span><br \/>\nmodel <span class=\"token operator\">&#061;<\/span> model<span class=\"token punctuation\">.<\/span>with_retry<span class=\"token punctuation\">(<\/span><br \/>\n        stop_after_attempt<span class=\"token operator\">&#061;<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span>         <span class=\"token comment\"># \u6700\u591a\u91cd\u8bd53\u6b21<\/span><br \/>\n        wait_exponential_jitter<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span>  <span class=\"token comment\"># \u6307\u6570\u9000\u907f &#043; \u968f\u673a\u6296\u52a8<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span><\/p>\n<h4>7. init_embeddings()<\/h4>\n<p><span class=\"token comment\"># 1. \u4f7f\u7528init_embeddings\u521d\u59cb\u5316\u5d4c\u5165\u6a21\u578b<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>embeddings <span class=\"token keyword\">import<\/span> init_embeddings<\/p>\n<p><span class=\"token comment\"># 2. \u521d\u59cb\u5316OpenAI\u7684text-embedding-3-small\u5d4c\u5165\u6a21\u578b<\/span><br \/>\nembedding <span class=\"token operator\">&#061;<\/span> init_embeddings<span class=\"token punctuation\">(<\/span>model<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;text-embedding-3-small&#034;<\/span><span class=\"token punctuation\">,<\/span>provider<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;openai&#034;<\/span><span class=\"token punctuation\">)<\/span>   <\/p>\n<p><span class=\"token comment\"># 3. \u5c06\u6587\u672c\u8f6c\u6362\u4e3a\u5411\u91cf\u8868\u793a<\/span><br \/>\nres <span class=\"token operator\">&#061;<\/span> embedding<span class=\"token punctuation\">.<\/span>embed_query<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Hello world&#034;<\/span><span class=\"token punctuation\">)<\/span>    <\/p>\n<p><span class=\"token comment\"># 4. \u6253\u5370\u5411\u91cf\u7684\u524d10\u4e2a\u5143\u7d20<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>res<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>[-0.002078542485833168, -0.04908587411046028, 0.020946789532899857, 0.03135102614760399, -0.04530530795454979, -0.026402482762932777, -0.028999701142311096, 0.06030462309718132, -0.02571091614663601, -0.01482258178293705]<\/p>\n<p><span class=\"token comment\"># \u5b9a\u4e49load_embedding\u51fd\u6570\u5c01\u88c5\u5d4c\u5165\u6a21\u578b\u521d\u59cb\u5316\u903b\u8f91<\/span><br \/>\n<span class=\"token comment\"># \u8be5\u51fd\u6570\u7528\u4e8e\u6839\u636e\u6307\u5b9a\u7684\u6a21\u578b\u540d\u79f0\u3001\u63d0\u4f9b\u5546\u548c\u53ef\u9009\u7684\u81ea\u5b9a\u4e49API\u5730\u5740&#xff0c;\u5feb\u901f\u521d\u59cb\u5316\u5e76\u8fd4\u56de\u4e00\u4e2a\u5d4c\u5165\u6a21\u578b\u5b9e\u4f8b<\/span><br \/>\n<span class=\"token keyword\">from<\/span> langchain<span class=\"token punctuation\">.<\/span>embeddings <span class=\"token keyword\">import<\/span> init_embeddings<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">load_embedding<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    model<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span>    <span class=\"token comment\"># \u6a21\u578b\u540d\u79f0<\/span><br \/>\n    provider<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span>    <span class=\"token comment\"># \u6a21\u578b\u63d0\u4f9b\u5546<\/span><br \/>\n    base_url<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span> <span class=\"token operator\">|<\/span> <span class=\"token boolean\">None<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">,<\/span>    <span class=\"token comment\"># \u81ea\u5b9a\u4e49API\u670d\u52a1\u5668\u5730\u5740<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u8c03\u7528init_embeddings\u5b8c\u6210\u5d4c\u5165\u6a21\u578b\u7684\u521d\u59cb\u5316<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> init_embeddings<span class=\"token punctuation\">(<\/span><br \/>\n        model<span class=\"token operator\">&#061;<\/span>model<span class=\"token punctuation\">,<\/span>    <span class=\"token comment\"># \u6a21\u578b\u540d\u79f0<\/span><br \/>\n        provider<span class=\"token operator\">&#061;<\/span>provider<span class=\"token punctuation\">,<\/span>    <span class=\"token comment\"># \u6a21\u578b\u63d0\u4f9b\u5546<\/span><br \/>\n        base_url<span class=\"token operator\">&#061;<\/span>base_url    <span class=\"token comment\"># \u81ea\u5b9a\u4e49API\u670d\u52a1\u5668\u5730\u5740<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u52a0\u8f7d\u6307\u5b9a\u7684\u6587\u672c\u5d4c\u5165\u6a21\u578b&#xff08;text-embedding-3-small&#xff09;\u5e76\u6307\u5b9a\u63d0\u4f9b\u5546\u4e3a openai<\/span><br \/>\nload_embedding<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;text-embedding-3-small&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">&#034;openai&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528\u5df2\u52a0\u8f7d\u7684\u5d4c\u5165\u6a21\u578b\u5bf9\u6587\u672c &#034;Hello world&#034; \u8fdb\u884c\u5411\u91cf\u5316&#xff0c;\u8fd4\u56de\u4e00\u4e2a\u5411\u91cf\u5217\u8868<\/span><br \/>\nres <span class=\"token operator\">&#061;<\/span> embedding<span class=\"token punctuation\">.<\/span>embed_query<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Hello world&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u6253\u5370\u8be5\u5411\u91cf\u5217\u8868\u7684\u524d 10 \u4e2a\u5143\u7d20&#xff0c;\u65b9\u4fbf\u5feb\u901f\u67e5\u770b\u7ed3\u679c<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>res<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c&#xff1a;<\/p>\n<p>[-0.0021342115942388773, -0.049084946513175964, 0.020961761474609375, 0.03135043382644653, -0.04533518850803375, -0.026371248066425323, -0.028922313824295998, 0.06024201214313507, -0.025725798681378365, -0.01483766920864582]<\/p>\n<ul>\n<li>\u66f4\u591a\u6a21\u578b\u63a5\u5165\u6d41\u7a0b&#xff0c;\u8be6\u89c1:https:\/\/docs.langchain.com\/oss\/python\/integrations\/chat<\/li>\n<\/ul>\n<hr \/>\n<h3>&#x1f3af; \u603b\u7ed3<\/h3>\n<p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86 LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3 \u7684\u6838\u5fc3\u6982\u5ff5\u548c\u5b9e\u6218\u6280\u5de7\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528 LangChain 1.0&#xff01;<\/p>\n<p>\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u5efa\u8bae&#xff0c;\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u4ea4\u6d41&#xff01;&#x1f4ac;<\/p>\n<hr \/>\n<p>\u2190 \u4e0a\u4e00\u7bc7&#xff1a;langchain-community \u4e0e\u5382\u5546\u96c6\u6210\u5305 | &#x1f4da; \u7cfb\u5217\u76ee\u5f55 | \u4e0b\u4e00\u7bc7&#xff1a;Messages \u4e0e Prompt \u63d0\u793a\u8bcd\u6a21\u677f \u2192<\/p>\n<hr \/>\n<p>&#x1f3f7;\ufe0f \u6807\u7b7e&#xff1a;LangChain \u5927\u6a21\u578b API\u63a5\u5165<\/p>\n<p>&#x1f49d; \u611f\u8c22\u9605\u8bfb&#xff01;\u5982\u679c\u89c9\u5f97\u6709\u5e2e\u52a9&#xff0c;\u8bb0\u5f97\u70b9\u8d5e\u6536\u85cf\u5173\u6ce8\u54e6&#xff01;<\/p>\n<hr \/>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u5185\u5bb9&#xff0c;\u7248\u6743\u5f52\u4f5c\u8005\u6240\u6709&#xff0c;\u8f6c\u8f7d\u9700\u6ce8\u660e\u51fa\u5904\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f4cc; \u6240\u5c5e\u7ae0\u8282&#xff1a;\u7b2c\u4e09\u9636\u6bb5 &#8211; LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3 \u2190 \u4e0a\u4e00\u7bc7&#xff1a;langchain-community \u4e0e\u5382\u5546\u96c6\u6210\u5305 | &#x1f4da; \u7cfb\u5217\u76ee\u5f55 | \u4e0b\u4e00\u7bc7&#xff1a;Messages \u4e0e Prompt \u63d0\u793a\u8bcd\u6a21\u677f \u2192 &#x1f4cb; \u6458\u8981<br \/>\n\u672c\u6587\u8be6\u7ec6\u8bb2\u89e3\u4e86 LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3&#xff0c;\u5305\u62ec\u6838\u5fc3\u6982\u5ff5\u3001\u5b9e\u6218\u4ee3\u7801\u793a\u4f8b\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u901a\u8fc7\u672c\u6587\u7684\u5b66\u4e60&#xff0c;\u4f60\u5c06\u638c\u63e1 Lan<\/p>\n","protected":false},"author":2,"featured_media":75531,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[8057,997,50],"topic":[],"class_list":["post-75535","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-8057","tag-langchain","tag-50"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/75535.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"&#x1f4cc; \u6240\u5c5e\u7ae0\u8282&#xff1a;\u7b2c\u4e09\u9636\u6bb5 - LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3 \u2190 \u4e0a\u4e00\u7bc7&#xff1a;langchain-community \u4e0e\u5382\u5546\u96c6\u6210\u5305 | &#x1f4da; \u7cfb\u5217\u76ee\u5f55 | \u4e0b\u4e00\u7bc7&#xff1a;Messages \u4e0e Prompt \u63d0\u793a\u8bcd\u6a21\u677f \u2192 &#x1f4cb; \u6458\u8981 \u672c\u6587\u8be6\u7ec6\u8bb2\u89e3\u4e86 LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3&#xff0c;\u5305\u62ec\u6838\u5fc3\u6982\u5ff5\u3001\u5b9e\u6218\u4ee3\u7801\u793a\u4f8b\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u901a\u8fc7\u672c\u6587\u7684\u5b66\u4e60&#xff0c;\u4f60\u5c06\u638c\u63e1 Lan\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/75535.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-12T06:42:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212064206-698d763e98362.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/75535.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/75535.html\",\"name\":\"\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-12T06:42:09+00:00\",\"dateModified\":\"2026-02-12T06:42:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/75535.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/75535.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/75535.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/75535.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"&#x1f4cc; \u6240\u5c5e\u7ae0\u8282&#xff1a;\u7b2c\u4e09\u9636\u6bb5 - LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3 \u2190 \u4e0a\u4e00\u7bc7&#xff1a;langchain-community \u4e0e\u5382\u5546\u96c6\u6210\u5305 | &#x1f4da; \u7cfb\u5217\u76ee\u5f55 | \u4e0b\u4e00\u7bc7&#xff1a;Messages \u4e0e Prompt \u63d0\u793a\u8bcd\u6a21\u677f \u2192 &#x1f4cb; \u6458\u8981 \u672c\u6587\u8be6\u7ec6\u8bb2\u89e3\u4e86 LLM \/ ChatModel \u5927\u6a21\u578b\u63a5\u53e3&#xff0c;\u5305\u62ec\u6838\u5fc3\u6982\u5ff5\u3001\u5b9e\u6218\u4ee3\u7801\u793a\u4f8b\u548c\u6700\u4f73\u5b9e\u8df5\u3002\u901a\u8fc7\u672c\u6587\u7684\u5b66\u4e60&#xff0c;\u4f60\u5c06\u638c\u63e1 Lan","og_url":"https:\/\/www.wsisp.com\/helps\/75535.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-12T06:42:09+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260212064206-698d763e98362.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/75535.html","url":"https:\/\/www.wsisp.com\/helps\/75535.html","name":"\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-12T06:42:09+00:00","dateModified":"2026-02-12T06:42:09+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/75535.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/75535.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/75535.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7b2c\u4e94\u7bc7\uff1aLangChain 1.0 \u6a21\u578b\u63a5\u5165\u5b9e\u6218\uff1aDeepSeek\/OpenAI\/\u901a\u4e49\u5343\u95ee\u5168\u6253\u901a"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/75535","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=75535"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/75535\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/75531"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=75535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=75535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=75535"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=75535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}