中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

廣州網站建設服務哪家好公司網站建設公司好

廣州網站建設服務哪家好,公司網站建設公司好,遼寧沈陽疫情最新消息,虛擬主機能做什么本教程將介紹如何使用LangChain庫和chatglm API來解決一個4x4的數獨問題。我們將通過以下步驟實現(xiàn)這一目標: 初始化chatglm 的聊天模型。定義數獨問題和解決方案。創(chuàng)建一個自定義的檢查器來驗證每一步的思考。使用ToTChain來運行整個思考過程。 1. 初始化chatglm4…

本教程將介紹如何使用LangChain庫和chatglm API來解決一個4x4的數獨問題。我們將通過以下步驟實現(xiàn)這一目標:

  1. 初始化chatglm 的聊天模型。
  2. 定義數獨問題和解決方案。
  3. 創(chuàng)建一個自定義的檢查器來驗證每一步的思考。
  4. 使用ToTChain來運行整個思考過程。

1. 初始化chatglm4 的聊天模型

首先,我們需要導入langchain_openai庫中的ChatOpenAI類,并初始化一個聊天模型實例。

from langchain_openai import ChatOpenAIllm = ChatOpenAI(temperature=1,model="GLM-4-Plus",openai_api_key="your api key",openai_api_base="https://open.bigmodel.cn/api/paas/v4/",max_tokens=512,
)

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. 創(chuàng)建自定義檢查器

我們需要創(chuàng)建一個自定義的檢查器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.INVALID

4. 測試檢查器

我們可以通過一些斷言來測試檢查器的功能。

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(llm=llm, checker=MyChecker(), k=30, c=5, verbose=True, verbose_llm=False
)
tot_chain.run(problem_description=problem_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_description=problem_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.[0m'3,4,1,2|1,2,3,4|2,1,4,3|4,3,2,1'

通過以上步驟,我們成功地使用LangChain解決了一個4x4的數獨問題。希望這個教程對你有所幫助!如果有任何問題,歡迎隨時提問。

http://www.risenshineclean.com/news/7160.html

相關文章:

  • 建站abc做的網站穩(wěn)定國內手機怎么上google瀏覽器
  • 建網站操作流程泰州seo網絡公司
  • 宜昌永東建設網站今日新聞 最新消息 大事
  • 公司就兩個開發(fā)百度seo教程網
  • 廣西桂林為什么窮優(yōu)化網站排名技巧
  • 龍華做棋牌網站建設多少錢網絡口碑營銷名詞解釋
  • 自己做的網站顯示不出來國際最新新聞熱點事件
  • WordPress碎語山東服務好的seo
  • 一個完整的動態(tài)網站開發(fā)東莞seo整站優(yōu)化火速
  • dede5.7 做的網站 下 加一個discuz論壇網站統(tǒng)計分析工具
  • 德陽網站開發(fā)熊掌號互聯(lián)網推廣是干什么的
  • 上傳網站到google什么是百度權重
  • 代碼網站開發(fā)seo搜索引擎優(yōu)化是什么意思
  • 建設企業(yè)網站可行性分析百度一下進入首頁
  • wordpress門戶網站模板下載互聯(lián)網營銷做什么
  • 做自動采集電影網站有什么處罰上海網絡推廣培訓機構
  • 專業(yè)做網站優(yōu)化個人網站模板
  • 茶網站開發(fā)的意義目的建站之星官方網站
  • 菏澤網站建設效果網址大全2345
  • 影響網站建設價格的因素有比較經典的營銷案例
  • 購物網站 購物車界面如何做html做一個簡單的網頁
  • 1920的做網站做多大重慶seo推廣運營
  • 網站服務器數據庫百度推廣找誰做靠譜
  • wordpress仿今日主題網站優(yōu)化包括哪些
  • 怎么進入wordpress后臺紹興網站快速排名優(yōu)化
  • cmseasy做網站簡單嗎營銷策劃培訓
  • 商丘市網站建設推廣福建企業(yè)seo推廣
  • 青島網站建設和優(yōu)化網絡營銷師有前途嗎
  • 網站建設 石家莊網站建設哪家公司好
  • 廣告公司做網站寧波seo網絡推廣代理公司