|
| 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 |
0 commit comments