subashpoudel commited on
Commit
a6ebaaf
·
1 Parent(s): eb40d68

Next commit after refinements

Browse files
__pycache__/main.cpython-312.pyc CHANGED
Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ
 
brainstroming_agent/__pycache__/agent.cpython-312.pyc CHANGED
Binary files a/brainstroming_agent/__pycache__/agent.cpython-312.pyc and b/brainstroming_agent/__pycache__/agent.cpython-312.pyc differ
 
brainstroming_agent/agent.py CHANGED
@@ -1,6 +1,6 @@
1
  from langgraph.graph import StateGraph, START, END
2
  from .utils.state import State
3
- from .utils.nodes import retrieve, generate_story, generate_brainstroming , route_after_selection, select_preferred_topics,caption_image
4
  from langgraph.checkpoint.memory import MemorySaver
5
 
6
  memory = MemorySaver()
 
1
  from langgraph.graph import StateGraph, START, END
2
  from .utils.state import State
3
+ from .utils.nodes import retrieve, generate_story, generate_brainstroming , select_preferred_topics,caption_image
4
  from langgraph.checkpoint.memory import MemorySaver
5
 
6
  memory = MemorySaver()
brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc CHANGED
Binary files a/brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc differ
 
brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc CHANGED
Binary files a/brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc differ
 
brainstroming_agent/utils/__pycache__/tools.cpython-312.pyc CHANGED
Binary files a/brainstroming_agent/utils/__pycache__/tools.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/tools.cpython-312.pyc differ
 
brainstroming_agent/utils/nodes.py CHANGED
@@ -54,9 +54,10 @@ def caption_image(state: State) -> State:
54
  def retrieve(state: State) -> State:
55
  print('Moving to retrieval process')
56
  retrievals=[]
 
57
  if len(state.latest_preferred_topics)==0:
58
  for topic in state.topic: # Loop through each topic
59
- embedded_query = ST.encode(topic) # Embed each topic
60
  data = load_influencer_data()
61
  scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
62
 
@@ -70,7 +71,7 @@ def retrieve(state: State) -> State:
70
  print('The preferred_topics are:',state.latest_preferred_topics)
71
  state.preferred_topics.append(state.latest_preferred_topics)
72
  for topic in state.preferred_topics[-1]: # Loop through each topic
73
- embedded_query = ST.encode(topic) # Embed each topic
74
  data = load_influencer_data()
75
  scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
76
 
@@ -102,6 +103,7 @@ def generate_story(state:State)-> State:
102
 
103
  response = react_agent.invoke({'messages':messages})
104
  response = response['messages'][-1].content
 
105
  state.stories.append(response)
106
  # return State(messages="Story generated", topic=state.topic,stories=state.stories)
107
  return state
 
54
  def retrieve(state: State) -> State:
55
  print('Moving to retrieval process')
56
  retrievals=[]
57
+ query_prompt = 'Represent this sentence for searching relevant passages: '
58
  if len(state.latest_preferred_topics)==0:
59
  for topic in state.topic: # Loop through each topic
60
+ embedded_query = ST.encode(topic+query_prompt) # Embed each topic
61
  data = load_influencer_data()
62
  scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
63
 
 
71
  print('The preferred_topics are:',state.latest_preferred_topics)
72
  state.preferred_topics.append(state.latest_preferred_topics)
73
  for topic in state.preferred_topics[-1]: # Loop through each topic
74
+ embedded_query = ST.encode(topic+query_prompt) # Embed each topic
75
  data = load_influencer_data()
76
  scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
77
 
 
103
 
104
  response = react_agent.invoke({'messages':messages})
105
  response = response['messages'][-1].content
106
+ print('The geenrated story: ', response)
107
  state.stories.append(response)
108
  # return State(messages="Story generated", topic=state.topic,stories=state.stories)
109
  return state
brainstroming_agent/utils/prompts.py CHANGED
@@ -79,23 +79,23 @@ Now, generate the final storyline for the video topic..
79
 
80
  def brainstroming_prompt(state):
81
  return f'''
82
- You are a creative consultant tasked with enhancing a storyline.
 
83
 
84
- Suggest **4 unique and creative enhancements** to the following storyline. Each suggestion must:
85
- - Be just 1 sentence long”
86
- - Add something **new or different** (not rephrasing what’s already in the story)
87
- - Improve the storyline’s **engagement, emotional depth, or audience appeal**
88
 
89
- Output format: a numbered list from 1 to 4.
90
 
91
- Here’s an example for a restaurant promo storyline:
92
- 1. Showcase the chef preparing a signature dish.
93
- 2. Add a sequence of customers sharing their experiences at the restaurant.
94
- 3. Highlight the farm-to-table sourcing of ingredients with a short segment showing local farms.
95
- 4. Include a time-lapse of the restaurant transforming from day to night, capturing its unique ambiance.
 
96
 
97
- Now, here is the current storyline you need to enhance:
98
 
 
99
  "{state.stories[-1]}"
100
  '''
101
 
