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

Refined ideation prompts

Browse files
.gitignore CHANGED
@@ -9,4 +9,17 @@ my_agent/utils/check.py
9
  streamlit_app.py
10
  data
11
  extracted_data.csv
12
- Research
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  streamlit_app.py
10
  data
11
  extracted_data.csv
12
+ Research
13
+ __pycache__/
14
+ *.pyc
15
+
16
+ # __pycache__
17
+ # context_analysis_agent/__pycache__
18
+ # context_analysis_agent/utils/__pycache__
19
+ # brainstroming_agent/__pycache__
20
+ # brainstroming_agent/utils__pycache__
21
+ # business_interaction_agent/__pycache__
22
+ # business_interaction_agent/utils/__pycache__
23
+ # ideation_agent/__pycache__
24
+ # ideation_agent/utils/__pycache__
25
+
__pycache__/main.cpython-312.pyc CHANGED
Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ
 
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/nodes.py CHANGED
@@ -1,4 +1,4 @@
1
- from .state import State , ValidationFormatter
2
  from .tools import retrieve_tool
3
  from langgraph.prebuilt import create_react_agent
4
  from utils.models_loader import ideator_llm, critic_llm , improver_llm , validator_llm
@@ -6,6 +6,7 @@ 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]
@@ -66,20 +67,25 @@ def improver(state: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)
 
1
+ from .state import State , ValidationFormatter , ImproverResponseFormatter
2
  from .tools import retrieve_tool
3
  from langgraph.prebuilt import create_react_agent
4
  from utils.models_loader import ideator_llm, critic_llm , improver_llm , validator_llm
 
6
  from .prompts import ideator_prompt , critic_prompt , improver_prompt , validator_prompt
7
 
8
 
