Tree-of-thoughts

Latest version: v0.4.8

Safety actively analyzes 625566 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

0.3.6

0.3.5

Changelog

1. **LangchainTOT Class Definition**: Introduced the LangchainTOT class to encapsulate all operations related to the Tree of Thought (ToT) process. This class holds an instance of the language model, the problem description, the thought checker, and the list of thoughts.

2. **LangchainTOT Class Customization**: Added optional parameters to the constructor of the LangchainTOT class for temperature, max_tokens, problem_description, model, and checker_class to make the class customizable. This allows for the customization of the language model and thought checker based on specific needs.

3. **LangchainTOT Class Error Handling**: Incorporated error handling within the `check_thoughts` method of the LangchainTOT class. It now raises a ValueError if no thoughts have been added or if the problem description hasn't been set, improving the robustness of the code.

4. **MyChecker Class Polymorphism**: Redefined the MyChecker class to make it more polymorphic and generalizable for any task. MyChecker now takes a validation function as a parameter, which defines how to check the validity of thoughts for a specific problem. This allows for the creation of checkers for any kind of problem, not just Sudoku.

5. **LangchainTOT Class Simplification**: Simplified the initialization of the LangchainTOT class by removing the parameter configuration from the instantiation of the OpenAI class. The LangchainTOT class now automatically configures these parameters based on the constructor arguments.

6. **Code Cleanup**: Cleaned up and debugged the code. Simplified the imports by using only the necessary ones. Reorganized the code for clarity and ease of understanding.

7. **Documentation**: Provided a detailed documentation explaining how to use the LangchainTOT and MyChecker classes, and how to define a custom validation function.

e28
File ~\...\treeofthoughts.py:267 in reconstruct_path
path = self.reconstruct_path(came_from, current_state)

TypeError: reconstruct_path() missing 1 required positional argument: 'initial_prompt'

E28
- DELETED LOGS FOLDER WITH WEIRD NAME FILES

E27
- Fixed file logging save error

E26
Tree of Thought Search Classes Documentation

Class: TreeofThoughts
This class represents the base class for the Tree of Thoughts search algorithm. It contains the following methods:

- `__init__(self, model)`: Initializes the TreeofThoughts object with the given model.
- `save_tree_to_json(self, file_name)`: Saves the tree to a JSON file with the given file name.
- `logNewState(self, state, evaluation)`: Logs a new state and its evaluation to the tree.
- `adjust_pruning_threshold_precentile(self, evaluated_thoughts, percentile)`: Adjusts the pruning threshold based on the percentile of evaluated thoughts.
- `adjust_pruning_threshold_moving_average(self, evaluated_thoughts, window_size)`: Adjusts the pruning threshold based on the moving average of evaluated thoughts.

Class: TreeofThoughtsBFS
This class represents the Breadth-First Search (BFS) variant of the Tree of Thoughts search algorithm. It inherits from the TreeofThoughts class and contains the following method:

- `solve(self, initial_prompt, num_thoughts, max_steps, max_states, value_threshold, pruning_threshold=0.5)`: Solves the problem using BFS with the given parameters.

Class: TreeofThoughtsDFS
This class represents the Depth-First Search (DFS) variant of the Tree of Thoughts search algorithm. It inherits from the TreeofThoughts class and contains the following method:

- `solve(self, initial_prompt, num_thoughts, max_steps, value_threshold, pruning_threshold=0.5)`: Solves the problem using DFS with the given parameters.

Class: TreeofThoughtsBEST
This class represents the Best-First Search variant of the Tree of Thoughts search algorithm. It contains the following methods:

- `__init__(self, model)`: Initializes the TreeofThoughtsBEST object with the given model.
- `save_tree_to_json(self, file_name)`: Saves the tree to a JSON file with the given file name.
- `log_new_state(self, state, evaluation)`: Logs a new state and its evaluation to the tree.
- `solve(self, initial_prompt, num_thoughts, max_steps, pruning_threshold)`: Solves the problem using Best-First Search with the given parameters.

Class: TreeofThoughtsASearch
This class represents the A* Search variant of the Tree of Thoughts search algorithm. It contains the following methods:

- `__init__(self, model)`: Initializes the TreeofThoughtsASearch object with the given model.
- `solve(self, initial_prompt, num_thoughts=5, max_steps=30, pruning_threshold=0.4)`: Solves the problem using A* Search with the given parameters.
- `is_goal(self, state, score)`: Determines if the given state is a goal state based on its score.
- `reconstruct_path(self, came_from, current_state, initial_prompt)`: Reconstructs the path from the initial state to the current state using the came_from dictionary.

Class: MonteCarloTreeofThoughts
This class represents the Monte Carlo Tree Search variant of the Tree of Thoughts search algorithm. It inherits from the TreeofThoughts class and contains the following methods:

- `__init__(self, model, objective="balance")`: Initializes the MonteCarloTreeofThoughts object with the given model and objective.
- `optimize_params(self, num_thoughts, max_steps, max_states)`: Optimizes the search parameters based on the objective.
- `solve(self, initial_prompt, num_thoughts, max_steps, max_states, pruning_threshold)`: Solves the problem using

Monte Carlo Tree Search with the given parameters.
- `monte_carlo_search(self, initial_prompt, num_thoughts, max_steps, max_states, pruning_threshold)`: Performs the Monte Carlo Tree Search with the given parameters.