@@ -110,95 +110,3 @@ I want to create a detailed storyline for a video in the given topic. You have t
110
  **Final Reminder** You have to strongly focus on these topics while creating the storyline: {[item for sublist in final_state['preferred_topics'] for item in sublist]}'''
111
  )
112
 
113
-
114
- introduction_prompt = '''
115
- You are a business assistant who collects only valid and relevant data.
116
- Your job is to gather details from business owners in a friendly and conversational manner to understand their business better. Ask in very easy and short way.
117
-
118
- We need these details:
119
- 1. Business Type (e.g., e-commerce, SaaS, consulting),
120
- 2. Platform(s) used (e.g., website, app, Instagram),
121
- 3. Target Audience (who are their customers or clients),
122
- 4. Business Goals (short-term or long-term objectives),
123
- 5. Offerings (products or services they provide),
124
- 6. Challenges faced (any current business problems or limitations).
125
-
126
- Keep interacting until all valid details are collected.
127
-
128
- VERY IMPORTANT: Once all valid details are received, say: '**Thanks for providing all your required business details.**'
129
-
130
- '''
131
- business_interaction_prompt = '''
132
- You are a strict assistant designed to help users **only by using data retrieved from the influencer retrieval tool**. You are not allowed to answer any query using your own knowledge or assumptions — you must respond **exclusively based on the retrieved influencer data** provided by the tool.
133
-
134
- For **every user query** — whether it's about business, lifestyle, motivation, strategy, ideas, challenges, or any general topic — you must:
135
- - **Always invoke the tool**
136
- - Analyze the influencer data it returns
137
- - Generate your response **only using that data**
138
-
139
- Your response must include:
140
- - **The names of the influencers**
141
- - **What those influencers are doing or sharing**
142
- - **How their content or insights relate to the user's query**
143
-
144
- You are strictly forbidden from making up any information, speculating, or answering without the tool’s data. If no relevant data is retrieved from the tool, reply clearly that you cannot generate a response without influencer data.
145
- Keep the response short and precise. Don't make it long as it will be time consuming to read. Just grab the response of the user query from the tool and give. No more out of the box explanations.
146
- '''
147
-
148
-
149
- def details_extract_prompt(interactions):
150
- return( f'''Extract the following details of the business from the conversation in the form of dictionary. Don't give any further explanations either in the beginning or ending of the response.
151
- I want the response **direct** in the form of python dictionary. The details you have to extract are:\n
152
- 1. Business Type (e.g., e-commerce, SaaS, consulting),
153
- 2. Platform(s) used (e.g., website, app, Instagram),
154
- 3. Target Audience (who are their customers or clients),
155
- 4. Business Goals (short-term or long-term objectives),
156
- 5. Offerings (products or services they provide),
157
- 6. Challenges faced (any current business problems or limitations).
158
-
159
- Now, start doing your work:\n
160
- The conversation is:\n{interactions}\n
161
-
162
-
163
- ''')
164
-
165
- def business_retrieval_prompt(user_message, retrievals):
166
- return f'''
167
- You are a professional AI assistant helping users understand how influencers can support their business. You will be given:
168
-
169
- - A **user message**
170
- - A list of **retrieved influencer data**
171
-
172
- Your job is to:
173
- 1. **First**, analyze the user message and decide if it is actually a business-related question or query that could be answered using influencer content.
174
- - If the message is just a casual greeting like “Hi”, “Hello”, “How are you?”, or not business-related (e.g., “Who are you?”, “Tell me a joke”), then **do NOT use the retrievals** and just respond to the user naturally.
175
- 2. **If the message is business-related**, proceed to analyze the influencer data and explain how each influencer might support the business based only on their content.
176
-
177
- --- USER MESSAGE ---
178
- {user_message}
179
-
180
- --- START OF RETRIEVALS ---
181
- {retrievals}
182
- --- END OF RETRIEVALS ---
183
-
184
- Rules:
185
- - If the user message is **not relevant to influencer or business help**, politely respond in a general helpful way and ignore the retrievals.
186
- - If the message **is relevant**, then:
187
- - Identify which influencer stories seem relevant to the query.
188
- - Explain what the influencers are promoting and how it might help the business.
189
- - You **must mention influencer usernames** and only use what is in the retrievals.
190
- - You are not allowed to invent, guess, or add information outside the retrievals.
191
-
192
- Keep your response:
193
- - Context-aware
194
- - Grounded only in retrievals if relevant
195
- - Helpful and brief
196
- '''
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
 
79
 
80
  def brainstroming_prompt(state):
81
  return f'''
82
+ You are a creative consultant who can diversify the video's story for brainstorming.
83
+ I have a detailed video story. I want to brainstorm creative ways to diversify or expand it into different directions.
84
 
85
+ Please suggest 4 highly creative, diverse, and practical short sentence ideas that show how the story can be visually or narratively diversified. These should not be abstract "what if" scenarios, but specific ways to evolve or branch the storyline — such as adding new scenes, shifting perspectives, integrating emotional moments, or enhancing visual storytelling.
 
 
 
86
 
87
+ Each idea should be a small sentence and propose a concrete way the video could take a new direction or include a compelling new element.
88
 
