|
| 1 | +import time |
| 2 | + |
| 3 | +import py_trees |
| 4 | + |
| 5 | +from playground.behavior_trees import ( |
| 6 | + create_assistant_action, |
| 7 | +) |
| 8 | + |
| 9 | +search_term = "GPT Agents" |
| 10 | +# Create the root node (sequence) |
| 11 | +root = py_trees.composites.Sequence("RootSequence", memory=True) |
| 12 | + |
| 13 | +selector = py_trees.composites.Selector("Search Selector", memory=True) |
| 14 | +root.add_child(selector) |
| 15 | + |
| 16 | +search_term = "GPT Agents" |
| 17 | +search_youtube_action = create_assistant_action( |
| 18 | + action_name=f"Search YouTube({search_term})", |
| 19 | + assistant_name="YouTube Researcher v2", |
| 20 | + assistant_instructions=f""" |
| 21 | + Search Term: {search_term} |
| 22 | + Use the query "{search_term}" to search for videos on YouTube. |
| 23 | + then for each video download the transcript and summarize it for relevance to {search_term} |
| 24 | + be sure to include a link to each of the videos, |
| 25 | + and then save all summarizations to a file called youtube_transcripts.txt |
| 26 | + If you encounter any errors, please return just the word FAILURE. |
| 27 | + """, |
| 28 | +) |
| 29 | +selector.add_child(search_youtube_action) |
| 30 | + |
| 31 | +search_term = "OpenAI" |
| 32 | +search_youtube_action = create_assistant_action( |
| 33 | + action_name=f"Search YouTube({search_term})", |
| 34 | + assistant_name="YouTube Researcher v2", |
| 35 | + assistant_instructions=f""" |
| 36 | + Search Term: {search_term} |
| 37 | + Use the query "{search_term}" to search for videos on YouTube. |
| 38 | + then for each video download the transcript and summarize it for relevance to {search_term} |
| 39 | + be sure to include a link to each of the videos, |
| 40 | + and then save all summarizations to a file called youtube_transcripts.txt |
| 41 | + If you encounter any errors, please return just the word FAILURE. |
| 42 | + """, |
| 43 | +) |
| 44 | +selector.add_child(search_youtube_action) |
| 45 | + |
| 46 | +search_term = "GPT-4o" |
| 47 | +search_youtube_action = create_assistant_action( |
| 48 | + action_name=f"Search YouTube({search_term})", |
| 49 | + assistant_name="YouTube Researcher v2", |
| 50 | + assistant_instructions=f""" |
| 51 | + Search Term: {search_term} |
| 52 | + Use the query "{search_term}" to search for videos on YouTube. |
| 53 | + then for each video download the transcript and summarize it for relevance to {search_term} |
| 54 | + be sure to include a link to each of the videos, |
| 55 | + and then save all summarizations to a file called youtube_transcripts.txt |
| 56 | + If you encounter any errors, please return just the word FAILURE. |
| 57 | + """, |
| 58 | +) |
| 59 | +selector.add_child(search_youtube_action) |
| 60 | + |
| 61 | +write_post_action = create_assistant_action( |
| 62 | + action_name="Write Post", |
| 63 | + assistant_name="Twitter Post Writer", |
| 64 | + assistant_instructions=""" |
| 65 | + Load the file called youtube_transcripts.txt, |
| 66 | + analyze the contents for references to search term at the top and then select |
| 67 | + the most exciting and relevant video related to: |
| 68 | + eductional, entertaining, or informative, to post on Twitter. |
| 69 | + Then write a Twitter post that is relevant to the video, |
| 70 | + and include a link to the video, along |
| 71 | + with exciting highlights or mentions, |
| 72 | + and save it to a file called youtube_twitter_post.txt. |
| 73 | + If you encounter any errors, please return just the word FAILURE. |
| 74 | + """, |
| 75 | +) |
| 76 | +root.add_child(write_post_action) |
| 77 | + |
| 78 | +post_action = create_assistant_action( |
| 79 | + action_name="Post", |
| 80 | + assistant_name="Social Media Assistant", |
| 81 | + assistant_instructions=""" |
| 82 | + Load the file called youtube_twitter_post.txt and post the content to Twitter. |
| 83 | + If the content is empty please do not post anything. |
| 84 | + If you encounter any errors, please return just the word FAILURE. |
| 85 | + """, |
| 86 | +) |
| 87 | +root.add_child(post_action) |
| 88 | + |
| 89 | + |
| 90 | +# Create the behavior tree |
| 91 | +tree = py_trees.trees.BehaviourTree(root) |
| 92 | + |
| 93 | +# Tick the tree to run it |
| 94 | +for i in range(1000): |
| 95 | + print(f"Tick {i + 1}") |
| 96 | + tree.tick() |
| 97 | + time.sleep(30) # Simulate time between ticks |
0 commit comments