{"id":13493811,"url":"https://github.com/spcl/graph-of-thoughts","last_synced_at":"2025-05-13T23:07:08.551Z","repository":{"id":189176952,"uuid":"680173591","full_name":"spcl/graph-of-thoughts","owner":"spcl","description":"Official Implementation of \"Graph of Thoughts: Solving Elaborate Problems with Large Language Models\"","archived":false,"fork":false,"pushed_at":"2024-12-11T10:46:50.000Z","size":15018,"stargazers_count":2359,"open_issues_count":5,"forks_count":165,"subscribers_count":22,"default_branch":"main","last_synced_at":"2025-05-12T03:06:31.449Z","etag":null,"topics":["graph-of-thoughts","graph-structures","graphs","large-language-models","llm","prompt-engineering","prompting"],"latest_commit_sha":null,"homepage":"https://arxiv.org/pdf/2308.09687.pdf","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spcl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-18T14:15:39.000Z","updated_at":"2025-05-09T04:39:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"e0410883-8240-4870-9033-761218c68505","html_url":"https://github.com/spcl/graph-of-thoughts","commit_stats":{"total_commits":24,"total_committers":4,"mean_commits":6.0,"dds":"0.41666666666666663","last_synced_commit":"363421c61c7bc11edf32845a697ae2aaccd75463"},"previous_names":["spcl/graph-of-thoughts"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcl%2Fgraph-of-thoughts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcl%2Fgraph-of-thoughts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcl%2Fgraph-of-thoughts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcl%2Fgraph-of-thoughts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spcl","download_url":"https://codeload.github.com/spcl/graph-of-thoughts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254041114,"owners_count":22004666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph-of-thoughts","graph-structures","graphs","large-language-models","llm","prompt-engineering","prompting"],"created_at":"2024-07-31T19:01:19.030Z","updated_at":"2025-05-13T23:07:03.515Z","avatar_url":"https://github.com/spcl.png","language":"Python","funding_links":[],"categories":["Python","A01_文本生成_文本对话"],"sub_categories":["大语言对话模型及数据"],"readme":"# Graph of Thoughts (GoT)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"paper/pics/preview.svg\"\u003e\n\u003c/p\u003e\n\nThis is the official implementation of [Graph of Thoughts: Solving Elaborate Problems with Large Language Models](https://arxiv.org/pdf/2308.09687.pdf).  \nThis framework gives you the ability to solve complex problems by modeling them as a Graph of Operations (GoO), which is automatically executed with a Large Language Model (LLM) as the engine.  \nThis framework is designed to be flexible and extensible, allowing you to not only solve problems using the new GoT approach, but also to implement GoOs resembling previous approaches like CoT or ToT.\n\n## Setup Guide\n\nIn order to use this framework, you need to have a working installation of Python 3.8 or newer.\n\n### Installing GoT\n\nBefore running either of the following two installation methods, make sure to activate your Python environment (if any) beforehand.  \nIf you are a user and you just want to use `graph_of_thoughts`, you can install it directly from PyPI:\n```bash\npip install graph_of_thoughts\n```\nIf you are a developer and you want to modify the code, you can install it in editable mode from source:\n```bash\ngit clone https://github.com/spcl/graph-of-thoughts.git\ncd graph-of-thoughts\npip install -e .\n```\n\n### Configuring the LLM\n\nIn order to use the framework, you need to have access to an LLM.\nPlease follow the instructions in the [Controller README](graph_of_thoughts/controller/README.md) to configure the LLM of your choice.\n\n## Quick Start\n\nThe following code snippet shows how to use the framework to solve the sorting problem for a list of 32 numbers using a CoT-like approach.  \nMake sure you have followed the [Setup Guide](#setup-guide) before running the code.\n\n```python\nfrom examples.sorting.sorting_032 import SortingPrompter, SortingParser, utils\nfrom graph_of_thoughts import controller, language_models, operations\n\n# Problem input\n\nto_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]\"\n\n# Create the Graph of Operations\ngop = operations.GraphOfOperations()\ngop.append_operation(operations.Generate())\ngop.append_operation(operations.Score(scoring_function=utils.num_errors))\ngop.append_operation(operations.GroundTruth(utils.test_sorting))\n\n# Configure the Language Model (Assumes config.json is in the current directory with OpenAI API key)\nlm = language_models.ChatGPT(\"config.json\", model_name=\"chatgpt\")\n\n# Create the Controller\nctrl = controller.Controller(\n  lm, \n  gop, \n  SortingPrompter(), \n  SortingParser(),\n  # The following dictionary is used to configure the initial thought state\n  {\n    \"original\": to_be_sorted,\n    \"current\": \"\",\n    \"method\": \"cot\"\n  }\n)\n\n# Run the Controller and generate the output graph\nctrl.run()\nctrl.output_graph(\"output_cot.json\")\n```\n\nTo run the more sophisticated GoT approach, you can use the following code snippet.\n\n```python\nfrom examples.sorting.sorting_032 import SortingPrompter, SortingParser, got, utils\nfrom graph_of_thoughts import controller, language_models, operations\n\n# Problem input\n\nto_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]\"\n\n# Retrieve the Graph of Operations\ngop = got()\n\n# Configure the Language Model (Assumes config.json is in the current directory with OpenAI API key)\nlm = language_models.ChatGPT(\"config.json\", model_name=\"chatgpt\")\n\n# Create the Controller\nctrl = controller.Controller(\n  lm, \n  gop, \n  SortingPrompter(), \n  SortingParser(),\n  # The following dictionary is used to configure the initial thought state\n  {\n    \"original\": to_be_sorted,\n    \"current\": \"\",\n    \"phase\": 0,\n    \"method\": \"got\"\n  }\n)\n\n# Run the Controller and generate the output graph\nctrl.run()\nctrl.output_graph(\"output_got.json\")\n```\nYou can compare the two results by inspecting the output graphs `output_cot.json` and `output_got.json`.  \nThe final thought states' scores indicate the number of errors in the sorted list.\n\n## Documentation\nThe paper gives a high-level overview of the framework and its components.  \nIn order to understand the framework in more detail, you can read the documentation of the individual modules.  \nEspecially the [Controller](graph_of_thoughts/controller/README.md) and [Operations](graph_of_thoughts/operations/README.md) modules are important for understanding how to make the most out of the framework.  \nWe took extra care to fully document the code, so that you can easily understand how it works and how to extend it.\n\n## Examples\n\nThe [examples](examples) directory contains several examples of problems that can be solved using the framework, including the ones presented in the paper.  \nIt is a great starting point for learning how to use the framework to solve real problems.  \nEach example contains a `README.md` file with instructions on how to run it and play with it. The code is fully documented and should be easy to follow.\nYou can also run the examples straight from the main directory. Note that the results will be stored in the respective examples sub-directory.\n\nTry for instance:\n```bash\npython -m examples.sorting.sorting_032\npython -m examples.keyword_counting.keyword_counting\n```\n## Paper Results\n\nYou can run the experiments from the paper by following the instructions in the [examples](examples) directory.  \nHowever, if you just want to inspect and replot the results, you can use the [paper](paper) directory.\n\n## Citations\n\nIf you find this repository valuable, please give it a star!  \nGot any questions or feedback? Feel free to reach out to [nils.blach@inf.ethz.ch](mailto:nils.blach@inf.ethz.ch) or open an issue.  \nUsing this in your work? Please reference us using the provided citation:\n\n```bibtex\n@article{besta2024got,\n  title = {{Graph of Thoughts: Solving Elaborate Problems with Large Language Models}},\n  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},\n  year = 2024,\n  month = {Mar},\n  journal = {Proceedings of the AAAI Conference on Artificial Intelligence},\n  volume = 38,\n  number = 16,\n  pages = {17682-17690},\n  publisher = {AAAI Press},\n  doi = {10.1609/aaai.v38i16.29720},\n  url = {https://ojs.aaai.org/index.php/AAAI/article/view/29720}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspcl%2Fgraph-of-thoughts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspcl%2Fgraph-of-thoughts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspcl%2Fgraph-of-thoughts/lists"}