89
+ For instance: If the storyline is about creating a promotional video for a restaurant, the brainstorming topics might include:
90
+ - showcase the chef preparing a signature dish.
91
+ - add a sequence of customers sharing their experiences at the restaurant.
92
+ - highlight the farm-to-table sourcing of ingredients with a short segment showing local farms.
93
+ - include a time-lapse of the restaurant transforming from day to night, capturing its unique ambiance.
94
+ - feature a quick interview with the owner sharing the story behind the restaurant.
95
 
96
+ **Remember**: Don't include the ideas or topics that are already presented in the video story.
97
 
98
+ Now, here is the detailed video story:
99
  "{state.stories[-1]}"
100
  '''
101
 
 
110
  **Final Reminder** You have to strongly focus on these topics while creating the storyline: {[item for sublist in final_state['preferred_topics'] for item in sublist]}'''
111
  )
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
brainstroming_agent/utils/tools.py CHANGED
@@ -16,7 +16,7 @@ import pandas as pd
16
  from .state import QueryFormatter
17
 
18
  os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
19
- @tool("influencer's data-retrieval-tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
20
  def retrieve_tool(video_topic):
21
  '''
22
  Always invoke this tool.
@@ -39,7 +39,7 @@ def retrieve_tool(video_topic):
39
 
40
  # === Encode the query and search ===
41
  query_embedding = ST.encode(str(video_topic)).reshape(1, -1).astype('float32')
42
- top_k=7
43
  distances, indices = index.search(query_embedding, top_k)
44
 
45
 
@@ -51,7 +51,7 @@ def retrieve_tool(video_topic):
51
  'rank': i + 1,
52
  'username': df.iloc[idx]['username'],
53
  'story': df.iloc[idx]['story'],
54
- 'visible_text_or_brandings': df.iloc[idx]['story'],
55
  'likesCount': df.iloc[idx]['likesCount'],
56
  'commentCount': df.iloc[idx]['commentCount'],
57
  }
 
16
  from .state import QueryFormatter
17
 
18
  os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
19
+ @tool("influencers_data_retrieval_tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
20
  def retrieve_tool(video_topic):
21
  '''
22
  Always invoke this tool.
 
39
 
40
  # === Encode the query and search ===
41
  query_embedding = ST.encode(str(video_topic)).reshape(1, -1).astype('float32')
42
+ top_k=3
43
  distances, indices = index.search(query_embedding, top_k)
44
 
45
 
 
51
  'rank': i + 1,
52
  'username': df.iloc[idx]['username'],
53
  'story': df.iloc[idx]['story'],
54
+ 'visible_text_or_brandings': df.iloc[idx]['visible_texts_or_brandings'],
55
  'likesCount': df.iloc[idx]['likesCount'],
56
  'commentCount': df.iloc[idx]['commentCount'],
57
  }
ideation_agent/__pycache__/agent.cpython-312.pyc CHANGED
Binary files a/ideation_agent/__pycache__/agent.cpython-312.pyc and b/ideation_agent/__pycache__/agent.cpython-312.pyc differ
 
ideation_agent/agent.py CHANGED
@@ -1,6 +1,8 @@
1
  from langgraph.graph import StateGraph, START, END
2
  from .utils.state import State
3
  from .utils.nodes import ideator , critic , improver , validator1 , validator2 , validator3 , validator4 , route1_after_validation , route2_after_validation , route3_after_validation , route4_after_validation
 
 
4
 
5
 
6
  def ideation_graph():
@@ -29,4 +31,4 @@ def ideation_graph():
29
  graph_builder.add_conditional_edges("validator3", route3_after_validation,{False:'improver',True:'validator4'})
30
  graph_builder.add_conditional_edges("validator4", route4_after_validation,{False:'improver',True:END})
31
 
32
- return graph_builder.compile()
 
1
  from langgraph.graph import StateGraph, START, END
2
  from .utils.state import State
3
  from .utils.nodes import ideator , critic , improver , validator1 , validator2 , validator3 , validator4 , route1_after_validation , route2_after_validation , route3_after_validation , route4_after_validation
4
+ from langgraph.checkpoint.memory import MemorySaver
5
+ memory = MemorySaver()
6
 
7
 
8
  def ideation_graph():
 
31
  graph_builder.add_conditional_edges("validator3", route3_after_validation,{False:'improver',True:'validator4'})
32
  graph_builder.add_conditional_edges("validator4", route4_after_validation,{False:'improver',True:END})
33
 
34
+ return graph_builder.compile(checkpointer=memory)
ideation_agent/utils/__pycache__/nodes.cpython-312.pyc CHANGED
Binary files a/ideation_agent/utils/__pycache__/nodes.cpython-312.pyc and b/ideation_agent/utils/__pycache__/nodes.cpython-312.pyc differ
 
ideation_agent/utils/__pycache__/prompts.cpython-312.pyc CHANGED
Binary files a/ideation_agent/utils/__pycache__/prompts.cpython-312.pyc and b/ideation_agent/utils/__pycache__/prompts.cpython-312.pyc differ
 
ideation_agent/utils/__pycache__/state.cpython-312.pyc CHANGED
Binary files a/ideation_agent/utils/__pycache__/state.cpython-312.pyc and b/ideation_agent/utils/__pycache__/state.cpython-312.pyc differ
 