Class: OptimizedTreeofThoughts
This class represents an optimized version of the Tree of Thoughts search algorithm. It inherits from the TreeofThoughts class and contains the following method:

- `solve(self, x, k=None, T=None, b=None, vth=None, timeout=None, confidence_threshold=None, max_iterations=None, convergence_threshold=None, convergence_count=None)`: Solves the problem using an optimized search algorithm with the given parameters.

e25
- Better prompts for few shot or one shot general learner prompts
- handling for rejected reasoning paths

e24
- Fixed none existent params in solve method of tree of thougths

e23
- Clean up positional args in treeofthoughts.solve()

e22
- removed dotenv

e21
- clean up of tree of thoughts main class
- examples clean up,
- removed parameters for dfs to improve usability
- dotenv installations
-

e19


e18
E18 CLEAN REFRACTOR

e17


e16
e16

e15


e20


e13


e12
no default values implement your own

e11
default values for optimizedTreeofThoughts class to simplify user experience

e10
e

6
v number

5
Much better printing

4
__INIT___.py fix

3
33

2


e9
Set default values for confidence threshold, max iterations, and convergence threshold

e8
Default stopping conditions

Research Analysis
Bugs Solved
Bug: The tot_dfs method did not have the pruning_threshold parameter implemented.

Root Problem: The original implementation of the tot_dfs method did not include dynamic pruning, which could lead to unnecessary exploration of low-quality states.

Fix: Implemented dynamic pruning in the tot_dfs method by adding a pruning_threshold parameter. If the state evaluation value is below the pruning_threshold, the state is pruned, and its children are not explored.

Optimizations and Improvements
Optimization: Introduced a confidence threshold for the evaluation values.

Benefit: By setting a confidence threshold, the algorithm can stop and return the solution when a generated thought has an evaluation value above this threshold. This ensures that the algorithm stops when it has reached a high-quality solution, improving reliability.

Optimization: Set a maximum number of iterations for the algorithm.

Benefit: Limiting the number of iterations prevents the algorithm from running indefinitely if a satisfactory solution is not found. This improves the algorithm's efficiency and ensures that it returns the best solution found so far within a reasonable time frame.

Optimization: Implemented a convergence check to monitor the change in evaluation values between consecutive iterations.

Benefit: By monitoring the change in evaluation values, the algorithm can stop and return the solution when the change is below a certain threshold for a specified number of consecutive iterations. This indicates that the algorithm has likely reached a local optimum and further exploration may not yield significant improvements. This optimization increases the algorithm's efficiency.

Optimization: Implemented parallel processing for generating thoughts and evaluating states.

Benefit: Parallel processing speeds up the execution of the algorithm by utilizing multiple CPU cores to generate thoughts and evaluate states concurrently. This reduces the overall computation time and improves the algorithm's efficiency.

Overall Benefits
The bug fixes and optimizations implemented in the Tree of Thoughts algorithm increase its reliability, efficiency, and speed. By introducing stopping conditions such as confidence threshold, max iterations, and convergence check, the algorithm can now stop when it has reached a satisfactory solution or when further exploration is unlikely to yield significant improvements. Additionally, the implementation of dynamic pruning and parallel processing reduces the search space and computation time, resulting in a faster and more efficient algorithm. These improvements ultimately benefit the user by providing more accurate and timely solutions to their problems.

e7
Research Analysis
Bugs Solved
Bug: The tot_dfs method did not have the pruning_threshold parameter implemented.

Root Problem: The original implementation of the tot_dfs method did not include dynamic pruning, which could lead to unnecessary exploration of low-quality states.

Fix: Implemented dynamic pruning in the tot_dfs method by adding a pruning_threshold parameter. If the state evaluation value is below the pruning_threshold, the state is pruned, and its children are not explored.

Optimizations and Improvements
Optimization: Introduced a confidence threshold for the evaluation values.

Benefit: By setting a confidence threshold, the algorithm can stop and return the solution when a generated thought has an evaluation value above this threshold. This ensures that the algorithm stops when it has reached a high-quality solution, improving reliability.

Optimization: Set a maximum number of iterations for the algorithm.

Benefit: Limiting the number of iterations prevents the algorithm from running indefinitely if a satisfactory solution is not found. This improves the algorithm's efficiency and ensures that it returns the best solution found so far within a reasonable time frame.

Optimization: Implemented a convergence check to monitor the change in evaluation values between consecutive iterations.

Benefit: By monitoring the change in evaluation values, the algorithm can stop and return the solution when the change is below a certain threshold for a specified number of consecutive iterations. This indicates that the algorithm has likely reached a local optimum and further exploration may not yield significant improvements. This optimization increases the algorithm's efficiency.

Optimization: Implemented parallel processing for generating thoughts and evaluating states.

Benefit: Parallel processing speeds up the execution of the algorithm by utilizing multiple CPU cores to generate thoughts and evaluate states concurrently. This reduces the overall computation time and improves the algorithm's efficiency.

Overall Benefits
The bug fixes and optimizations implemented in the Tree of Thoughts algorithm increase its reliability, efficiency, and speed. By introducing stopping conditions such as confidence threshold, max iterations, and convergence check, the algorithm can now stop when it has reached a satisfactory solution or when further exploration is unlikely to yield significant improvements. Additionally, the implementation of dynamic pruning and parallel processing reduces the search space and computation time, resulting in a faster and more efficient algorithm. These improvements ultimately benefit the user by providing more accurate and timely solutions to their problems.

e1

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.