subashpoudel commited on
Commit
0c51449
·
1 Parent(s): 708437f

Structured the prompts in a separate module

Browse files
my_agent/utils/__pycache__/utils.cpython-312.pyc CHANGED
Binary files a/my_agent/utils/__pycache__/utils.cpython-312.pyc and b/my_agent/utils/__pycache__/utils.cpython-312.pyc differ
 
my_agent/utils/nodes.py CHANGED
@@ -7,6 +7,7 @@ from .models_loader import llm , ST
7
  from .data_loader import load_influencer_data
8
  from groq import Groq
9
  import os
 
10
 
11
 
12
  def caption_image(state: State) -> State:
@@ -19,7 +20,7 @@ def caption_image(state: State) -> State:
19
  {
20
  "role": "user",
21
  "content": [
22
- {"type": "text", "text": "What's in this image?"},
23
  {
24
  "type": "image_url",
25
  "image_url": {
@@ -39,10 +40,6 @@ def caption_image(state: State) -> State:
39
  state.image_captions.append(None)
40
  return state
41
 
42
- # elif state.images[-1]==None:
43
- # state.image_captions.append(None)
44
-
45
-
46
 
47
 
48
  def retrieve(state: State) -> State:
@@ -92,17 +89,9 @@ def generate_story(state:State)-> State:
92
  retrieval = " ".join(agentic_stories)
93
 
94
  if len(state.preferred_topics)==0:
95
- template = f'''I want to create a detailed storyline for a video in any domain. You have to provide me that storyline what to include in the video.
96
- Now, i am giving you the topic of the video. But the need is to generate the story focusing on the format that i'll provide to you.
97
- You can use this format for the reference purpose, not for the exact similar generation. Th format is:\n{retrieval}.
98
- \n\n Now let's start creating the storyline for my topic. The topic of the video is: \n\n{state.topic}'''
99
  else:
100
- template = f'''I want to create a detailed storyline for a video in the given topic. You have to provide me that storyline what to include in the video.
101
- Now, i am giving you the topic of the video. But the need is to generate the story focusing on the format that i'll provide to you.
102
- You can use this format for the reference purpose, not for the exact similar generation. The format is:\n{retrieval}.
103
- \n\n Now let's start creating the storyline for my topic. The topic of the video is: \n\n{state.topic}\n\n
104
-
105
- **Final Reminder** You have to strongly focus on these topics while creating the storyline: {state.preferred_topics[-1]}'''
106
 
107
  # and {state.image_captions[-1]}
108
 
@@ -122,17 +111,8 @@ def generate_story(state:State)-> State:
122
 
123
 
124
  def generate_brainstroming(state:State)-> State:
125
- story=state.stories[-1]
126
-
127
- template= f'''I want to brainstorm ways to diversify or improve a storyline in exactly 4 sentences.
128
- The goal is to generate creative and actionable ideas that are not on the storyline on how the storyline can be expanded or modified for better engagement.
129
- For example: If the storyline is about creating a promotional video for a restaurant, the new suggestions might include:
130
- - I want to showcase the chef preparing a signature dish.
131
- - I want to add a sequence of customers sharing their experiences at the restaurant.
132
- - I want to highlight the farm-to-table sourcing of ingredients with a short segment showing local farms.
133
- - I want to include a time-lapse of the restaurant transforming from day to night, capturing its unique ambiance.
134
- - I want to feature a quick interview with the owner sharing the story behind the restaurant.
135
- Now, I will provide you with the storyline. The storyline is:\n{story}'''
136
 
137
  messages = [SystemMessage(content=template)]
138
  response = llm.bind_tools([BrainstromTopicFormatter]).invoke(messages)
@@ -193,14 +173,9 @@ def route_after_selection(state:State):
193
  elif len(state.latest_preferred_topics)>0:
194
  return True
195
 
196
- def generate_final_story(query):
197
- if len(query['preferred_topics'])>0:
198
- template = f'''I want to create a detailed storyline for a video in the given topic. You have to provide me that storyline what to include in the video.
199
- Now, i am giving you the topic of the video. But the need is to generate the story focusing on the format that i'll provide to you.
200
- You can use this format for the reference purpose, not for the exact similar generation. The format is:\n{query['retrievals'][-1]}.
201
- \n\n Now let's start creating the storyline for my topic. The topic of the video is: \n\n{query['topic']}\n\n
202
-
203
- **Final Reminder** You have to strongly focus on these topics while creating the storyline: {[item for sublist in query['preferred_topics'] for item in sublist]}'''
204
  messages = [SystemMessage(content=template)]
205
  response = llm.bind_tools([StoryFormatter]).invoke(messages)
206
  print('The final response is:',response)
@@ -215,7 +190,7 @@ def generate_final_story(query):
215
  return response
216
 
217
  else:
218
- return query['stories'][-1]
219
 
220
 
221
 
 
7
  from .data_loader import load_influencer_data
8
  from groq import Groq
9
  import os
10
+ from .prompts import image_captioning_prompt , initial_story_prompt , refined_story_prompt , brainstroming_prompt , final_story_prompt
11
 
12
 
13
  def caption_image(state: State) -> State:
 
20
  {
21
  "role": "user",
22
  "content": [
23
+ {"type": "text", "text": image_captioning_prompt},
24
  {
25
  "type": "image_url",
26
  "image_url": {
 
40
  state.image_captions.append(None)
41
  return state
42
 
 
 
 
 
43
 
44
 
45
  def retrieve(state: State) -> State:
 
89
  retrieval = " ".join(agentic_stories)
90
 
91
  if len(state.preferred_topics)==0:
92
+ template = initial_story_prompt(retrieval , state)
 
 
 
93
  else:
94
+ template = refined_story_prompt(retrieval , state)
 
 
 
 
 
95
 
96
  # and {state.image_captions[-1]}
97
 
 
111
 
112
 
113
  def generate_brainstroming(state:State)-> State:
114
+
115
+ template= brainstroming_prompt(state)
 
 
 
 
 
 
 
 
 
116
 
117
  messages = [SystemMessage(content=template)]
118
  response = llm.bind_tools([BrainstromTopicFormatter]).invoke(messages)
 
173
  elif len(state.latest_preferred_topics)>0:
174
  return True
175
 
176
+ def generate_final_story(final_state):
177
+ if len(final_state['preferred_topics'])>0:
178
+ template = final_story_prompt(final_state)
 
 
 
 
 
179
  messages = [SystemMessage(content=template)]
180
  response = llm.bind_tools([StoryFormatter]).invoke(messages)
181
  print('The final response is:',response)
 
190
  return response
191
 
192
  else:
193
+ return final_state['stories'][-1]
194
 
195
 
196
 
my_agent/utils/prompts.py CHANGED
@@ -8,4 +8,54 @@ Example input:
8
 
9
  Desired output:
10
  "A cinematic street scene reveals the charming exterior of 'Vegetarian Delights,' then glides into a warmly lit, spice-scented interior where skilled chefs craft vibrant vegetarian dishes and a delighted diner savors each flavorful bite in glowing ambiance."
11
- '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  Desired output:
10
  "A cinematic street scene reveals the charming exterior of 'Vegetarian Delights,' then glides into a warmly lit, spice-scented interior where skilled chefs craft vibrant vegetarian dishes and a delighted diner savors each flavorful bite in glowing ambiance."
11
+ '''
12
+
13
+ image_captioning_prompt = '''
14
+ Analyze the image deeply and give the story of the image what it wants to say?
15
+ '''
16
+
17
+
18
+ def initial_story_prompt(retrieval , state):
19
+ return (
20
+ f'''
21
+ I want to create a detailed storyline for a video in any domain. You have to provide me that storyline what to include in the video.
22
+ Now, i am giving you the topic of the video. But the need is to generate the story focusing on the format that i'll provide to you.
23
+ You can use this format for the reference purpose, not for the exact similar generation. The format is:\n{retrieval}.
24
+ \n\n Now let's start creating the storyline for my topic. The topic of the video is: \n\n{state.topic}'''
25
+ )
26
+
27
+ def refined_story_prompt(retrieval , state):
28
+ return(
29
+ f'''
30
+ I want to create a detailed storyline for a video in the given topic. You have to provide me that storyline what to include in the video.
31
+ Now, i am giving you the topic of the video. But the need is to generate the story focusing on the format that i'll provide to you.
32
+ You can use this format for the reference purpose, not for the exact similar generation. The format is:\n{retrieval}.
33
+ \n\n Now let's start creating the storyline for my topic. The topic of the video is: \n\n{state.topic}\n\n
34
+
35
+ **Final Reminder** You have to strongly focus on these topics while creating the storyline: {state.preferred_topics[-1]} and {state.image_captions[-1]}'''
36
+ )
37
+
38
+ def brainstroming_prompt(state):
39
+ return(
40
+ f'''
41
+ I want to brainstorm ways to diversify or improve a storyline in exactly 4 sentences.
42
+ The goal is to generate creative and actionable ideas that are not on the storyline on how the storyline can be expanded or modified for better engagement.
43
+ For example: If the storyline is about creating a promotional video for a restaurant, the new suggestions might include:
44
+ - I want to showcase the chef preparing a signature dish.
45
+ - I want to add a sequence of customers sharing their experiences at the restaurant.
46
+ - I want to highlight the farm-to-table sourcing of ingredients with a short segment showing local farms.
47
+ - I want to include a time-lapse of the restaurant transforming from day to night, capturing its unique ambiance.
48
+ - I want to feature a quick interview with the owner sharing the story behind the restaurant.
49
+ Now, I will provide you with the storyline. The storyline is:\n{state.stories[-1]}'''
50
+ )
51
+
52
+ def final_story_prompt(final_state):
53
+ return(
54
+ f'''
55
+ I want to create a detailed storyline for a video in the given topic. You have to provide me that storyline what to include in the video.
56
+ Now, i am giving you the topic of the video. But the need is to generate the story focusing on the format that i'll provide to you.
57
+ You can use this format for the reference purpose, not for the exact similar generation. The format is:\n{final_state['retrievals'][-1]}.
58
+ \n\n Now let's start creating the storyline for my topic. The topic of the video is: \n\n{final_state['topic']}\n\n
59
+
60
+ **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]}'''
61
+ )