ideation_agent/utils/__pycache__/tools.cpython-312.pyc CHANGED
Binary files a/ideation_agent/utils/__pycache__/tools.cpython-312.pyc and b/ideation_agent/utils/__pycache__/tools.cpython-312.pyc differ
 
ideation_agent/utils/nodes.py CHANGED
@@ -5,138 +5,157 @@ from utils.models_loader import ideator_llm, critic_llm , improver_llm , validat
5
  from langchain_core.messages import SystemMessage , HumanMessage
6
  from .prompts import ideator_prompt , critic_prompt , improver_prompt , validator_prompt
7
 
8
- def ideator(state:State):
9
- tools=[retrieve_tool]
10
- react_agent=create_react_agent(
11
  model=ideator_llm,
12
- tools=tools
 
 
 
 
13
  )
14
 
15
- template = ideator_prompt(state)
 
 
 
16
 
17
- messages = [SystemMessage(content=template),
18
- HumanMessage(content=f'''The topic of the video is:\n{state.topic}\n''')]
19
 
20
- response = react_agent.invoke({'messages':messages})
21
- response = response['messages'][-1].content
22
- print('Ideator Response:',response)
23
- state.ideator_response = response
24
- print('Ideator Generated the story')
25
- return state
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  def critic(state:State):
28
- tools=[retrieve_tool]
29
- react_agent=create_react_agent(
30
- model=critic_llm,
31
- tools=tools
32
- )
33
-
34
  template = critic_prompt(state)
35
  messages = [SystemMessage(content=template),
36
- HumanMessage(content=f'''The topic of the video is:\n{state.topic}\n. The business_details is\n{state.business_details}\n''')]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
- response = react_agent.invoke({'messages':messages})
39
- response = response['messages'][-1].content
40
- print('Critic Response:',response)
41
-
42
- state.critic_response = response
43
- print('Critic Evaluated the story')
44
-
45
- return state
46
 
47
  def improver(state:State):
48
- react_agent=create_react_agent(
49
- model=improver_llm,
50
- tools=[]
51
- )
52
-
53
  template = improver_prompt(state)
54
  messages = [SystemMessage(content=template),
55
- HumanMessage(content=f'''The topic of the video is:\n{state.topic}\n The business_details is:\n{state.business_details}''')]
56
-
57
- response = react_agent.invoke({'messages':messages})
58
- response = response['messages'][-1].content
59
- print('Improver Response:',response)
60
- state.improver_response = response
61
- print('Improver Improved the story')
62
- return state
 
 
 
 
 
 
 
 
63
 
64
  def validator1(state:State):
65
  template = validator_prompt(state)
66
  messages = [SystemMessage(content=template),
67
- HumanMessage(content=f'''The topic of the video is:\n{state.topic}\n The business_details is:\n{state.business_details}''')]
68
 
69
  response = validator_llm.with_structured_output(ValidationFormatter).invoke(messages)
70
  print(f'Validator 1 response: {response}')
71
- state.validator1_response = response.result
72
- print('The state check:',state.validator1_response)
73
  if 'not validated' in response.result:
74
- state.disagreement_reason = response.reason
75
  return state
76
 
77
  def validator2(state:State):
78
  template = validator_prompt(state)
79
  messages = [SystemMessage(content=template),
80
- HumanMessage(content=f'''The topic of the video is:\n{state.topic}\n The business_details is:\n{state.business_details}''')]
81
 
82
  response = ideator_llm.with_structured_output(ValidationFormatter).invoke(messages)
83
  print(f'Validator 2 response: {response}')
84
- state.validator2_response = response.result
85
- print('The state check:',state.validator1_response)
86
  if 'not validated' in response.result:
87
- state.disagreement_reason = response.reason
88
  return state
89
 
90
  def validator3(state:State):
91
  template = validator_prompt(state)
92
  messages = [SystemMessage(content=template),
93
- HumanMessage(content=f'''The topic of the video is:\n{state.topic}\n The business_details is:\n{state.business_details}''')]
94
 
95
  response = critic_llm.with_structured_output(ValidationFormatter).invoke(messages)
96
  print(f'Validator 3 response: {response}')
97
- state.validator3_response = response.result
98
- print('The state check:',state.validator1_response)
99
  if 'not validated' in response.result:
100
- state.disagreement_reason = response.reason
101
  return state
102
 
103
  def validator4(state:State):
104
  template = validator_prompt(state)
105
  messages = [SystemMessage(content=template),
106
- HumanMessage(content=f'''The topic of the video is:\n{state.topic}\n The business_details is:\n{state.business_details}''')]
107
 
108
  response = improver_llm.with_structured_output(ValidationFormatter).invoke(messages)
109
  print(f'Validator 4 response: {response}')
110
- state.validator4_response = response.result
111
- print('The state check:',state.validator1_response)
112
  if 'not validated' in response.result:
113
- state.topic=None
114
- state.disagreement_reason = response.reason
115
  return state
116
 
117
  def route1_after_validation(state:State):
118
- if 'not validated' in state.validator1_response:
119
  return False
120
  else:
121
  return True
122
 
