-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode.py
221 lines (112 loc) · 5.3 KB
/
node.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from termcolor import colored
from chains import *
from tools import * #reddit scraper and commeent claner
from branding_rag import RAGbot
### Nodes
def google_search(state):
#agency_type="AI Automation Agency"
product = state["product"]
print(colored(f"\n---GOOOGLE SEARCHER---", 'green'))
results=serper_search(f"branding stratergies for {product} ")
print(results)
web_text = detect_and_scrape_url(results[200:1000])
google_summary_agent= web_summary_chain.invoke({"web_text":web_text, "product": product})
return {"google_search_summary":google_summary_agent}
#google_search(agency_type)
def subreddit_to_search(state):
"""
"""
print(colored(f"---POSSIBLE SUB REDDITS---", 'green'))
product = state["product"]
subreddit_name_agent= subreddit_name_chain.invoke({"product": product})
print(subreddit_name_agent)
return {"sub_reddits_to_search": subreddit_name_agent}
def subreddit_selector(state):
"""
"""
print(colored(f"\n\n ---SUB-REDDITS SELECTOR---", 'green'))
sub_reddits_to_search = state["sub_reddits_to_search"]
product= state["product"]
sub_reddits = search_subreddits(sub_reddits_to_search)
#google_search=web_search_tool.invoke({"query": "latest {location} "})
subreddit_searcher_agent= subreddit_searcher_chain.invoke({"product": product, "sub_reddits":sub_reddits})
print(subreddit_searcher_agent)
print(colored(f"\nSub Reddits:\n\n {subreddit_searcher_agent} ", 'green'))
return {"sub_reddits_to_scrape": subreddit_searcher_agent}
def detect_and_scrape_url(message):
# Regular expression to detect URLs
url_pattern = re.compile(r'(https?://[^\s]+)')
# Search for URLs in the message
match = url_pattern.search(message)
# Check if a URL was found
if match:
url = match.group(0)
# Check if the URL has already been scraped
print(f"\nScraping {url}")
website_text = get_links_and_text(url)
# Store the scraped content
result = {"URL": url, "text": website_text}
else:
result = {}
# Convert to JSON format
result_json = json.dumps(result)
print(result_json)
return result_json
def web_summarizer(state):
"""
"""
print(colored(f"\n---COMPETITION WEB SUMMARY---", 'green'))
product = state["product"]
# summary generation
web_text= detect_and_scrape_url(product)
web_summary_agent= web_summary_chain.invoke({"web_text":web_text, "product": product})
print(web_summary_agent[:300])
return { "web_summary": web_summary_agent}
def market_researcher(state):
"""
"""
print(colored(f"\n---MARKET RESEARCHER---", 'green'))
subreddits_to_scrape = state["sub_reddits_to_scrape"]
product = state["product"]
# summary generation
comments= reddit_comments(subreddits_to_scrape)
print(colored(f"\n---Filtering Comments---", 'blue'))
filtered_comments= filter_comments(comments)
market_researcher_agent= market_researcher_chain.invoke({"filtered_comments":filtered_comments[:1000], "product": product})
return { "market_research": market_researcher_agent}
def branding_rag_search(state):
"""
"""
print(colored(f"\n---BRANDIN RAG---", 'green'))
product = state["product"]
market_research = state["market_research"]
# summary generation
branding_rag_agent= branding_rag_chain.invoke({"market_researcher_agent": market_research, "product": product})
branding_rag = RAGbot.run(branding_rag_agent)
print( branding_rag)
#target_audience= brand_strategist_agent['Potential target audience']
return { "branding_rag": branding_rag_agent}
def strategist(state):
"""
"""
print(colored(f"\n---BRAND STRATEGIST---", 'green'))
market_research = state["market_research"]
product = state["product"]
branding_rag_agent = state["branding_rag"]
# summary generation
brand_strategist_agent= brand_strategist_chain.invoke({"market_researcher_agent": market_research, "product": product, "branding_rag_agent": branding_rag_agent})
print( brand_strategist_agent)
#target_audience= brand_strategist_agent['Potential target audience']
return { "brand_strategy": brand_strategist_agent}
def branding_creator(state):
"""
"""
print(colored(f"\n---BRAND CRAFTER---\n\n", 'green'))
market_research = state["market_research"]
brand_strategy = state["brand_strategy"]
web_summary =state["web_summary"]
google_search_summary = state["google_search_summary"]
product = state["product"]
# summary generation
branding_agent = branding_chain.invoke({"product":product, "google_summary": google_search_summary, "web_summary_agent":web_summary, "market_researcher_agent": market_research,"brand_strategist_agent":brand_strategy})
return { "product":product, "branding": branding_agent}