Skip to content

Commit

Permalink
Updating tree of thoughts
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 28, 2023
1 parent 0d2ebbe commit 3d038c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
12 changes: 4 additions & 8 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from tree_of_thoughts.openaiModels import OpenAILanguageModel, OptimizedOpenAILanguageModel
from tree_of_thoughts.treeofthoughts import TreeofThoughts, OptimizedTreeofThoughts
from tree_of_thoughts.treeofthoughts import TreeofThoughts

use_v2 = True
api_key=""
api_base= "" # leave it blank if you simply use default openai api url
api_model= "gpt-3.5-turbo"
Expand All @@ -16,12 +15,9 @@
# value or vote
evaluation_strategy = "value"

if not use_v2:
#create an instance of the tree of thoughts class v1
tree_of_thoughts = TreeofThoughts(model, search_algorithm)
else:
#or v2 -> dynamic beam width -< adjust the beam width [b] dynamically based on the search depth quality of the generated thoughts
tree_of_thoughts= OptimizedTreeofThoughts(model, search_algorithm)

tree_of_thoughts = TreeofThoughts(model, search_algorithm)


input_problem = "use 4 numbers and basic arithmetic operations (+-*/) to obtain 24"
k = 5
Expand Down
Binary file modified tree_of_thoughts/__pycache__/treeofthoughts.cpython-39.pyc
Binary file not shown.
23 changes: 2 additions & 21 deletions tree_of_thoughts/treeofthoughts.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,6 @@ def print_tree(self, node, depth=0):


#does not output state after each thought --- idk why -- needs work
class OptimizedTreeofThoughts(TreeofThoughts):
def 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):
start_time = time.time()
print(f'Start time {start_time}')
if self.search_algorithm == 'BFS':
while timeout is None or time.time() - start_time < timeout:
result = self.tot_bfs(x, k, T, b, vth)
print(f'result in optimized tree of thoughts: {result}')
if result:
return result
elif self.search_algorithm == 'DFS':
while timeout is None or time.time() - start_time < timeout:
result = self.tot_dfs(x, k, T, vth, confidence_threshold=confidence_threshold, max_iterations=max_iterations, convergence_threshold=convergence_threshold, convergence_count=convergence_count)
if result:
return result
else:
raise ValueError("Invalid search algorithm. Choose 'BFS' or 'DFS'.")



if __name__ == '__main__':

Expand Down Expand Up @@ -266,9 +247,9 @@ def solve(self, x, k=None, T=None, b=None, vth=None, timeout=None, confidence_th
args = parser.parse_args()
print(args)

model = OptimizedOpenAILanguageModel('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')
model = OptimizedOpenAILanguageModel('sk-')
#solve the problem using the tree of thoughts class
optimized_tree_of_thoughts = OptimizedTreeofThoughts(model, search_algorithm=args.search_algorithm)
optimized_tree_of_thoughts = TreeofThoughts(model, search_algorithm=args.search_algorithm)

#solve the porblem using tree of thoughts problem helper
best_state = optimized_tree_of_thoughts.solve(args.problem, k=args.k, T=args.T, b=args.b, vth=args.vth)
Expand Down

0 comments on commit 3d038c7

Please sign in to comment.