123
 
124
  def route2_after_validation(state:State):
125
- if 'not validated' in state.validator2_response:
126
  return False
127
  else:
128
  return True
129
 
130
 
131
  def route3_after_validation(state:State):
132
- if 'not validated' in state.validator3_response:
133
  return False
134
  else:
135
  return True
136
 
137
 
138
  def route4_after_validation(state:State):
139
- if 'not validated' in state.validator4_response:
140
  return False
141
  else:
142
  return True
 
5
  from langchain_core.messages import SystemMessage , HumanMessage
6
  from .prompts import ideator_prompt , critic_prompt , improver_prompt , validator_prompt
7
 
8
+
9
+ ideator_agent = create_react_agent(
 
10
  model=ideator_llm,
11
+ tools=[retrieve_tool]
12
+ )
13
+ critic_agent = create_react_agent(
14
+ model=critic_llm,
15
+ tools=[retrieve_tool]
16
  )
17
 
18
+ improver_agent = create_react_agent(
19
+ model=improver_llm,
20
+ tools=[]
21
+ )
22
 
 
 
23
 
24
+ def ideator(state:State):
25
+ template = ideator_prompt(state)
26
+ messages = [SystemMessage(content=template),
27
+ HumanMessage(content=f'''The topic of the video is:\n{state.topic[-1]}\n''')]
28
+ print('Ideator prompt:', messages)
29
+ try:
30
+ response = ideator_agent.invoke({'messages':messages})
31
+ response = response['messages'][-1].content
32
+ print('Ideator Response:',response)
33
+ state.ideator_response.append(response)
34
+ print('Ideator Generated the story')
35
+ return state
36
+
37
+ except:
38
+ response = ideator_llm.invoke(messages)
39
+ print('Ideator backup Response:',response.content)
40
+ state.ideator_response.append(response.content)
41
+ return state
42
 
43
  def critic(state:State):
 
 
 
 
 
 
44
  template = critic_prompt(state)
45
  messages = [SystemMessage(content=template),
46
+ HumanMessage(content=f'''The topic of the video is:\n{state.topic[-1]}\n. The business_details is\n{state.business_details[-1]}\n''')]
47
+ print('Critic prompt:', messages)
48
+
49
+ try:
50
+ response = critic_agent.invoke({'messages':messages})
51
+ response = response['messages'][-1].content
52
+ print('Critic Response:',response)
53
+ state.critic_response.append(response)
54
+ print('Critic Evaluated the story')
55
+ return state
56
+
57
+ except:
58
+ response = critic_llm.invoke(messages)
59
+ print('Critic backup Response:',response.content)
60
+ state.critic_response.append(response.content)
61
+ return state
62
 
 
 
 
 
 
 
 
 
63
 
64
  def improver(state:State):
 
 
 
 
 
65
  template = improver_prompt(state)
66
  messages = [SystemMessage(content=template),
67
+ HumanMessage(content=f'''The topic of the video is:\n{state.topic[-1]}\n The business_details is:\n{state.business_details[-1]}''')]
68
+ print('improver prompt:', messages)
69
+
70
+ try:
71
+ response = improver_agent.invoke({'messages':messages})
72
+ response = response['messages'][-1].content
73
+ print('Improver Response:',response)
74
+ state.improver_response.append(response)
75
+ print('Improver Improved the story')
76
+ return state
77
+
78
+ except:
79
+ response = improver_llm.invoke(messages)
80
+ print('Improver backup Response:',response.content)
81
+ state.improver_response.append(response.content)
82
+ return state
83
 
84
  def validator1(state:State):
85
  template = validator_prompt(state)
86
  messages = [SystemMessage(content=template),
87
+ HumanMessage(content=f'''The topic of the video is:\n{state.topic[-1]}\n The business_details is:\n{state.business_details[-1]}''')]
88
 
89
  response = validator_llm.with_structured_output(ValidationFormatter).invoke(messages)
90
  print(f'Validator 1 response: {response}')
91
+ state.validator1_response.append(response.result)
92
+ print('The state check:',state.validator1_response[-1])
93
  if 'not validated' in response.result:
94
+ state.disagreement_reason.append(response.reason)
95
  return state
96
 
97
  def validator2(state:State):
98
  template = validator_prompt(state)
99
  messages = [SystemMessage(content=template),
100
+ HumanMessage(content=f'''The topic of the video is:\n{state.topic[-1]}\n The business_details is:\n{state.business_details[-1]}''')]
101
 
102
  response = ideator_llm.with_structured_output(ValidationFormatter).invoke(messages)
103
  print(f'Validator 2 response: {response}')
104
+ state.validator2_response.append(response.result)
105
+ print('The state check:',state.validator2_response[-1])
106
  if 'not validated' in response.result:
107
+ state.disagreement_reason.append(response.reason)
108
  return state
109
 
110
  def validator3(state:State):
111
  template = validator_prompt(state)
112
  messages = [SystemMessage(content=template),
113
+ HumanMessage(content=f'''The topic of the video is:\n{state.topic[-1]}\n The business_details is:\n{state.business_details[-1]}''')]
114
 
115
  response = critic_llm.with_structured_output(ValidationFormatter).invoke(messages)