9
+
10
  ideator_agent = create_react_agent(
11
  model=ideator_llm,
12
  tools=[retrieve_tool]
 
67
  messages = [SystemMessage(content=template),
68
  HumanMessage(content=f'''The topic of the video is:\n{state.topic[-1]}\n The business_details is:\n{state.business_details[-1]}''')]
69
  print('improver prompt:', messages)
70
+ response = improver_llm.with_structured_output(ImproverResponseFormatter).invoke(messages)
71
+ state.improver_response.append(response.improved_idea)
72
+ state.critic_fault.append(response.faults)
73
+ print('Improver response:',response.improved_idea)
74
+ return state
75
 
76
+ # try:
77
+ # response = improver_agent.invoke({'messages':messages})
78
+ # response = response['messages'][-1].content
79
+ # print('Improver Response:',response)
80
+ # state.improver_response.append(response)
81
+ # print('Improver Improved the story')
82
+ # return state
83
+
84
+ # except:
85
+ # response = improver_llm.invoke(messages)
86
+ # print('Improver backup Response:',response.content)
87
+ # state.improver_response.append(response.content)
88
+ # return state
89
 
90
  def validator1(state:State):
91
  template = validator_prompt(state)
ideation_agent/utils/prompts.py CHANGED
@@ -1,37 +1,40 @@
 
 
1
 
2
- def ideator_prompt_old(state):
3
- return f'''
4
 
5
- You are a highly creative video content strategist who specializes in generating original, compelling video ideas in exactly 100 words.
 
 
6
 
7
- Your task is to develop a **unique, creative and imaginative root idea** for a promotional video based on the following **video topic** and **business details**. The idea should be highly creative, catchy, and distinct—something that instantly grabs attention.
 
8
 
9
- Another important thing is that you have to give the response focusing on the response of the tool provided to you. The tool contains the video stories and contents created by the influencers.
10
- Use those responses for your reference. You can use your creativity but stay within the boundaries of the tool's response.
11
 
12
- ---
 
 
13
 
14
- **Video Topic**:
15
- {state.topic[-1]}
16
 
17
- **Business Details**:
18
- {state.business_details[-1]}
19
 
20
- ---
21
 
22
- **Important Instructions**:
23
- Do **not** generate a complete storyline. Focus only on the **main root idea** that is clear, unique, bold, and creatively promising. Keep it exactly 100 words.
24
- Now, generate the final idea for the video topic.
25
- '''
26
 
27
  def ideator_prompt(state):
28
  return f'''
29
- You are a highly imaginative and strategic **video ideator** who specializes in crafting powerful promotional video **core ideas** in **exactly 100 words**.
30
 
31
- Your task is to develop a **single, bold, unique, and creative paragraph** that represents the **root idea** of a promotional video. This is **not** a full concept or storyline just the **main idea**, presented creatively and concisely.
 
 
32
 
33
  Use the response of the provided tool (which includes video stories from influencers) as inspiration. Stay within the creative boundaries of that tool's content, but feel free to push the edges with originality.
34
 
 
35
  ---
36
 
37
  **Video Topic**:
@@ -43,15 +46,42 @@ Use the response of the provided tool (which includes video stories from influen
43
  ---
44
 
45
  **Important Instructions**:
46
- - Write only **one paragraph**, not a list.
47
- - Do **not** include titles, headers, sections, or formatting like bullet points.
48
- - The output must be exactly **100 words** — no more, no less.
49
- - Focus on uniqueness, imagination, and viral potential.
 
 
 
 
50
 
51
- Now, generate the **core idea paragraph**.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  '''
53
 
54
 
 
55
  def critic_prompt(state):
56
  return f'''
57
  You are an expert **video content strategist and creative critic**.
@@ -60,6 +90,8 @@ def critic_prompt(state):
60
 
61
  Also, you have to check whether the given idea is relevant to the tool's response or not. The tool's response includes the video stories of the influencers. If it's not relevant to the tool's response, you have to specify it.
62
 
 
 
63
  After identifying the weaknesses or faults in the idea, you must **rewrite a new, improved version** of the core idea that fixes those flaws or faults while keeping the concept bold, creative, and engaging. The improved idea should also be exactly 100 words.
64
 
65
  ---
@@ -78,20 +110,26 @@ def critic_prompt(state):
78
  **Your Task as the Critic**:
79
  1. List the **key faults** or weak areas in the original idea.
80
  2. Provide a **revised version** of the idea that improves upon the original, maintains high creativity, and stays within 100 words.
 
 
81
  '''
82
 
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.
91
 
92
- Your task is to carefully evaluate the **critic's response** to a promotional video idea. The critic has already listed faults in the original idea and provided a revised version. You must now go a step further and generate an **even more creative, emotionally engaging, and original 100-word idea** that corrects any lingering weaknesses or missed potential in the critic’s revision.
93
 
94
- Focus on making the idea sharper, bolder, and more impactful while staying aligned with the video topic, business details, and the style of influencer content referenced in the tool’s response.
 
 
 
95
 
96
  ---
97
 
@@ -101,16 +139,18 @@ Focus on making the idea sharper, bolder, and more impactful — while staying a
101
  **Business Details**:
102
  {state.business_details[-1]}
103
 
104
- **Critic's Response**:
105
  {state.critic_response[-1]}
106
 
107
  {disagreement_note}
108
 
109
  ---
110
 
111
- **Your Task**:
112
- Generate a **new, final improved idea** based on the critics analysis and revision. Your idea must be exactly **100 words**, stand out with high creativity, and reflect a strong understanding of narrative appeal and brand relevance.
113
- If the critic's revision doesn't have any problem, give the same critic's idea.
 
 
114
  '''
115
 
116
 
 
1
+ example = '''
2
+ **To better understand the expected tone, depth, and style, here are two sample ideas with their exact business contexts**:
3
 
4
+ ---
 
5
 
6
+ **Example 1: Restaurant Business**
7
+ **Business Details**:
8
+ "business_type": "restaurant", "platform": "instagram", "target_audience": "youths", "business_goals": "to go global", "offerings": "nepali foods", "Challenges_faced": "finding new customers, attracting large customers"
9
 
10
+ **Core Idea (100 words)**:
11
+ The influencer challenges the chef: “Can your food impress people from 5 different countries?” The restaurant serves the same Nepali dish (like momo or gundruk soup) to five diverse international students/youths without telling them it’s Nepali. Each gives raw reactions and ratings. Once they fall in love with it, the reveal hits. Final line: “If the world loves it—why isn’t it global yet?” This idea plays on suspense, universal taste appeal, and social proof—turning traditional Nepali food into an underdog hero.
12
 
13
+ ---
 
14
 
15
+ **Example 2: Clothing Business**
16
+ **Business Details**:
17
+ "business_type": "clothing business", "platform": "instagram", "target_audience": "youths", "business_goals": "to go global", "offerings": "nepali clothing products", "Challenges_faced": "finding new customers, attracting large customers"
18
 
19
+ **Core Idea (100 words)**:
20
+ The influencer opens with: “What if your drip had 1,000 years of history behind it?” They showcase traditional Nepali garments reimagined with modern streetwear styling—hoodies with Dhaka patterns, joggers inspired by daura suruwal. Youths on the street try them on and react: “I’d totally wear this!” The story ends with: “Nepali fashion isn’t old—it’s timeless. And now, it’s global.” A core idea blending heritage with youth-driven reinvention, sparking both pride and curiosity.
21
 
22
+ ---
23
+ '''
24
 
 
25
 
 
 
 
 
26
 
27
  def ideator_prompt(state):
28
  return f'''
29
+ You are a highly imaginative and strategic **video ideator** with a reputation for crafting unforgettable promotional video **core ideas** that go viral — all in **exactly 100 words**.
30
 
31
+ Your task is to create a **single, bold, deeply creative paragraph** that captures the **central narrative engine** of a promotional video. Think of it as the **beating heart** of a blockbuster: one core idea that flows smoothly, emotionally, and memorably. It should resonate instantly with the business’s target audience, platform, and goals — while staying tight, rooted, and crystal clear.
32
+
33
+ Do not write scattered ideas or concepts that jump in multiple directions. Focus on **one clear concept** that could inspire an entire successful video campaign. This is not a title, slogan, or script — it’s the foundational idea the rest of the content could build on.
34
 
35
  Use the response of the provided tool (which includes video stories from influencers) as inspiration. Stay within the creative boundaries of that tool's content, but feel free to push the edges with originality.
36
 
37
+
38
  ---
39
 
40
  **Video Topic**:
 
46
  ---
47
 
48
  **Important Instructions**:
49
+ - Output must be **one paragraph** only — not a list or outline.
50
+ - Do **not** use headers, titles, sections, or formatting like bullet points.
51
+ - The idea must be **exactly 100 words** — no more, no less.
52
+ - Prioritize originality, emotional engagement, and shareability.
53
+ - Keep it firmly grounded in the business details provided — product, audience, platform, challenge, and goal.
54
+ - Imagine this idea being executed by a top influencer with millions of views.
55
+
56
+ ---
57
 
58
+ **To better understand the expected tone, depth, and style, here are two sample ideas with their exact business contexts**:
59
+
60
+ ---
61
+
62
+ **Example 1: Restaurant Business**
63
+ **Business Details**:
64
+ "business_type": "restaurant", "platform": "instagram", "target_audience": "youths", "business_goals": "to go global", "offerings": "nepali foods", "Challenges_faced": "finding new customers, attracting large customers"
65
+
66
+ **Core Idea (100 words)**:
67
+ The influencer challenges the chef: “Can your food impress people from 5 different countries?” The restaurant serves the same Nepali dish (like momo or gundruk soup) to five diverse international students/youths without telling them it’s Nepali. Each gives raw reactions and ratings. Once they fall in love with it, the reveal hits. Final line: “If the world loves it—why isn’t it global yet?” This idea plays on suspense, universal taste appeal, and social proof—turning traditional Nepali food into an underdog hero.
68
+
69
+ ---
70
+
71
+ **Example 2: Clothing Business**
72
+ **Business Details**:
73
+ "business_type": "clothing business", "platform": "instagram", "target_audience": "youths", "business_goals": "to go global", "offerings": "nepali clothing products", "Challenges_faced": "finding new customers, attracting large customers"
74
+
75
+ **Core Idea (100 words)**:
76
+ The influencer opens with: “What if your drip had 1,000 years of history behind it?” They showcase traditional Nepali garments reimagined with modern streetwear styling—hoodies with Dhaka patterns, joggers inspired by daura suruwal. Youths on the street try them on and react: “I’d totally wear this!” The story ends with: “Nepali fashion isn’t old—it’s timeless. And now, it’s global.” A core idea blending heritage with youth-driven reinvention, sparking both pride and curiosity.
77
+
78
+ ---
79
+
80
+ Now, generate your **core idea paragraph**.
81
  '''
82
 
83
 
84
+
85
  def critic_prompt(state):
86
  return f'''
87
  You are an expert **video content strategist and creative critic**.
 
90
 
91
  Also, you have to check whether the given idea is relevant to the tool's response or not. The tool's response includes the video stories of the influencers. If it's not relevant to the tool's response, you have to specify it.
92
 
93
+ Also, you have to check whether the given idea is scattered in several dimensions or not. If it's scattered or bit vague, you have to mainrtain it at the root idea flowing smoothly in a core concept.
94
+
95
  After identifying the weaknesses or faults in the idea, you must **rewrite a new, improved version** of the core idea that fixes those flaws or faults while keeping the concept bold, creative, and engaging. The improved idea should also be exactly 100 words.
96
 
97
  ---
 
110
  **Your Task as the Critic**:
111
  1. List the **key faults** or weak areas in the original idea.
112
  2. Provide a **revised version** of the idea that improves upon the original, maintains high creativity, and stays within 100 words.
113
+
114
+ {example}
115
  '''
116
 
117
 
118
  def improver_prompt(state):
119
  disagreement_note = (
120
+ f"**Note:** This idea was not validated earlier because:\n{state.disagreement_reason[-1]}\n"
121
+ if len(state.disagreement_reason) > 0 else ""
122
  )
123
+
124
  return f'''
125
  You are a master-level **video concept developer** known for turning creative ideas into standout, refined gems.
126
 
127
+ Your task is to **evaluate the critics response** to a promotional video idea. The critic has already listed faults and provided a revised version. Now, you must go a step further by:
128
 
129
+ 1. **Listing the key faults or missed opportunities** in the critic’s revised idea (if any), such as lack of emotional engagement, weak narrative flow, unoriginality, poor alignment with brand/influencer style, etc.
130
+ 2. **Generating a final, improved version** of the idea that is more creative, emotionally resonant, and narratively strong — while still aligned with the business context and influencer content style.
131
+
132
+ If the critic’s idea is already strong and has no faults, simply **repeat it** as your final version.
133
 
134
  ---
135
 
 
139
  **Business Details**:
140
  {state.business_details[-1]}
141
 
142
+ **Critic's Response**:
143
  {state.critic_response[-1]}
144
 
145
  {disagreement_note}
146
 
147
  ---
148
 
149
+ **Your Tasks**:
150
+ **A. List faults (if any) in the critic's revised idea.**
151
+ **B. Write a final improved idea (100 words exactly). If no faults found, repeat the critics version.**
152
+
153
+ {example}
154
  '''
155
 
156
 
ideation_agent/utils/state.py CHANGED
@@ -8,6 +8,7 @@ class State(BaseModel):
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] = []
@@ -19,6 +20,10 @@ class State(BaseModel):
19
  class QueryFormatter(BaseModel):
20
  video_topic: str = Field(description="The video topic that user passes to the agent")
21
 
 
 
 
 
22
  class ValidationFormatter(BaseModel):
23
  result: str = Field(description="Returns **validated** if the story is validated. Returns **not validated** if story is not validated.")
24
  reason: str = Field(description="Returns the reason why the story is validated or not validated.")
 
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
+ critic_fault: Annotated[list[str],operator.add] = []
12
  improver_response: Annotated[list[str],operator.add] = []
13
  validator1_response: Annotated[list[str],operator.add] = []
14
  validator2_response: Annotated[list[str],operator.add] = []
 
20
  class QueryFormatter(BaseModel):
21
  video_topic: str = Field(description="The video topic that user passes to the agent")
22
 
23
+ class ImproverResponseFormatter(BaseModel):
24
+ faults: str= Field(description="Returns the faults of the critic's response if any.")
25
+ improved_idea: str = Field(description="Returns the improved idea of exactly 100 words. If no faults found, repeat the critic's version.")
26
+
27
  class ValidationFormatter(BaseModel):
28
  result: str = Field(description="Returns **validated** if the story is validated. Returns **not validated** if story is not validated.")
29
  reason: str = Field(description="Returns the reason why the story is validated or not validated.")
main.py CHANGED
@@ -24,7 +24,7 @@ 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
30
  @app.post("/context-analysis")
@@ -65,6 +65,7 @@ def ideation_endpoint(request:IdeationRequest):
65
  },
66
  config=config,
67
  )
 
68
  return {'response':result}
69
  except GraphRecursionError:
70
  result = idea_graph.get_state({"configurable": {"thread_id": "ideation_thread123"}})
@@ -74,18 +75,16 @@ def ideation_endpoint(request:IdeationRequest):
74
 
75
 
76
  class BrainstormRequest(BaseModel):
77
- query: List[str]
78
- preferred_topics: Optional[List] = []
79
- image_base64_list: Optional[List] = []
80
  thread_id: Optional[str]="default-session"
81
 
82
  @app.post("/brainstrom")
83
  def brainstroming_endpoint(
84
  request: BrainstormRequest, # 🔥 Full JSON body here
85
- # thread_id: Optional[str] = Query("default-session"), # Separate query param
86
  ):
87
  result = brainstrom_graph.invoke({
88
- 'topic': request.query,
89
  'images': request.image_base64_list,
90
  'latest_preferred_topics': request.preferred_topics,
91
  'business_details': (lambda d: d['business_details'] if 'business_details' in d else {})(stored_data)
 
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['final_ideation'] = {}
28
  class UserMessage(BaseModel):
29
  message: str
30
  @app.post("/context-analysis")
 
65
  },
66
  config=config,
67
  )
68
+ stored_data['final_ideation'] = result['improver_response'][-1]
69
  return {'response':result}
70
  except GraphRecursionError:
71
  result = idea_graph.get_state({"configurable": {"thread_id": "ideation_thread123"}})
 
75
 
76
 
77
  class BrainstormRequest(BaseModel):
78
+ preferred_topics: Optional[list] = []
79
+ image_base64_list: Optional[list] = []
 
80
  thread_id: Optional[str]="default-session"
81
 
82
  @app.post("/brainstrom")
83
  def brainstroming_endpoint(
84
  request: BrainstormRequest, # 🔥 Full JSON body here
 
85
  ):
86
  result = brainstrom_graph.invoke({
87
+ 'topic': [stored_data['final_ideation']],
88
  'images': request.image_base64_list,
89
  'latest_preferred_topics': request.preferred_topics,
90
  'business_details': (lambda d: d['business_details'] if 'business_details' in d else {})(stored_data)
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/models_loader.py CHANGED
@@ -14,19 +14,19 @@ login(os.environ['HUGGINGFACEHUB_ACCESS_TOKEN'])
14
  os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
15
 
16
 
17
- # llm = ChatGroq(
18
- # model="llama3-8b-8192",
19
- # temperature=0.3,
20
- # max_tokens=500,
21
-
22
- # )
23
-
24
- llm = ChatOpenAI(
25
- model="gpt-4o-mini",
26
  temperature=0.3,
27
  max_tokens=500,
 
28
  )
29
 
 
 
 
 
 
 
30
 
31
  class HFEmbeddingAPI:
32
  def __init__(self, api_url, token):
 
14
  os.environ['GROQ_API_KEY']=os.getenv('GROQ_API_KEY')
15
 
16
 
17
+ llm = ChatGroq(
18
+ model="llama3-8b-8192",
 
 
 
 
 
 
 
19
  temperature=0.3,
20
  max_tokens=500,
21
+
22
  )
23
 
24
+ # llm = ChatOpenAI(
25
+ # model="gpt-4o-mini",
26
+ # temperature=0.3,
27
+ # max_tokens=500,
28
+ # )
29
+
30
 
31
  class HFEmbeddingAPI:
32
  def __init__(self, api_url, token):