Skip to content

Commit 6aa960e

Browse files
committed
Update version two of btree
1 parent afac7d0 commit 6aa960e

File tree

4 files changed

+121
-1
lines changed

4 files changed

+121
-1
lines changed

‎btree.py renamed to ‎btree_v1.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
then for each video download the transcript and summarize it for relevance to {search_term}
3434
be sure to include a link to each of the videos,
3535
and then save all summarizations to a file called youtube_transcripts.txt
36+
If you encounter any errors, please return just the word FAILURE.
3637
""",
3738
)
3839
root.add_child(search_youtube_action)
@@ -48,6 +49,7 @@
4849
and include a link to the video, along
4950
with exciting highlights or mentions,
5051
and save it to a file called youtube_twitter_post.txt.
52+
If you encounter any errors, please return just the word FAILURE.
5153
""",
5254
)
5355
root.add_child(write_post_action)
@@ -58,6 +60,7 @@
5860
assistant_instructions="""
5961
Load the file called youtube_twitter_post.txt and post the content to Twitter.
6062
If the content is empty please do not post anything.
63+
If you encounter any errors, please return just the word FAILURE.
6164
""",
6265
)
6366
root.add_child(post_action)
@@ -81,4 +84,4 @@
8184
for i in range(1000):
8285
print(f"Tick {i + 1}")
8386
tree.tick()
84-
time.sleep(300) # Simulate time between ticks
87+
time.sleep(10) # Simulate time between ticks

‎btree_v2.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import time
2+
3+
import py_trees
4+
5+
from playground.behavior_trees import (
6+
create_assistant_action,
7+
create_assistant_condition,
8+
)
9+
10+
search_term = "GPT Agents"
11+
# Create the root node (sequence)
12+
root = py_trees.composites.Sequence("RootSequence", memory=True)
13+
14+
file_condition = create_assistant_condition(
15+
condition_name="Check File Date",
16+
assistant_name="File Manager",
17+
assistant_instructions="""
18+
load the file youtube_current.txt.
19+
it will contain a date and time in the form HH-MM-DD-YY
20+
where HH (01-24) is the hour, DD is the month (01 - 31), MM is the day (01 - 12) and YY is the year (24)
21+
Return just the word SUCCESS if the date and time is earlier than the current date and time,
22+
Return just the word FAILURE if the date and time is the same or later than the current date and time.
23+
""",
24+
)
25+
root.add_child(file_condition)
26+
27+
selector = py_trees.composites.Selector("Search Selector", memory=True)
28+
root.add_child(selector)
29+
30+
search_term = "GPT Agents"
31+
search_youtube_action = create_assistant_action(
32+
action_name="Search YouTube",
33+
assistant_name="YouTube Researcher",
34+
assistant_instructions=f"""
35+
Search Term: {search_term}
36+
Use the query "{search_term}" to search for videos on YouTube.
37+
then for each video download the transcript and summarize it for relevance to {search_term}
38+
be sure to include a link to each of the videos,
39+
and then save all summarizations to a file called youtube_transcripts.txt
40+
If you encounter any errors, please return just the word FAILURE.
41+
""",
42+
)
43+
selector.add_child(search_youtube_action)
44+
45+
search_term = "OpenAI"
46+
search_youtube_action = create_assistant_action(
47+
action_name="Search YouTube",
48+
assistant_name="YouTube Researcher",
49+
assistant_instructions=f"""
50+
Search Term: {search_term}
51+
Use the query "{search_term}" to search for videos on YouTube.
52+
then for each video download the transcript and summarize it for relevance to {search_term}
53+
be sure to include a link to each of the videos,
54+
and then save all summarizations to a file called youtube_transcripts.txt
55+
If you encounter any errors, please return just the word FAILURE.
56+
""",
57+
)
58+
selector.add_child(search_youtube_action)
59+
60+
write_post_action = create_assistant_action(
61+
action_name="Write Post",
62+
assistant_name="Twitter Post Writer",
63+
assistant_instructions="""
64+
Load the file called youtube_transcripts.txt,
65+
analyze the contents for references to search term at the top and then select
66+
the most exciting and relevant video to post on Twitter.
67+
Then write a Twitter post that is relevant to the video,
68+
and include a link to the video, along
69+
with exciting highlights or mentions,
70+
and save it to a file called youtube_twitter_post.txt.
71+
If you encounter any errors, please return just the word FAILURE.
72+
""",
73+
)
74+
root.add_child(write_post_action)
75+
76+
post_action = create_assistant_action(
77+
action_name="Post",
78+
assistant_name="Social Media Assistant",
79+
assistant_instructions="""
80+
Load the file called youtube_twitter_post.txt and post the content to Twitter.
81+
If the content is empty please do not post anything.
82+
If you encounter any errors, please return just the word FAILURE.
83+
""",
84+
)
85+
root.add_child(post_action)
86+
87+
file_write_action = create_assistant_action(
88+
action_name="Write File Date",
89+
assistant_name="File Manager",
90+
assistant_instructions="""
91+
write the current date and time to a file called youtube_current.txt.
92+
Format the date and time in the form HH-MM-DD-YY
93+
where HH (01-24) is the hour, DD is the month (01 - 31), MM is the day (01 - 12) and YY is the year (24)
94+
Be sure to increment the hour by 1 each time this action is called.
95+
""",
96+
)
97+
root.add_child(file_write_action)
98+
99+
# Create the behavior tree
100+
tree = py_trees.trees.BehaviourTree(root)
101+
102+
# Tick the tree to run it
103+
for i in range(1000):
104+
print(f"Tick {i + 1}")
105+
tree.tick()
106+
time.sleep(10) # Simulate time between ticks

‎playground/behavior_trees.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ def long_running_process(self):
4949
agentops.start_session()
5050
result = self.function_wrapper()
5151
print(result)
52+
if "FAILURE" in result["text"]:
53+
agentops.end_session("Fail")
54+
print("%s: Thread completed with failure." % self.name)
55+
return
5256

5357
if self.is_condition:
5458
self.thread_success = "SUCCESS" in result["text"]

‎tests/test_youtube_actions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from playground.assistant_actions.youtube_search import search_youtube_videos
2+
3+
4+
def test_youtube_search():
5+
videos = search_youtube_videos("GPT Agents")
6+
7+
assert len(videos) > 0

0 commit comments

Comments
 (0)