-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathig_post_planner.py
206 lines (188 loc) · 7.12 KB
/
ig_post_planner.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Use [run_ig_post_planner_example] to run the Instagram Post Planner example.
# It's a blocking function that takes a client and package ID as arguments
# and then prompts the user for input to describe what product they want to market.
from nexus_sdk import (
create_cluster,
create_agent_for_cluster,
create_task,
execute_cluster,
get_cluster_execution_response,
)
class InstagramPostPlanner:
def __init__(
self,
client,
package_id,
model_id,
model_owner_cap_id,
product_website,
product_details,
):
self.client = client
self.package_id = package_id
self.model_id = model_id
self.model_owner_cap_id = model_owner_cap_id
self.product_website = product_website
self.product_details = product_details
def setup_cluster(self):
cluster_id, cluster_owner_cap_id = create_cluster(
self.client,
self.package_id,
"Instagram Post Planning Cluster",
"A cluster for creating Instagram marketing content",
)
return cluster_id, cluster_owner_cap_id
def setup_agents(self, cluster_id, cluster_owner_cap_id):
agent_configs = [
(
"product_competitor",
"Lead Market Analyst",
"Conduct amazing analysis of products and competitors",
),
(
"strategy_planner",
"Chief Marketing Strategist",
"Synthesize insights to formulate incredible marketing strategies",
),
(
"creative_content",
"Creative Content Creator",
"Develop compelling content for social media campaigns",
),
(
"senior_photographer",
"Senior Photographer",
"Take amazing photographs for Instagram ads",
),
(
"chief_creative_director",
"Chief Creative Director",
"Oversee and approve the final content",
),
]
for agent_name, role, goal in agent_configs:
create_agent_for_cluster(
self.client,
self.package_id,
cluster_id,
cluster_owner_cap_id,
self.model_id,
self.model_owner_cap_id,
agent_name,
role,
goal,
f"An AI agent specialized in {role.lower()} for Instagram marketing.",
)
def setup_tasks(self, cluster_id, cluster_owner_cap_id):
tasks = [
(
"product_analysis",
"product_competitor",
f"""
Analyze the product website: {self.product_website}.
Extra details: {self.product_details}.
Identify unique features, benefits, and overall narrative.
Report on key selling points, market appeal, and suggestions for enhancement.
""",
),
(
"competitor_analysis",
"product_competitor",
f"""
Explore competitors of: {self.product_website}.
Identify top 3 competitors and analyze their strategies and positioning.
Provide a detailed comparison to the competitors.
""",
),
(
"campaign_development",
"strategy_planner",
f"""
Create a targeted marketing campaign for: {self.product_website}.
Develop a strategy and creative content ideas that will resonate with the audience.
Include all context about the product and customer.
""",
),
(
"instagram_ad_copy",
"creative_content",
"""
Craft 3 engaging Instagram post copy options.
Make them punchy, captivating, and concise.
Align with the product marketing strategy and highlight unique selling points.
Encourage viewers to take action (visit website, make purchase, learn more).
""",
),
(
"take_photograph",
"senior_photographer",
f"""
Describe 3 amazing photo options for an Instagram post.
Use the product details: {self.product_details}.
Each description should be a paragraph, focusing on capturing audience attention.
Don't show the actual product in the photo.
""",
),
(
"review_photo",
"chief_creative_director",
f"""
Review the 3 photo options from the senior photographer.
Ensure they align with the product goals: {self.product_website}.
Approve, ask clarifying questions, or suggest improvements.
Provide 3 reviewed and improved photo descriptions.
""",
),
]
task_ids = []
for task_name, agent_id, description in tasks:
task_id = create_task(
self.client,
self.package_id,
cluster_id,
cluster_owner_cap_id,
task_name,
agent_id,
description,
f"Complete {task_name} for Instagram post",
description,
"",
)
task_ids.append(task_id)
return task_ids
def run(self):
cluster_id, cluster_owner_cap_id = self.setup_cluster()
self.setup_agents(cluster_id, cluster_owner_cap_id)
self.setup_tasks(cluster_id, cluster_owner_cap_id)
execution_id = execute_cluster(
self.client,
self.package_id,
cluster_id,
f"""
Create an Instagram post for the product: {self.product_website}
Additional details: {self.product_details}
Provide both ad copy options and photo descriptions.
""",
)
if execution_id is None:
return "Cluster execution failed"
print(f"Cluster execution started with ID: {execution_id}")
return get_cluster_execution_response(self.client, execution_id, 600)
# Runs the Instagram Post Planner example using the provided Nexus package ID.
def run_ig_post_planner_example(client, package_id, model_id, mode_owner_cap):
print("## Welcome to the Instagram Post Planner")
print("-------------------------------")
product_website = input(
"What is the product website you want a marketing strategy for? "
)
product_details = input(
"Any extra details about the product and/or the Instagram post you want? "
)
planner = InstagramPostPlanner(
client, package_id, model_id, mode_owner_cap, product_website, product_details
)
result = planner.run()
print("\n\n########################")
print("## Here is the result")
print("########################\n")
print(result)