当前位置: 首页 > news >正文

单页网站 开元wordpress博客小工具标签

单页网站 开元,wordpress博客小工具标签,酒类网站建,怎样设计网站版面本教程将介绍如何使用LangChain库和chatglm API来解决一个4x4的数独问题。我们将通过以下步骤实现这一目标#xff1a; 初始化chatglm 的聊天模型。定义数独问题和解决方案。创建一个自定义的检查器来验证每一步的思考。使用ToTChain来运行整个思考过程。 1. 初始化chatglm4…本教程将介绍如何使用LangChain库和chatglm API来解决一个4x4的数独问题。我们将通过以下步骤实现这一目标 初始化chatglm 的聊天模型。定义数独问题和解决方案。创建一个自定义的检查器来验证每一步的思考。使用ToTChain来运行整个思考过程。 1. 初始化chatglm4 的聊天模型 首先我们需要导入langchain_openai库中的ChatOpenAI类并初始化一个聊天模型实例。 from langchain_openai import ChatOpenAIllm ChatOpenAI(temperature1,modelGLM-4-Plus,openai_api_keyyour api key,openai_api_basehttps://open.bigmodel.cn/api/paas/v4/,max_tokens512, )2. 定义数独问题和解决方案 接下来我们定义一个4x4的数独问题和其解决方案并生成问题描述。 sudoku_puzzle 3,*,*,2|1,*,3,*|*,1,*,3|4,*,*,1 sudoku_solution 3,4,1,2|1,2,3,4|2,1,4,3|4,3,2,1 problem_description f {sudoku_puzzle}- This is a 4x4 Sudoku puzzle. - The * represents a cell to be filled. - The | character separates rows. - At each step, replace one or more * with digits 1-4. - There must be no duplicate digits in any row, column or 2x2 subgrid. - Keep the known digits from previous valid thoughts in place. - Each thought can be a partial or the final solution. .strip() print(problem_description)输出结果如下 3,*,*,2|1,*,3,*|*,1,*,3|4,*,*,1- This is a 4x4 Sudoku puzzle. - The * represents a cell to be filled. - The | character separates rows. - At each step, replace one or more * with digits 1-4. - There must be no duplicate digits in any row, column or 2x2 subgrid. - Keep the known digits from previous valid thoughts in place. - Each thought can be a partial or the final solution.3. 创建自定义检查器 我们需要创建一个自定义的检查器MyChecker用于验证每一步的思考是否有效。 import re from typing import Tuplefrom langchain_experimental.tot.checker import ToTChecker from langchain_experimental.tot.thought import ThoughtValidityclass MyChecker(ToTChecker):def evaluate(self, problem_description: str, thoughts: Tuple[str, ...] ()) - ThoughtValidity:last_thought thoughts[-1]clean_solution last_thought.replace( , ).replace(, )regex_solution clean_solution.replace(*, .).replace(|, \\|)if sudoku_solution in clean_solution:return ThoughtValidity.VALID_FINALelif re.search(regex_solution, sudoku_solution):return ThoughtValidity.VALID_INTERMEDIATEelse:return ThoughtValidity.INVALID4. 测试检查器 我们可以通过一些断言来测试检查器的功能。 checker MyChecker() assert (checker.evaluate(, (3,*,*,2|1,*,3,*|*,1,*,3|4,*,*,1,)) ThoughtValidity.VALID_INTERMEDIATE ) assert (checker.evaluate(, (3,4,1,2|1,2,3,4|2,1,4,3|4,3,2,1,)) ThoughtValidity.VALID_FINAL ) assert (checker.evaluate(, (3,4,1,2|1,2,3,4|2,1,4,3|4,3,*,1,)) ThoughtValidity.VALID_INTERMEDIATE ) assert (checker.evaluate(, (3,4,1,2|1,2,3,4|2,1,4,3|4,*,3,1,)) ThoughtValidity.INVALID )5. 运行ToTChain 最后我们使用ToTChain来运行整个思考过程并尝试解决数独问题。 from langchain_experimental.tot.base import ToTChaintot_chain ToTChain(llmllm, checkerMyChecker(), k30, c5, verboseTrue, verbose_llmFalse ) tot_chain.run(problem_descriptionproblem_description)输出结果如下 C:\Users\32564\AppData\Local\Temp\ipykernel_5080\1223294212.py:6: LangChainDeprecationWarning: The method Chain.run was deprecated in langchain 0.1.0 and will be removed in 1.0. Use :meth:~invoke instead.tot_chain.run(problem_descriptionproblem_description) d:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([1m Entering new ToTChain chain...[0m Starting the ToT solve procedure. [33;1m[1;3mThought: 3,*,*,2|1,*,3,*|*,1,*,3|4,*,*,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([31;1m[1;3m Thought: 3,1,*,2|1,*,3,*|*,1,*,3|4,*,*,1 [0m[31;1m[1;3m Thought: 3,*,4,2|1,*,3,*|*,1,*,3|4,*,*,1 [0m[33;1m[1;3m Thought: 3,*,*,2|1,2,3,*|*,1,*,3|4,*,*,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: 3,*,*,2|1,2,3,4|*,1,*,3|4,*,*,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: 3,*,*,2|1,2,3,4|2,1,*,3|4,*,*,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: 3,*,*,2|1,2,3,4|2,1,4,3|4,*,*,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: 3,*,*,2|1,2,3,4|2,1,4,3|4,3,*,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: 3,*,*,2|1,2,3,4|2,1,4,3|4,3,2,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: 3,*,*,2|1,2,3,4|2,1,4,3|4,3,2,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([31;1m[1;3m Thought: 3,1,*,2|1,2,3,4|2,1,4,3|4,3,2,1 [0m[33;1m[1;3m Thought: 3,4,*,2|1,2,3,4|2,1,4,3|4,3,2,1 [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([33;1m[1;3m Thought: [0md:\soft\anaconda\envs\langchain\Lib\site-packages\langchain\chains\llm.py:341: UserWarning: The predict_and_parse method is deprecated, instead pass an output parser directly to LLMChain.warnings.warn([32;1m[1;3m Thought: 3,4,1,2|1,2,3,4|2,1,4,3|4,3,2,1 [0m [1m Finished chain.[0m3,4,1,2|1,2,3,4|2,1,4,3|4,3,2,1通过以上步骤我们成功地使用LangChain解决了一个4x4的数独问题。希望这个教程对你有所帮助如果有任何问题欢迎随时提问。
http://www.hkea.cn/news/14293233/

