tree-of-thoughts


Nametree-of-thoughts JSON
Version 0.6.5 PyPI version JSON
download
home_pagehttps://github.com/kyegomez/tree-of-thoughts
SummaryTree of Thoughts - Pytorch
upload_time2024-10-29 15:23:19
maintainerNone
docs_urlNone
authorKye Gomez
requires_python<4.0,>=3.10
licenseMIT
keywords artificial intelligence deep learning optimizers prompt engineering
VCS
bugtrack_url
requirements swarms pydantic loguru python-dotenv swarm-models
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Multi-Modality](images/agorabanner.png)](https://discord.gg/qUtxnK2NMf)

![Tree of Thoughts Banner](images/treeofthoughts.png)

![Discord](https://img.shields.io/discord/999382051935506503)
[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)](https://twitter.com/intent/tweet?text=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts!%20https://github.com/kyegomez/tree-of-thoughts)
[![LinkedIn](https://img.shields.io/badge/Share-LinkedIn-blue?style=social&logo=linkedin)](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)
[![Facebook](https://img.shields.io/badge/Share-Facebook-blue?style=social&logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)
[![Reddit](https://img.shields.io/badge/Share-Reddit-orange?style=social&logo=reddit)](https://www.reddit.com/submit?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&title=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21)
[![Hacker News](https://img.shields.io/badge/Share-Hacker%20News-orange?style=social&logo=y-combinator)](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&t=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21)
[![Pinterest](https://img.shields.io/badge/Share-Pinterest-red?style=social&logo=pinterest)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&media=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts%2Fraw%2Fmain%2Ftree-of-thoughts.jpeg&description=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21)
[![WhatsApp](https://img.shields.io/badge/Share-WhatsApp-green?style=social&logo=whatsapp)](https://api.whatsapp.com/send?text=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21%20https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)


[Paper link](https://arxiv.org/pdf/2305.10601.pdf)
[Author's implementation](https://github.com/princeton-nlp/tree-of-thought-llm)

## Introduction

Tree of Thoughts (ToT) is a powerful and flexible algorithm that significantly advances model reasoning by up to 70%. This plug-and-play version allows you to connect your own models and experience superintelligence!


## Install

```bash
$ pip3 install -U tree-of-thoughts
```

## Requirements 
In your .env file, you need to have the following variables:

```bash
WORKSPACE_DIR="artifacts"
OPENAI_API_KEY="your_openai_api_key"
```

## Example
```python
from tree_of_thoughts import TotAgent, ToTDFSAgent
from dotenv import load_dotenv

load_dotenv()

# Create an instance of the TotAgent class
tot_agent = TotAgent(use_openai_caller=False)  # Use openai caller

# Create an instance of the ToTDFSAgent class with specified parameters
dfs_agent = ToTDFSAgent(
    agent=tot_agent,  # Use the TotAgent instance as the agent for the DFS algorithm
    threshold=0.8,  # Set the threshold for evaluating the quality of thoughts
    max_loops=1,  # Set the maximum number of loops for the DFS algorithm
    prune_threshold=0.5,  # Branches with evaluation < 0.5 will be pruned
    number_of_agents=4,  # Set the number of agents to be used in the DFS algorithm
)

# Define the initial state for the DFS algorithm
initial_state = """

Your task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math

"""

# Run the DFS algorithm to solve the problem and obtain the final thought
final_thought = dfs_agent.run(initial_state)

# Print the final thought in JSON format for easy reading
print(final_thought)

"""

# Run the DFS algorithm to solve the problem and obtain the final thought
final_thought = dfs_agent.run(initial_state)

# Print the final thought in JSON format for easy reading
print(final_thought)


```

### Basic Prompts
```txt

Imagine three different experts are answering this question. All experts will write down 1 step of their thinking, then share it with the group. Then all experts will go on to the next step, etc. If any expert realises they're wrong at any point then they leave. The question is...



################ 2nd ################

Simulate three brilliant, logical experts collaboratively answering a question. Each one verbosely explains their thought process in real-time, considering the prior explanations of others and openly acknowledging mistakes. At each step, whenever possible, each expert refines and builds upon the thoughts of others, acknowledging their contributions. They continue until there is a definitive answer to the question. For clarity, your entire response should be in a markdown table. The question is...


################ ################

Imagine three highly intelligent experts working together to answer a question. They will follow a tree of thoughts approach, where each expert shares their thought process step by step. They will consider the input from others, refine their thoughts, and build upon the group's collective knowledge. If an expert realizes their thought is incorrect, they will acknowledge it and withdraw from the discussion. Continue this process until a definitive answer is reached. Present the entire response in a markdown table. The question is...


################ 2nd ################

Three experts with exceptional logical thinking skills are collaboratively answering a question using a tree of thoughts method. Each expert will share their thought process in detail, taking into account the previous thoughts of others and admitting any errors. They will iteratively refine and expand upon each other's ideas, giving credit where it's due. The process continues until a conclusive answer is found. Organize the entire response in a markdown table format. The question is...
################ 2nd ################


Envision a group of three experts working in unison to tackle a question by employing a tree of thoughts strategy. Each expert will thoroughly explain their line of thinking at every step, while also considering the insights provided by their peers. They will openly recognize any mistakes and build upon the group's shared understanding. This iterative process will continue until a definitive solution is reached. Structure the entire response as a markdown table. The question is...


################ 2nd ################

"Three experts with exceptional logical thinking skills are collaboratively answering a question using the tree of thoughts method. Each expert will share their thought process in detail, taking into account the previous thoughts of others and admitting any errors. They will iteratively refine and expand upon each other's ideas, giving credit where it's due. The process continues until a conclusive answer is found. Organize the entire response in a markdown table format. The task is:
```

## Todo
- [ ] Finish implementing the depth or max_loops feature in the dfs class
- [ ] Finish the new BFS search algorithm
- [ ] Implement montecarlo search algorithm
- [ ] Make a function that can intake json and make a tree out of it visually to visualize the tree of thoughts! 


# Acknowledgements

Thanks to: Shunyu Yao Princeton University, Dian Yu Google DeepMind, Jeffrey Zhao, Google DeepMind, Izhak Shafran Google DeepMind, Thomas L. Griffiths, Princeton University, Yuan Cao Google DeepMind, Karthik Narasimha, Princeton University for sharing this amazing work with the world!

And, thanks to Phil Wang or Lucidrains for inspiring me to devote myself to open source AI Research

# License
Apache

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kyegomez/tree-of-thoughts",
    "name": "tree-of-thoughts",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "artificial intelligence, deep learning, optimizers, Prompt Engineering",
    "author": "Kye Gomez",
    "author_email": "kye@apac.ai",
    "download_url": "https://files.pythonhosted.org/packages/c9/1f/7fd279b670bd0786426aadb3bb4cdc8d5a3c155c5ae5f06e44c1ef6c1c87/tree_of_thoughts-0.6.5.tar.gz",
    "platform": null,
    "description": "[![Multi-Modality](images/agorabanner.png)](https://discord.gg/qUtxnK2NMf)\n\n![Tree of Thoughts Banner](images/treeofthoughts.png)\n\n![Discord](https://img.shields.io/discord/999382051935506503)\n[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)](https://twitter.com/intent/tweet?text=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts!%20https://github.com/kyegomez/tree-of-thoughts)\n[![LinkedIn](https://img.shields.io/badge/Share-LinkedIn-blue?style=social&logo=linkedin)](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)\n[![Facebook](https://img.shields.io/badge/Share-Facebook-blue?style=social&logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)\n[![Reddit](https://img.shields.io/badge/Share-Reddit-orange?style=social&logo=reddit)](https://www.reddit.com/submit?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&title=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21)\n[![Hacker News](https://img.shields.io/badge/Share-Hacker%20News-orange?style=social&logo=y-combinator)](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&t=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21)\n[![Pinterest](https://img.shields.io/badge/Share-Pinterest-red?style=social&logo=pinterest)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&media=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts%2Fraw%2Fmain%2Ftree-of-thoughts.jpeg&description=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21)\n[![WhatsApp](https://img.shields.io/badge/Share-WhatsApp-green?style=social&logo=whatsapp)](https://api.whatsapp.com/send?text=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21%20https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)\n\n\n[Paper link](https://arxiv.org/pdf/2305.10601.pdf)\n[Author's implementation](https://github.com/princeton-nlp/tree-of-thought-llm)\n\n## Introduction\n\nTree of Thoughts (ToT) is a powerful and flexible algorithm that significantly advances model reasoning by up to 70%. This plug-and-play version allows you to connect your own models and experience superintelligence!\n\n\n## Install\n\n```bash\n$ pip3 install -U tree-of-thoughts\n```\n\n## Requirements \nIn your .env file, you need to have the following variables:\n\n```bash\nWORKSPACE_DIR=\"artifacts\"\nOPENAI_API_KEY=\"your_openai_api_key\"\n```\n\n## Example\n```python\nfrom tree_of_thoughts import TotAgent, ToTDFSAgent\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\n# Create an instance of the TotAgent class\ntot_agent = TotAgent(use_openai_caller=False)  # Use openai caller\n\n# Create an instance of the ToTDFSAgent class with specified parameters\ndfs_agent = ToTDFSAgent(\n    agent=tot_agent,  # Use the TotAgent instance as the agent for the DFS algorithm\n    threshold=0.8,  # Set the threshold for evaluating the quality of thoughts\n    max_loops=1,  # Set the maximum number of loops for the DFS algorithm\n    prune_threshold=0.5,  # Branches with evaluation < 0.5 will be pruned\n    number_of_agents=4,  # Set the number of agents to be used in the DFS algorithm\n)\n\n# Define the initial state for the DFS algorithm\ninitial_state = \"\"\"\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math\n\n\"\"\"\n\n# Run the DFS algorithm to solve the problem and obtain the final thought\nfinal_thought = dfs_agent.run(initial_state)\n\n# Print the final thought in JSON format for easy reading\nprint(final_thought)\n\n\"\"\"\n\n# Run the DFS algorithm to solve the problem and obtain the final thought\nfinal_thought = dfs_agent.run(initial_state)\n\n# Print the final thought in JSON format for easy reading\nprint(final_thought)\n\n\n```\n\n### Basic Prompts\n```txt\n\nImagine three different experts are answering this question. All experts will write down 1 step of their thinking, then share it with the group. Then all experts will go on to the next step, etc. If any expert realises they're wrong at any point then they leave. The question is...\n\n\n\n################ 2nd ################\n\nSimulate three brilliant, logical experts collaboratively answering a question. Each one verbosely explains their thought process in real-time, considering the prior explanations of others and openly acknowledging mistakes. At each step, whenever possible, each expert refines and builds upon the thoughts of others, acknowledging their contributions. They continue until there is a definitive answer to the question. For clarity, your entire response should be in a markdown table. The question is...\n\n\n################ ################\n\nImagine three highly intelligent experts working together to answer a question. They will follow a tree of thoughts approach, where each expert shares their thought process step by step. They will consider the input from others, refine their thoughts, and build upon the group's collective knowledge. If an expert realizes their thought is incorrect, they will acknowledge it and withdraw from the discussion. Continue this process until a definitive answer is reached. Present the entire response in a markdown table. The question is...\n\n\n################ 2nd ################\n\nThree experts with exceptional logical thinking skills are collaboratively answering a question using a tree of thoughts method. Each expert will share their thought process in detail, taking into account the previous thoughts of others and admitting any errors. They will iteratively refine and expand upon each other's ideas, giving credit where it's due. The process continues until a conclusive answer is found. Organize the entire response in a markdown table format. The question is...\n################ 2nd ################\n\n\nEnvision a group of three experts working in unison to tackle a question by employing a tree of thoughts strategy. Each expert will thoroughly explain their line of thinking at every step, while also considering the insights provided by their peers. They will openly recognize any mistakes and build upon the group's shared understanding. This iterative process will continue until a definitive solution is reached. Structure the entire response as a markdown table. The question is...\n\n\n################ 2nd ################\n\n\"Three experts with exceptional logical thinking skills are collaboratively answering a question using the tree of thoughts method. Each expert will share their thought process in detail, taking into account the previous thoughts of others and admitting any errors. They will iteratively refine and expand upon each other's ideas, giving credit where it's due. The process continues until a conclusive answer is found. Organize the entire response in a markdown table format. The task is:\n```\n\n## Todo\n- [ ] Finish implementing the depth or max_loops feature in the dfs class\n- [ ] Finish the new BFS search algorithm\n- [ ] Implement montecarlo search algorithm\n- [ ] Make a function that can intake json and make a tree out of it visually to visualize the tree of thoughts! \n\n\n# Acknowledgements\n\nThanks to: Shunyu Yao Princeton University, Dian Yu Google DeepMind, Jeffrey Zhao, Google DeepMind, Izhak Shafran Google DeepMind, Thomas L. Griffiths, Princeton University, Yuan Cao Google DeepMind, Karthik Narasimha, Princeton University for sharing this amazing work with the world!\n\nAnd, thanks to Phil Wang or Lucidrains for inspiring me to devote myself to open source AI Research\n\n# License\nApache\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Tree of Thoughts - Pytorch",
    "version": "0.6.5",
    "project_urls": {
        "Homepage": "https://github.com/kyegomez/tree-of-thoughts"
    },
    "split_keywords": [
        "artificial intelligence",
        " deep learning",
        " optimizers",
        " prompt engineering"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "329fe96a41ee5283a3589c1c6199d3ce0b61911a146fb73d98680a16d7980e93",
                "md5": "f9e4185e880d20c26a784ff9863a2ebf",
                "sha256": "4ddd4d7597440f14ca415ce1f8f8bccba66f52e414867b74b032eb84522cd975"
            },
            "downloads": -1,
            "filename": "tree_of_thoughts-0.6.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f9e4185e880d20c26a784ff9863a2ebf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 13801,
            "upload_time": "2024-10-29T15:23:18",
            "upload_time_iso_8601": "2024-10-29T15:23:18.252593Z",
            "url": "https://files.pythonhosted.org/packages/32/9f/e96a41ee5283a3589c1c6199d3ce0b61911a146fb73d98680a16d7980e93/tree_of_thoughts-0.6.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c91f7fd279b670bd0786426aadb3bb4cdc8d5a3c155c5ae5f06e44c1ef6c1c87",
                "md5": "4ec60892c0178f77e849e3231b4b229c",
                "sha256": "61575c243895f06b35ddb1b87077112b32706517f7e0273336fd1429f6fe21c8"
            },
            "downloads": -1,
            "filename": "tree_of_thoughts-0.6.5.tar.gz",
            "has_sig": false,
            "md5_digest": "4ec60892c0178f77e849e3231b4b229c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 14280,
            "upload_time": "2024-10-29T15:23:19",
            "upload_time_iso_8601": "2024-10-29T15:23:19.661393Z",
            "url": "https://files.pythonhosted.org/packages/c9/1f/7fd279b670bd0786426aadb3bb4cdc8d5a3c155c5ae5f06e44c1ef6c1c87/tree_of_thoughts-0.6.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-29 15:23:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kyegomez",
    "github_project": "tree-of-thoughts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "swarms",
            "specs": []
        },
        {
            "name": "pydantic",
            "specs": []
        },
        {
            "name": "loguru",
            "specs": []
        },
        {
            "name": "python-dotenv",
            "specs": []
        },
        {
            "name": "swarm-models",
            "specs": []
        }
    ],
    "lcname": "tree-of-thoughts"
}
        
Elapsed time: 0.37405s