116
  print(f'Validator 3 response: {response}')
117
+ state.validator3_response.append(response.result)
118
+ print('The state check:',state.validator1_response[-1])
119
  if 'not validated' in response.result:
120
+ state.disagreement_reason.append(response.reason)
121
  return state
122
 
123
  def validator4(state:State):
124
  template = validator_prompt(state)
125
  messages = [SystemMessage(content=template),
126
+ HumanMessage(content=f'''The topic of the video is:\n{state.topic[-1]}\n The business_details is:\n{state.business_details[-1]}''')]
127
 
128
  response = improver_llm.with_structured_output(ValidationFormatter).invoke(messages)
129
  print(f'Validator 4 response: {response}')
130
+ state.validator4_response.append(response.result)
131
+ print('The state check:',state.validator1_response[-1])
132
  if 'not validated' in response.result:
133
+ state.disagreement_reason.append(response.reason)
 
134
  return state
135
 
136
  def route1_after_validation(state:State):
137
+ if 'not validated' in state.validator1_response[-1]:
138
  return False
139
  else:
140
  return True
141
 
142
 
143
  def route2_after_validation(state:State):
144
+ if 'not validated' in state.validator2_response[-1]:
145
  return False
146
  else:
147
  return True
148
 
149
 
150
  def route3_after_validation(state:State):
151
+ if 'not validated' in state.validator3_response[-1]:
152
  return False
153
  else:
154
  return True
155
 
156
 
157
  def route4_after_validation(state:State):
158
+ if 'not validated' in state.validator4_response[-1]:
159
  return False
160
  else:
161
  return True
ideation_agent/utils/prompts.py CHANGED
@@ -12,10 +12,10 @@ def ideator_prompt_old(state):
12
  ---
13
 
14
  **Video Topic**:
15
- {state.topic}
16
 
17
  **Business Details**:
18
- {state.business_details}
19
 
20
  ---
21
 
