@tom_doerr: 使用LLMs通过图形解决复杂问题 https://github.com/spcl/graph-of-thoughts…

X AI KOLs Timeline 工具

摘要

Graph of Thoughts (GoT) 是一个开源的Python框架,它通过将复杂问题建模为操作图来使用LLMs解决这些问题,支持CoT和ToT等方法。

使用LLMs通过图形解决复杂问题 https://t.co/mAEsrbYjdK https://t.co/T2eGGebdAt
查看原文
查看缓存全文

缓存时间: 2026/06/16 13:38

使用LLM通过图来解决复杂问题 https://t.co/mAEsrbYjdK https://t.co/T2eGGebdAt — # spcl/graph-of-thoughts 源码:https://github.com/spcl/graph-of-thoughts # Graph of Thoughts (GoT) 这是 Graph of Thoughts: Solving Elaborate Problems with Large Language Models(https://arxiv.org/pdf/2308.09687.pdf)的官方实现。该框架使你能够通过将复杂问题建模为操作图(Graph of Operations,GoO)来解决它们,并自动以大型语言模型(LLM)作为引擎执行该图。该框架设计灵活且可扩展,不仅允许你使用新的 GoT 方法解决问题,还可以实现类似 CoT 或 ToT 等以往方法对应的 GoO。 ## 安装指南 要使用此框架,你需要安装 Python 3.8 或更高版本。 ### 安装 GoT 在运行以下两种安装方法之前,请确保已激活你的 Python 环境(如有)。 如果你是用户,只想使用 graph_of_thoughts,可以直接从 PyPI 安装: bash pip install graph_of_thoughts 如果你是开发者,想要修改代码,可以从源码以可编辑模式安装: bash git clone https://github.com/spcl/graph-of-thoughts.git cd graph-of-thoughts pip install -e . ### 配置 LLM 要使用该框架,你需要能够访问一个 LLM。请按照 Controller README 中的说明配置你选择的 LLM。 ## 快速开始 以下代码片段展示了如何使用该框架,通过类似 CoT 的方法对 32 个数字的列表进行排序。运行代码前,请确保已遵循安装指南python from examples.sorting.sorting_032 import SortingPrompter, SortingParser, utils from graph_of_thoughts import controller, language_models, operations # 问题输入 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]" # 创建操作图 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)) # 配置语言模型(假设当前目录下有包含 OpenAI API 密钥的 config.json) lm = language_models.ChatGPT("config.json", model_name="chatgpt") # 创建控制器 ctrl = controller.Controller( lm, gop, SortingPrompter(), SortingParser(), # 以下字典用于配置初始思维状态 { "original": to_be_sorted, "current": "", "method": "cot" } ) # 运行控制器并生成输出图 ctrl.run() ctrl.output_graph("output_cot.json") 要运行更复杂的 GoT 方法,可以使用以下代码片段。 python from examples.sorting.sorting_032 import SortingPrompter, SortingParser, got, utils from graph_of_thoughts import controller, language_models, operations # 问题输入 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]" # 获取操作图 gop = got() # 配置语言模型(假设当前目录下有包含 OpenAI API 密钥的 config.json) lm = language_models.ChatGPT("config.json", model_name="chatgpt") # 创建控制器 ctrl = controller.Controller( lm, gop, SortingPrompter(), SortingParser(), # 以下字典用于配置初始思维状态 { "original": to_be_sorted, "current": "", "phase": 0, "method": "got" } ) # 运行控制器并生成输出图 ctrl.run() ctrl.output_graph("output_got.json") 你可以通过检查输出图 output_cot.jsonoutput_got.json 来比较两个结果。最终思维状态的分数表示排序列表中的错误数量。 ## 文档 论文提供了框架及其组件的高层概述。要更详细地了解该框架,你可以阅读各个模块的文档。尤其是 ControllerOperations 模块,对于理解如何充分利用该框架非常重要。我们特别注重代码的完整文档化,以便你轻松理解其工作原理并对其进行扩展。 ## 示例 examples 目录包含几个可以使用该框架解决的问题示例,包括论文中介绍的示例。它是学习如何使用框架解决实际问题的绝佳起点。每个示例都有一个 README.md 文件,其中包含运行和尝试该示例的说明。代码有完整文档,易于理解。你也可以直接从主目录运行示例。请注意,结果将存储在相应的示例子目录中。例如尝试: bash python -m examples.sorting.sorting_032 python -m examples.keyword_counting.keyword_counting ## 论文结果 你可以按照 examples 目录中的说明运行论文中的实验。但如果你只是想查看和重新绘制结果,可以使用 paper 目录。 ## 引用 如果你觉得这个仓库有价值,请给它一个 star!有任何问题或反馈?请随时联系 [email protected] 或提交 issue。在你的工作中使用了这项技术?请使用提供的引用信息注明我们: bibtex @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} }

相似文章