Skip to content

Commit b27c58c

Browse files
committed
various updates to support new btree process
1 parent 933cb1c commit b27c58c

File tree

6 files changed

+132
-8
lines changed

6 files changed

+132
-8
lines changed

‎avatar2.png

56.9 KB
Loading

‎btree_v3.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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

‎main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,22 @@ def stream_worker(assistant_id, thread_id, event_handler):
163163
overflow-y: auto; /* Enable vertical scrollbar when content exceeds max-height */
164164
box-sizing: border-box; /* Ensure padding and border are included in the height calculation */
165165
}
166+
167+
#actionsnew {
168+
color: #000000;
169+
}
170+
171+
#actions {
172+
color: #000000;
173+
}
166174
"""
167175

168-
theme = gr.themes.Default()
176+
# theme = gr.themes.Default()
169177

170178
# theme = gr.themes.Glass()
171179
# theme = gr.themes.Monochrome()
172180
# theme = gr.themes.Soft()
181+
theme = "gstaff/sketch"
173182

174183
with gr.Blocks(css=custom_css, theme=theme) as demo:
175184
with gr.Tab(label="Playground"):
@@ -225,4 +234,4 @@ def stream_worker(assistant_id, thread_id, event_handler):
225234
if __name__ == "__main__":
226235
demo.launch()
227236
# use the following to launch in browser with a shareable link
228-
#demo.launch(share=True, inbrowser=True)
237+
# demo.launch(share=True, inbrowser=True)

‎playground/assistant_actions/youtube_search.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def __init__(self, search_terms: str, max_results=None):
1616
def _search(self):
1717
encoded_search = urllib.parse.quote_plus(self.search_terms)
1818
BASE_URL = "https://youtube.com"
19-
# This filter shows only videos uploaded today, sorted by relevance and between 4 and 20 minutes long
20-
url = f"{BASE_URL}/results?search_query={encoded_search}&sp=EgIIAQ%253D%253D"
19+
# This filter shows only videos uploaded in the last hour, sorted by relevance
20+
url = f"{BASE_URL}/results?search_query={encoded_search}&sp=EgQIARAB"
2121
response = requests.get(url).text
2222
while "ytInitialData" not in response:
2323
response = requests.get(url).text
@@ -97,13 +97,31 @@ def to_json(self, clear_cache=True):
9797

9898

9999
@agent_action
100-
def search_youtube_videos(query: str, max_results=5):
100+
def search_youtube_videos(query: str, max_results=10):
101101
"""Searches for videos on YouTube based on the query string and returns the video titles and IDs."""
102102
results = YoutubeSearch(query, max_results=max_results)
103103
videos = results.videos
104104
return [{"title": video["title"], "id": video["id"]} for video in videos]
105105

106106

107+
search_cache = []
108+
109+
110+
@agent_action
111+
def search_new_youtube_videos(query: str, max_results=10):
112+
"""Searches for new videos on YouTube based on the query string and returns the video titles and IDs."""
113+
global search_cache
114+
results = YoutubeSearch(query, max_results=max_results)
115+
videos = results.videos
116+
new_videos = [
117+
{"title": video["title"], "id": video["id"]}
118+
for video in videos
119+
if video["id"] not in search_cache
120+
]
121+
search_cache += [video["id"] for video in videos]
122+
return new_videos
123+
124+
107125
@agent_action
108126
def download_transcripts(video_ids):
109127
"""Downloads the transcripts for the given video IDs."""

‎playground/assistants_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def list_assistants(self):
6565
def get_assistant_by_name(self, name):
6666
assistants = self.list_assistants()
6767
for assistant in assistants.data:
68-
if assistant.name.lower().startswith(name.lower()):
68+
if assistant.name and assistant.name.lower().startswith(name.lower()):
6969
return assistant
7070
return None
7171

‎playground/assistants_panel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def assistant_selected_change(assistant_key):
182182
# assistant_files_new = gr.Textbox(
183183
# label="Add Files or Functions", placeholder="+ Files, + Functions"
184184
# )
185-
with gr.Accordion("Actions", open=False):
185+
with gr.Accordion("Actions", open=False, elem_id="actionsnew"):
186186
assistant_actions_new = gr.CheckboxGroup(
187187
label="Actions", choices=action_choices, interactive=True
188188
)
@@ -223,7 +223,7 @@ def assistant_selected_change(assistant_key):
223223
assistant_tools = gr.CheckboxGroup(
224224
label="Tools", choices=["File search", "Code interpreter"]
225225
)
226-
with gr.Accordion("Actions", open=False):
226+
with gr.Accordion("Actions", open=False, elem_id="actions"):
227227
assistant_actions = gr.CheckboxGroup(
228228
label="Actions", choices=action_choices, interactive=True
229229
)

0 commit comments

Comments
 (0)