forked from kyegomez/tree-of-thoughts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuggingfaceExample.py
More file actions
37 lines (27 loc) · 1.17 KB
/
huggingfaceExample.py
File metadata and controls
37 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from tree_of_thoughts.treeofthoughts import OpenAILanguageModel, GuidanceOpenAILanguageModel, TreeofThoughts, OptimizedOpenAILanguageModel, OptimizedTreeofThoughts, HuggingLanguageModel
model_name="gpt"
model = HuggingLanguageModel(model_name,
model_Tokenizer="gpt2",
verbose=True)
#choose search algorithm('BFS' or 'DFS')
search_algorithm = "BFS"
#cot or propose
strategy="cot"
# value or vote
evaluation_strategy = "value"
gpt2_model = HuggingLanguageModel(model_name)
tree_of_thoughts= OptimizedTreeofThoughts(model, search_algorithm)
input_problem = "use 4 numbers and basic arithmetic operations (+-*/) to obtain 24"
k = 5
T = 3
b = 5
vth = 0.5
timeout = 10
confidence = 0.8 #cmodel is confident on performance
max_iterations = 40 #tree branh nodes
convergence_threshold = 0.01
convergence_count = 5
#call the solve emthod with the input problem and other params
solution = tree_of_thoughts.solve(input_problem, k, T, b, vth, timeout, confidence, max_iterations, convergence_threshold, convergence_count)
#use the solution in your production environment
print(f"solution: {solution}")