這是思想圖的官方實施:通過大型語言模型解決精心設計的問題。
該框架使您能夠通過將它們建模為操作圖(GOO)來解決複雜問題,該圖形將自動以大型語言模型(LLM)作為引擎執行。
該框架旨在靈活且可擴展,您不僅可以使用新的GOT方法解決問題,還可以實現類似於COT或TOT等先前方法的Goos。
為了使用此框架,您需要進行Python 3.8或更新的工作安裝。
在運行以下兩種安裝方法中的任何一個之前,請確保事先激活您的Python環境(如果有)。
如果您是用戶,並且只想使用graph_of_thoughts ,則可以直接從PYPI安裝它:
pip install graph_of_thoughts如果您是開發人員,並且要修改代碼,則可以從源以可編輯模式安裝它:
git clone https://github.com/spcl/graph-of-thoughts.git
cd graph-of-thoughts
pip install -e .為了使用該框架,您需要訪問LLM。請按照控制器讀取中的說明進行配置,以配置您選擇的LLM。
以下代碼片段顯示瞭如何使用類似COT的方法來解決32個數字列表的排序問題。
在運行代碼之前,請確保已遵循設置指南。
from examples . sorting . sorting_032 import SortingPrompter , SortingParser , utils
from graph_of_thoughts import controller , language_models , operations
# Problem input
to_be_sorted = "[0, 2, 6, 3, 8, 7, 1, 1, 6, 7, 7, 7, 7, 9, 3, 0, 1, 7, 9, 1, 3, 5, 1, 3, 6, 4, 5, 4, 7, 3, 5, 7]"
# Create the Graph of Operations
gop = operations . GraphOfOperations ()
gop . append_operation ( operations . Generate ())
gop . append_operation ( operations . Score ( scoring_function = utils . num_errors ))
gop . append_operation ( operations . GroundTruth ( utils . test_sorting ))
# Configure the Language Model (Assumes config.json is in the current directory with OpenAI API key)
lm = language_models . ChatGPT ( "config.json" , model_name = "chatgpt" )
# Create the Controller
ctrl = controller . Controller (
lm ,
gop ,
SortingPrompter (),
SortingParser (),
# The following dictionary is used to configure the initial thought state
{
"original" : to_be_sorted ,
"current" : "" ,
"method" : "cot"
}
)
# Run the Controller and generate the output graph
ctrl . run ()
ctrl . output_graph ( "output_cot.json" )為了運行更複雜的方法,您可以使用以下代碼段。
from examples . sorting . sorting_032 import SortingPrompter , SortingParser , got , utils
from graph_of_thoughts import controller , language_models , operations
# Problem input
to_be_sorted = "[0, 2, 6, 3, 8, 7, 1, 1, 6, 7, 7, 7, 7, 9, 3, 0, 1, 7, 9, 1, 3, 5, 1, 3, 6, 4, 5, 4, 7, 3, 5, 7]"
# Retrieve the Graph of Operations
gop = got ()
# Configure the Language Model (Assumes config.json is in the current directory with OpenAI API key)
lm = language_models . ChatGPT ( "config.json" , model_name = "chatgpt" )
# Create the Controller
ctrl = controller . Controller (
lm ,
gop ,
SortingPrompter (),
SortingParser (),
# The following dictionary is used to configure the initial thought state
{
"original" : to_be_sorted ,
"current" : "" ,
"phase" : 0 ,
"method" : "got"
}
)
# Run the Controller and generate the output graph
ctrl . run ()
ctrl . output_graph ( "output_got.json" )您可以通過檢查輸出圖output_cot.json和output_got.json來比較兩個結果。
最終思想的分數指出了排序列表中的錯誤數量。
該論文提供了框架及其組件的高級概述。
為了更詳細地了解框架,您可以閱讀單個模塊的文檔。
特別是控制器和操作模塊對於理解如何充分利用框架很重要。
我們謹慎地記錄了代碼,以便您可以輕鬆地了解其工作原理以及如何擴展它。
示例目錄包含幾個可以使用該框架(包括論文中提出的問題)解決的問題的示例。
這是學習如何使用框架來解決實際問題的好起點。
每個示例都包含一個README.md文件,其中包含有關如何運行並使用它的說明。該代碼已充分記錄,應該易於遵循。您還可以直接從主目錄直接運行示例。請注意,結果將存儲在相應的示例子目錄中。
例如,嘗試:
python -m examples.sorting.sorting_032
python -m examples.keyword_counting.keyword_counting您可以按照示例目錄中的說明從紙張中運行實驗。
但是,如果您只想檢查和重新調整結果,則可以使用紙目錄。
如果您發現此存儲庫有價值,請給它一顆星!
有任何問題或反饋嗎?請隨時與[email protected]聯繫或打開問題。
在您的工作中使用這個?請使用提供的引用來引用我們:
@article { besta2024got ,
title = { {Graph of Thoughts: Solving Elaborate Problems with Large Language Models} } ,
author = { Besta, Maciej and Blach, Nils and Kubicek, Ales and Gerstenberger, Robert and Gianinazzi, Lukas and Gajda, Joanna and Lehmann, Tomasz and Podstawski, Micha{l} and Niewiadomski, Hubert and Nyczyk, Piotr and Hoefler, Torsten } ,
year = 2024 ,
month = { Mar } ,
journal = { Proceedings of the AAAI Conference on Artificial Intelligence } ,
volume = 38 ,
number = 16 ,
pages = { 17682-17690 } ,
publisher = { AAAI Press } ,
doi = { 10.1609/aaai.v38i16.29720 } ,
url = { https://ojs.aaai.org/index.php/AAAI/article/view/29720 }
}