相关文章:

  • 织梦网站管理安装婚纱摄影网页制作
  • 网站推广营销的步骤wordpress 简单模板
  • 如何在百度建设企业网站天津个人网站备案查询
  • 2017国外优秀网站设计网站搜索功能怎样做
  • 黄石网站设计制作建门户网站哪家最好
  • wordpress英文站群舟山网络公司网站建设公司
  • 提高网站seowordpress怎么弄背景
  • 企业网站宣传视频外链纺织服装网站建设规划方案
  • 网站备案号要怎么查询资讯网站建设流程
  • 怎么在网站上放广告怀化买房网站
  • 欧美做爰视频网站做模版的网站
  • ps怎么做响应式网站布局图最新国际局势新消息
  • 找人网站o2o是指的是什么
  • 百度网站名称及网址wordpress短码
  • 泊头网站建设价格张家港市住房和城乡建设局网站
  • 网站前台建设需要哪些技术知识网页设计与制作100例怎么写
  • 网站开发需要哪些证书免费建站哪个好
  • 网站建设补贴网站服务器关闭怎么恢复
  • 帮传销做网站违法吗填空秒懂网站
  • 厦门网站建设屈兴东网站建设所有权
  • 网站建设价格多少钱免费观看行情软件
  • 电子商务网站建设与维护致谢词佛山网站制作网站设计
  • 成都网站制作是什么广州网站优
  • 快速做网站流量数据统计分析wordpress建设企业网站
  • 徐州市住房和城乡建设局网站首页邯郸房产网签查询网
  • 漳州正规网站建设做网站九州科技
  • 无锡网站建设书生商友福建省建设注册执业管理中心网站
  • 仿网站源码湖南公司网站建设
  • 为什么网站很少做全屏办公室装修费计入什么费用
  • 网站建设找哪家公司好慈利网站建设