forked from kyegomez/tree-of-thoughts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipelinehuggingface.py
50 lines (31 loc) · 1.5 KB
/
pipelinehuggingface.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
from tree_of_thoughts.treeofthoughts import HFPipelineModel, OptimizedTreeofThoughts
from tree_of_thoughts.treeofthoughts import OpenAILanguageModel, GuidanceOpenAILanguageModel, TreeofThoughts, OptimizedOpenAILanguageModel, OptimizedTreeofThoughts, HuggingLanguageModel
model_name="gpt2"
gpt2_pipeline_model = HFPipelineModel(model_name)
tree_of_thoughts = OptimizedTreeofThoughts(gpt2_pipeline_model, search_algorithm="DFS")
# from transformers import AutoModelForCausalLM, AutoTokenizer
# # Initialize the HuggingLanguageModel with the GPT-2 model
# model_name = "gpt2"
# 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"
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
solution = tree_of_thoughts.solve(input_problem)
# `k, T, b, vth, timeout, confidence_threshold=confidence, max_iterations=max_iterations, convergence_threshold=convergence_threshold, convergence_count=convergence_count)
#use the solution in your production environment
print(f"solution: {solution}")