@@ -35,10 +35,10 @@ Use the response of the provided tool (which includes video stories from influen
35
  ---
36
 
37
  **Video Topic**:
38
- {state.topic}
39
 
40
  **Business Details**:
41
- {state.business_details}
42
 
43
  ---
44
 
@@ -65,13 +65,13 @@ def critic_prompt(state):
65
  ---
66
 
67
  **Video Topic**:
68
- {state.topic}
69
 
70
  **Business Details**:
71
- {state.business_details}
72
 
73
  **Original Video Idea** (100 words):
74
- {state.ideator_response}
75
 
76
  ---
77
 
@@ -83,8 +83,8 @@ def critic_prompt(state):
83
 
84
  def improver_prompt(state):
85
  disagreement_note = (
86
- f"**Your idea was not validated before because of this reason:\n{state.disagreement_reason}\n**"
87
- if state.disagreement_reason else ""
88
  )
89
  return f'''
90
  You are a master-level **video concept developer** known for turning creative ideas into standout, refined gems.
@@ -96,13 +96,13 @@ Focus on making the idea sharper, bolder, and more impactful — while staying a
96
  ---
97
 
98
  **Video Topic**:
99
- {state.topic}
100
 
101
  **Business Details**:
102
- {state.business_details}
103
 
104
  **Critic's Response**:
105
- {state.critic_response}
106
 
107
  {disagreement_note}
108
 
@@ -131,13 +131,13 @@ def validator_prompt(state):
131
 
132
 
133
  **Video Topic**:
134
- {state.topic}
135
 
136
  **Business Details**:
137
- {state.business_details}
138
 
139
  **Final idea from Improver**:
140
- {state.improver_response}
141
 
142
  ---
143
 
@@ -152,8 +152,8 @@ def validator_prompt(state):
152
  **Output Instruction**: There are two outputs you have to give.
153
 
154
  1.Respond strictly just with one of the following values:
155
- - `validated` if the idea meets all the criteria and is validated.
156
- - `not validated` if it fails to meet any key criteria and needs further improvement.
157
 
158
  2. Give a short reason of 30 words why the idea is validated or not validated.
159
  '''
 
12
  ---
13
 
14
  **Video Topic**:
15
+ {state.topic[-1]}
16
 
17
  **Business Details**:
18
+ {state.business_details[-1]}
19
 
20
  ---
21
 
 
35
  ---
36
 
37
  **Video Topic**:
38
+ {state.topic[-1]}
39
 
40
  **Business Details**:
41
+ {state.business_details[-1]}
42
 
43
  ---
44
 
 
65
  ---
66
 
67
  **Video Topic**:
68
+ {state.topic[-1]}
69
 
70
  **Business Details**:
71
+ {state.business_details[-1]}
72
 
73
  **Original Video Idea** (100 words):
74
+ {state.ideator_response[-1]}
75
 
76
  ---
77
 
 
83
 
84
  def improver_prompt(state):
85
  disagreement_note = (
86
+ f"**Your idea was not validated before because of this reason:\n{state.disagreement_reason[-1]}\n**"
87
+ if len(state.disagreement_reason)>0 else ""
88
  )
89
  return f'''
90
  You are a master-level **video concept developer** known for turning creative ideas into standout, refined gems.
 
96
  ---
97
 
98
  **Video Topic**:
99
+ {state.topic[-1]}
100
 
101
  **Business Details**:
102
+ {state.business_details[-1]}
103
 
104
  **Critic's Response**:
105
+ {state.critic_response[-1]}
106
 
107
  {disagreement_note}
108
 
 
131
 
132
 
133
  **Video Topic**:
134
+ {state.topic[-1]}
135
 
136
  **Business Details**:
137
+ {state.business_details[-1]}
138
 
139
  **Final idea from Improver**:
140
+ {state.improver_response[-1]}
141
 
142
  ---
143
 
 
152
  **Output Instruction**: There are two outputs you have to give.
153
 
154
  1.Respond strictly just with one of the following values:
155
+ - `validated` - if the idea meets all the criteria and is validated.
156
+ - `not validated` - if it fails to meet any key criteria and needs further improvement.
157
 
158
  2. Give a short reason of 30 words why the idea is validated or not validated.
159
  '''
ideation_agent/utils/state.py CHANGED
@@ -4,16 +4,16 @@ import operator
4
  from typing import Annotated
5
 
6
  class State(BaseModel):
7
- topic: list
8
- business_details: Optional[dict]
9
- ideator_response: Optional[str] = None
10
- critic_response: Optional[str]=None
11
- improver_response: Optional[str]=None
12
- validator1_response: Optional[str]=None
13
- validator2_response: Optional[str]=None
14
- validator3_response: Optional[str]=None
15
- validator4_response: Optional[str]=None
16
- disagreement_reason: Optional[str]=None
17
 
18
 
19
  class QueryFormatter(BaseModel):
 
4
  from typing import Annotated
5
 
6
  class State(BaseModel):
7
+ topic: Annotated[list[str], operator.add]
8
+ business_details : Annotated[list[dict],operator.add] = []
9
+ ideator_response: Annotated[list[str],operator.add] = []
10
+ critic_response: Annotated[list[str],operator.add] = []
11
+ improver_response: Annotated[list[str],operator.add] = []
12
+ validator1_response: Annotated[list[str],operator.add] = []
13
+ validator2_response: Annotated[list[str],operator.add] = []
14
+ validator3_response: Annotated[list[str],operator.add] = []
15
+ validator4_response: Annotated[list[str],operator.add] = []
16
+ disagreement_reason: Annotated[list[str],operator.add] = []
17
 
18
 
19
  class QueryFormatter(BaseModel):
ideation_agent/utils/tools.py CHANGED
@@ -7,7 +7,7 @@ import ast
7
  import faiss
8
  from utils.models_loader import ST
9
 
10
- @tool("influencer's data-retrieval-tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
11
  def retrieve_tool(video_topic):
12
  '''
13
  Always invoke this tool.
@@ -42,16 +42,18 @@ def retrieve_tool(video_topic):
42
  'rank': i + 1,
43
  'username': df.iloc[idx]['username'],
44
  'story': df.iloc[idx]['story'],
45
- 'visible_text_or_brandings': df.iloc[idx]['story'],
46
  'likesCount': df.iloc[idx]['likesCount'],
47
  'commentCount': df.iloc[idx]['commentCount'],
 
 
48
  }
49
 
50
  inner_list = []
51
  inner_list.append(f"[{res['rank']}]. The influencer name is: **{res['username']}** — Likes: **{res['likesCount']}**, Comments: **{res['commentCount']}**")
52
  inner_list.append(f"The story of that particular video is:\n{res['story']}")
53
  inner_list.append(f"The branding or promotion done is:\n{res['visible_text_or_brandings']}")
54
-
55
  outer_list.append(inner_list)
56
 
57
  return str(outer_list)
 
7
  import faiss
8
  from utils.models_loader import ST
9
 
10
+ @tool("influencers_data_retrieval_tool", args_schema=QueryFormatter, return_direct=False,description="Retrieve influencer-related data for a given query.")
11
  def retrieve_tool(video_topic):
12
  '''
13
  Always invoke this tool.
 
42
  'rank': i + 1,
43
  'username': df.iloc[idx]['username'],
44
  'story': df.iloc[idx]['story'],
45
+ 'visible_text_or_brandings': df.iloc[idx]['visible_texts_or_brandings'],
46
  'likesCount': df.iloc[idx]['likesCount'],
47
  'commentCount': df.iloc[idx]['commentCount'],
48
+ 'product_or_service_details': df.iloc[idx]['product_or_service_details'],
49
+
50
  }
51
 
52
  inner_list = []
53
  inner_list.append(f"[{res['rank']}]. The influencer name is: **{res['username']}** — Likes: **{res['likesCount']}**, Comments: **{res['commentCount']}**")
54
  inner_list.append(f"The story of that particular video is:\n{res['story']}")
55
  inner_list.append(f"The branding or promotion done is:\n{res['visible_text_or_brandings']}")
56
+ inner_list.append(f"The details of product or service is:\n{res['product_or_service_details']}")
57
  outer_list.append(inner_list)
58
 
59
  return str(outer_list)
main.py CHANGED
@@ -9,8 +9,8 @@ from business_interaction_agent.agent import BusinessInteractionChatbot
9
  from context_analysis_agent.utils.utils import save_to_db
10
  import ast
11
  from brainstroming_agent.utils.utils import encode_image_to_base64 , generate_final_story, generate_image
12
- from fastapi import Body, Query
13
  from ideation_agent.agent import ideation_graph
 
14
 
15
  import json
16
 
@@ -23,7 +23,7 @@ idea_graph = ideation_graph()
23
  brainstrom_graph = brainstroming_graph()
24
 
25
  stored_data={}
26
- stored_data['business_details']={"business_type": "cosmetic", "platform": "instagram", "target_audience": "youths", "business_goals": "to go global", "offerings": "nepali skin care products", "Challenges_faced": "finding new customers, attracting large customers"}
27
  # stored_data['business_details']={}
28
  class UserMessage(BaseModel):
29
  message: str
@@ -53,15 +53,23 @@ def business_interaction(interaction: str):
53
 
54
  class IdeationRequest(BaseModel):
55
  topic : List[str]
56
- business_details: dict
57
 
58
  @app.post("/ideation")
59
  def ideation_endpoint(request:IdeationRequest):
60
- result = idea_graph.invoke({
61
- 'topic': request.topic,
62
- 'business_details': stored_data['business_details']
63
- })
64
- return {'response':result}
 
 
 
 
 
 
 
 
 
65
 
66
 
67
 
 
9
  from context_analysis_agent.utils.utils import save_to_db
10
  import ast
11
  from brainstroming_agent.utils.utils import encode_image_to_base64 , generate_final_story, generate_image
 
12
  from ideation_agent.agent import ideation_graph
13
+ from langgraph.errors import GraphRecursionError
14
 
15
  import json
16
 
 
23
  brainstrom_graph = brainstroming_graph()
24
 
25
  stored_data={}
26
+ stored_data['business_details']={"business_type": "restaurant", "platform": "instagram", "target_audience": "youths", "business_goals": "to go global", "offerings": "nepali foods", "Challenges_faced": "finding new customers, attracting large customers"}
27
  # stored_data['business_details']={}
28
  class UserMessage(BaseModel):
29
  message: str
 
53
 
54
  class IdeationRequest(BaseModel):
55
  topic : List[str]
 
56
 
57
  @app.post("/ideation")
58
  def ideation_endpoint(request:IdeationRequest):
59
+ config={"recursion_limit":10, "configurable": {"thread_id": "ideation_thread123"}}
60
+ try:
61
+ result = idea_graph.invoke(
62
+ {
63
+ 'topic': request.topic,
64
+ 'business_details': [stored_data['business_details']]
65
+ },
66
+ config=config,
67
+ )
68
+ return {'response':result}
69
+ except GraphRecursionError:
70
+ result = idea_graph.get_state({"configurable": {"thread_id": "ideation_thread123"}})
71
+ return {'response': result[0]}
72
+
73
 
74
 
75
 
utils/__pycache__/data_loader.cpython-312.pyc CHANGED
Binary files a/utils/__pycache__/data_loader.cpython-312.pyc and b/utils/__pycache__/data_loader.cpython-312.pyc differ
 
utils/__pycache__/models_loader.cpython-312.pyc CHANGED
Binary files a/utils/__pycache__/models_loader.cpython-312.pyc and b/utils/__pycache__/models_loader.cpython-312.pyc differ
 
utils/data_loader.py CHANGED
@@ -3,7 +3,7 @@ from datasets import load_dataset
3
 
4
  print("Loading dataset and indexing FAISS...") # Optional: for debugging
5
 
6
- dataset = load_dataset("subashdvorak/tiktok-formatted-story", revision="embedded")
7
  data = dataset['train'].add_faiss_index('embeddings')
8
 
9
  def load_influencer_data():
 
3
 
4
  print("Loading dataset and indexing FAISS...") # Optional: for debugging
5
 
6
+ dataset = load_dataset("subashdvorak/tiktok-formatted-story-v2", revision="embedded")
7
  data = dataset['train'].add_faiss_index('embeddings')
8
 
9
  def load_influencer_data():
utils/models_loader.py CHANGED
@@ -63,7 +63,7 @@ ideator_llm = ChatGroq(
63
  )
64
 
65
  critic_llm = ChatGroq(
66
- model="gemma2-9b-it",
67
  temperature=0.3,
68
  max_tokens=500,
69
 
@@ -81,10 +81,8 @@ improver_llm = ChatGroq(
81
  max_tokens=500,
82
 
83
  )
84
-
85
-
86
  validator_llm = ChatGroq(
87
- model="gemma2-9b-it",
88
  temperature=0.3,
89
  max_tokens=500,
90
 
 
63
  )
64
 
65
  critic_llm = ChatGroq(
66
+ model="llama-3.3-70b-versatile",
67
  temperature=0.3,
68
  max_tokens=500,
69
 
 
81
  max_tokens=500,
82
 
83
  )
 
 
84
  validator_llm = ChatGroq(
85
+ model="llama-3.3-70b-versatile",
86
  temperature=0.3,
87
  max_tokens=500,
88