这是思想图的官方实施:通过大型语言模型解决精心设计的问题。
该框架使您能够通过将它们建模为操作图(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 }
}