-
Notifications
You must be signed in to change notification settings - Fork 346
/
huggingface_example.py
71 lines (58 loc) · 1.56 KB
/
huggingface_example.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
from tree_of_thoughts import ToTAgent, MonteCarloSearch
from dotenv import load_dotenv
from swarms import Agent, HuggingfaceLLM
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize an agent from swarms
agent = Agent(
agent_name="tree_of_thoughts",
agent_description=(
"This agent uses the tree_of_thoughts library to generate thoughts."
),
system_prompt=None,
llm=HuggingfaceLLM(
"EleutherAI/gpt-neo-2.7B",
),
)
# Initialize the ToTAgent class with the API key
model = ToTAgent(
agent,
strategy="cot",
evaluation_strategy="value",
enable_react=True,
k=3,
)
# Initialize the MonteCarloSearch class with the model
tree_of_thoughts = MonteCarloSearch(model)
# Define the initial prompt
initial_prompt = """
Input: 2 8 8 14
Possible next steps:
2 + 8 = 10 (left: 8 10 14)
8 / 2 = 4 (left: 4 8 14)
14 + 2 = 16 (left: 8 8 16)
2 * 8 = 16 (left: 8 14 16)
8 - 2 = 6 (left: 6 8 14)
14 - 8 = 6 (left: 2 6 8)
14 / 2 = 7 (left: 7 8 8)
14 - 2 = 12 (left: 8 8 12)
Input: use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation
Possible next steps:
"""
# Define the number of thoughts to generate
num_thoughts = 1
max_steps = 3
max_states = 4
pruning_threshold = 0.5
# Generate the thoughts
solution = tree_of_thoughts.solve(
initial_prompt=initial_prompt,
num_thoughts=num_thoughts,
max_steps=max_steps,
max_states=max_states,
pruning_threshold=pruning_threshold,
# sleep_time=sleep_time
)
print(f"Solution: {solution}")