Spaces:
Sleeping
Sleeping
Commit
·
a0929ab
1
Parent(s):
9acd478
Next refined
Browse files- __pycache__/main.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/tools.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/utils.cpython-312.pyc +0 -0
- brainstroming_agent/utils/nodes.py +19 -20
- brainstroming_agent/utils/prompts.py +35 -74
- brainstroming_agent/utils/tools.py +1 -2
- brainstroming_agent/utils/utils.py +7 -5
- human_refined_ideation/utils/nodes.py +5 -4
- human_refined_ideation/utils/prompts.py +1 -0
- human_refined_ideation/utils/state.py +5 -1
- main.py +5 -2
- utils/__pycache__/data_loader.cpython-312.pyc +0 -0
- utils/data_loader.py +4 -4
__pycache__/main.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ
|
|
|
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/__pycache__/utils.cpython-312.pyc
CHANGED
|
Binary files a/brainstroming_agent/utils/__pycache__/utils.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/utils.cpython-312.pyc differ
|
|
|
brainstroming_agent/utils/nodes.py
CHANGED
|
@@ -2,7 +2,7 @@ import pandas as pd
|
|
| 2 |
import ast
|
| 3 |
from .state import State
|
| 4 |
from .tools import retrieve_tool
|
| 5 |
-
from langchain_core.messages import SystemMessage ,HumanMessage
|
| 6 |
from utils.models_loader import llm , ST
|
| 7 |
from utils.data_loader import load_influencer_data
|
| 8 |
from groq import Groq
|
|
@@ -56,13 +56,8 @@ def retrieve(state: State) -> State:
|
|
| 56 |
retrievals=[]
|
| 57 |
query_prompt = 'Represent this sentence for searching relevant passages: '
|
| 58 |
if len(state.latest_preferred_topics)==0:
|
| 59 |
-
for
|
| 60 |
-
|
| 61 |
-
data = load_influencer_data()
|
| 62 |
-
scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
|
| 63 |
-
|
| 64 |
-
# Construct a list of dictionaries for this topic
|
| 65 |
-
result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['story'])]
|
| 66 |
retrievals.append(result)
|
| 67 |
print('Retrieval process completed......')
|
| 68 |
state.retrievals.append(retrievals)
|
|
@@ -70,13 +65,8 @@ def retrieve(state: State) -> State:
|
|
| 70 |
if len (state.latest_preferred_topics)>0:
|
| 71 |
print('The preferred_topics are:',state.latest_preferred_topics)
|
| 72 |
state.preferred_topics.append(state.latest_preferred_topics)
|
| 73 |
-
for
|
| 74 |
-
|
| 75 |
-
data = load_influencer_data()
|
| 76 |
-
scores, retrieved_examples = data.get_nearest_examples("embeddings", embedded_query, k=1)
|
| 77 |
-
|
| 78 |
-
# Construct a list of dictionaries for this topic
|
| 79 |
-
result = [{user: story} for user, story in zip(retrieved_examples['username'], retrieved_examples['story'])]
|
| 80 |
retrievals.append(result)
|
| 81 |
print('Retrieval process completed for preferred_topics......')
|
| 82 |
state.latest_preferred_topics=[]
|
|
@@ -84,11 +74,12 @@ def retrieve(state: State) -> State:
|
|
| 84 |
return state
|
| 85 |
|
| 86 |
def generate_story(state:State)-> State:
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
react_agent=create_react_agent(
|
| 90 |
-
model=llm
|
| 91 |
-
tools=
|
| 92 |
|
| 93 |
)
|
| 94 |
if len(state.preferred_topics)==0:
|
|
@@ -99,7 +90,12 @@ def generate_story(state:State)-> State:
|
|
| 99 |
# and {state.image_captions[-1]}
|
| 100 |
|
| 101 |
messages = [SystemMessage(content=template),
|
| 102 |
-
HumanMessage(content=f'''The idea of the video is:\n{state.idea}\n''')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
response = react_agent.invoke({'messages':messages})
|
| 105 |
response = response['messages'][-1].content
|
|
@@ -114,7 +110,10 @@ def generate_brainstroming(state:State)-> State:
|
|
| 114 |
|
| 115 |
template= brainstroming_prompt(state)
|
| 116 |
|
| 117 |
-
messages = [SystemMessage(content=template)
|
|
|
|
|
|
|
|
|
|
| 118 |
response = llm.with_structured_output(BrainstromTopicFormatter).invoke(messages)
|
| 119 |
response = response.model_dump()
|
| 120 |
state.brainstroming_topics.append(response)
|
|
|
|
| 2 |
import ast
|
| 3 |
from .state import State
|
| 4 |
from .tools import retrieve_tool
|
| 5 |
+
from langchain_core.messages import SystemMessage ,HumanMessage, ToolMessage
|
| 6 |
from utils.models_loader import llm , ST
|
| 7 |
from utils.data_loader import load_influencer_data
|
| 8 |
from groq import Groq
|
|
|
|
| 56 |
retrievals=[]
|
| 57 |
query_prompt = 'Represent this sentence for searching relevant passages: '
|
| 58 |
if len(state.latest_preferred_topics)==0:
|
| 59 |
+
for idea in state.idea:
|
| 60 |
+
result = retrieve_tool(idea+query_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
retrievals.append(result)
|
| 62 |
print('Retrieval process completed......')
|
| 63 |
state.retrievals.append(retrievals)
|
|
|
|
| 65 |
if len (state.latest_preferred_topics)>0:
|
| 66 |
print('The preferred_topics are:',state.latest_preferred_topics)
|
| 67 |
state.preferred_topics.append(state.latest_preferred_topics)
|
| 68 |
+
for idea in state.preferred_topics[-1]:
|
| 69 |
+
result = retrieve_tool(idea+query_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
retrievals.append(result)
|
| 71 |
print('Retrieval process completed for preferred_topics......')
|
| 72 |
state.latest_preferred_topics=[]
|
|
|
|
| 74 |
return state
|
| 75 |
|
| 76 |
def generate_story(state:State)-> State:
|
| 77 |
+
retrievals_from_tool = retrieve_tool(state.idea)
|
| 78 |
+
# tools=[retrieve_tool]
|
| 79 |
|
| 80 |
react_agent=create_react_agent(
|
| 81 |
+
model=llm,
|
| 82 |
+
tools=[]
|
| 83 |
|
| 84 |
)
|
| 85 |
if len(state.preferred_topics)==0:
|
|
|
|
| 90 |
# and {state.image_captions[-1]}
|
| 91 |
|
| 92 |
messages = [SystemMessage(content=template),
|
| 93 |
+
HumanMessage(content=f'''The idea of the video is:\n{state.idea}\n'''),
|
| 94 |
+
ToolMessage(content=f'''The business details is:\n{state.business_details}\n
|
| 95 |
+
The retrieved data of influencers is:\n{state.retrievals[-1]}\n
|
| 96 |
+
The information from the image is:\n{state.image_captions[-1]} ''', tool_call_id='generate_story_tool')]
|
| 97 |
+
|
| 98 |
+
print('Messages:',messages)
|
| 99 |
|
| 100 |
response = react_agent.invoke({'messages':messages})
|
| 101 |
response = response['messages'][-1].content
|
|
|
|
| 110 |
|
| 111 |
template= brainstroming_prompt(state)
|
| 112 |
|
| 113 |
+
messages = [SystemMessage(content=template),
|
| 114 |
+
HumanMessage(content=f'''Here is the story to you for brainstorming:\n{state.stories[-1]}'''),
|
| 115 |
+
ToolMessage(content=f'''The details of business is:\n{state.business_details}\n''', tool_call_id="brainstorm_tool")]
|
| 116 |
+
print('Message for brainstorming:',messages)
|
| 117 |
response = llm.with_structured_output(BrainstromTopicFormatter).invoke(messages)
|
| 118 |
response = response.model_dump()
|
| 119 |
state.brainstroming_topics.append(response)
|
brainstroming_agent/utils/prompts.py
CHANGED
|
@@ -17,96 +17,57 @@ Analyze the image deeply and give the story of the image what it potraits in jus
|
|
| 17 |
|
| 18 |
def initial_story_prompt(state):
|
| 19 |
return f"""
|
| 20 |
-
You are
|
| 21 |
-
|
| 22 |
-
Your task is to generate a **detailed and creative storyline** for a promotional video on the **given idea**. The storyline should be structured, engaging, and highly relevant to the following **business details** and **inspiration from the image context if it contains some informations*.
|
| 23 |
-
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.
|
| 24 |
-
Use that responses of tool for your reference. You can use your creativity but inside the boundary of tool's response.
|
| 25 |
-
|
| 26 |
-
---
|
| 27 |
-
|
| 28 |
-
**Video idea**:
|
| 29 |
-
{state.idea}
|
| 30 |
-
|
| 31 |
-
**Business Details**:
|
| 32 |
-
{state.business_details}
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
**Inspiration from Image Context** (must be strongly incorporated):
|
| 36 |
-
{state.image_captions[-1]}
|
| 37 |
-
|
| 38 |
-
---
|
| 39 |
-
|
| 40 |
-
🎯 **Important Instructions**:
|
| 41 |
-
- Creatively connect the image cues to make the storyline compelling. (If provided).
|
| 42 |
-
- Structure the storyline logically (e.g., beginning, middle, end), showing what scenes or visuals to include.
|
| 43 |
-
- Match the tone and depth to the business type (e.g., fun, luxurious, emotional, professional).
|
| 44 |
-
|
| 45 |
-
Now, generate the final storyline for the video dea..
|
| 46 |
"""
|
| 47 |
|
|
|
|
| 48 |
def refined_story_prompt(state):
|
| 49 |
return f"""
|
| 50 |
-
You are
|
| 51 |
-
|
| 52 |
-
Your task is to generate a **detailed and creative storyline** for a promotional video on the **given idea**. The storyline should be structured, engaging, and highly relevant to the following **business details** , **preferred focus areas** and **inspiration from the image context(if any)**.
|
| 53 |
-
Another important thing is that you have to give the response only focusing on the response of the tool provided to you. The tool contains the video stories and contents created by the influencers.
|
| 54 |
-
Use that responses of tool for your reference. You can use your creativity but inside the boundary of tool's response.
|
| 55 |
-
|
| 56 |
-
---
|
| 57 |
-
|
| 58 |
-
**Video idea**:
|
| 59 |
-
{state.idea}
|
| 60 |
-
|
| 61 |
-
**Business Details**:
|
| 62 |
-
{state.business_details}
|
| 63 |
-
|
| 64 |
-
**Preferred Focus Areas** *(must be strongly incorporated)*:
|
| 65 |
-
{state.preferred_topics[-1]}
|
| 66 |
-
|
| 67 |
-
**Inspiration from Image Context** (must be strongly incorporated):
|
| 68 |
-
{state.image_captions[-1]}
|
| 69 |
-
|
| 70 |
-
---
|
| 71 |
-
|
| 72 |
-
🎯 **Important Instructions**:
|
| 73 |
-
- Creatively connect the preferred topics and image cues to make the storyline compelling.
|
| 74 |
-
- Structure the storyline logically (e.g., beginning, middle, end), showing what scenes or visuals to include.
|
| 75 |
-
- Match the tone and depth to the business type (e.g., fun, luxurious, emotional, professional).
|
| 76 |
-
|
| 77 |
-
Now, generate the final storyline for the video idea..
|
| 78 |
"""
|
| 79 |
|
|
|
|
| 80 |
def brainstroming_prompt(state):
|
| 81 |
return f'''
|
| 82 |
-
You are a creative consultant
|
| 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 |
-
|
| 88 |
|
| 89 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
-
"{state.stories[-1]}"
|
| 100 |
'''
|
| 101 |
|
| 102 |
|
|
|
|
| 103 |
def final_story_prompt(final_state):
|
| 104 |
return(
|
| 105 |
f'''
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
|
|
|
| 17 |
|
| 18 |
def initial_story_prompt(state):
|
| 19 |
return f"""
|
| 20 |
+
You are a top-tier video content strategist. Create a compelling, scene-by-scene promotional video storyline based strictly on the given business details. The video idea comes from a human and must drive the structure, tone, and visuals. Use influencer content and image insights as creative inspiration only—not as requirements. Ensure the story flows logically (beginning, middle, end), visually engaging the audience. Reflect the brand's personality—fun, emotional, or professional as needed. Focus on clarity, depth, and storytelling impact while aligning every scene with the business's core message.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
"""
|
| 22 |
|
| 23 |
+
|
| 24 |
def refined_story_prompt(state):
|
| 25 |
return f"""
|
| 26 |
+
You are a top video content strategist. Craft an entire scene-by-scene promotional video storyline based on a human-provided idea. Strongly focus on the **preferred topic**: \n{state.preferred_topics[-1]}\n, making it central to every part of the story. Align the tone and visuals with the given business details. Use influencer content and image insights only as creative references—not as requirements. The story must be structured (beginning, middle, end), visually rich, and emotionally compelling. Keep the narrative aligned with the brand’s identity—fun, emotional, bold, or premium. Prioritize clarity, flow, and impact tied tightly to the preferred topic.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
"""
|
| 28 |
|
| 29 |
+
|
| 30 |
def brainstroming_prompt(state):
|
| 31 |
return f'''
|
| 32 |
+
You are a top-tier creative video consultant. Your task is to deeply analyze a detailed promotional video storyline and propose **four unique, creative, and practical brainstorming ideas** that could expand or diversify the direction of the story. These ideas should feel fresh, visual, and narratively strong—offering compelling branches or additions without duplicating what's already in the story.
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
You must carefully consider the **existing storyline** and **business details** provided via human and the tool. Your suggestions should not repeat scenes or themes from the current story but instead open up imaginative new angles—new scenes, emotional layers, alternate perspectives, character arcs, or innovative visual sequences.
|
| 35 |
|
| 36 |
+
Each brainstorming idea should be 1–2 concise sentences, clearly suggesting how the story could evolve or become more dynamic. Avoid abstract or vague ideas—focus on **actionable directions** that add depth, contrast, or engagement to the narrative.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
For example, if the story is about a tech gadget, suggestions might include:
|
| 39 |
+
- add a testimonial from a real user with a surprising background;
|
| 40 |
+
- contrast urban and rural uses of the product through visual storytelling;
|
| 41 |
+
- introduce a fast-paced “day-in-the-life” montage;
|
| 42 |
+
- show a behind-the-scenes of the product’s invention story.
|
| 43 |
|
| 44 |
+
Only generate ideas that have **not already appeared** in the storyline.
|
|
|
|
| 45 |
'''
|
| 46 |
|
| 47 |
|
| 48 |
+
|
| 49 |
def final_story_prompt(final_state):
|
| 50 |
return(
|
| 51 |
f'''
|
| 52 |
+
You are a senior video content strategist responsible for crafting the **final, polished storyline** for a promotional video. This will be the definitive version, so it must be complete, well-structured, visually rich, and highly satisfying to the client.
|
| 53 |
+
|
| 54 |
+
You will be provided with:
|
| 55 |
+
- A **video idea** by a human,
|
| 56 |
+
- A list of **preferred focus topics** (brainstormed and selected),
|
| 57 |
+
- Detailed **business information**, and
|
| 58 |
+
- **Influencer-generated content** as creative reference (not mandatory to include directly).
|
| 59 |
+
|
| 60 |
+
**Your task**:
|
| 61 |
+
Generate a **scene-by-scene video storyline** in around 300 words that:
|
| 62 |
+
- Fully aligns with the business goals and identity (fun, emotional, luxurious, or professional),
|
| 63 |
+
- Strongly integrates all preferred topics from the human (these represent the core focus),
|
| 64 |
+
- Uses influencer data and image cues **only as inspiration** for tone, emotion, or visual cues,
|
| 65 |
+
- Is logically structured (beginning, middle, end) and cinematic in detail,
|
| 66 |
+
- Ensures each scene flows into the next, building engagement and narrative strength.
|
| 67 |
+
|
| 68 |
+
This is the final creative delivery. The storyline should feel **complete, emotionally resonant, and visually engaging** — ready for a director to begin production.
|
| 69 |
+
|
| 70 |
+
**Very Important**
|
| 71 |
+
You have to strongly focus on these topics while creating the storyline: {[item for sublist in final_state['preferred_topics'] for item in sublist]}'''
|
| 72 |
+
)
|
| 73 |
|
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("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.
|
|
@@ -64,4 +64,3 @@ def retrieve_tool(video_topic):
|
|
| 64 |
outer_list.append(inner_list)
|
| 65 |
|
| 66 |
return str(outer_list)
|
| 67 |
-
|
|
|
|
| 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.
|
|
|
|
| 64 |
outer_list.append(inner_list)
|
| 65 |
|
| 66 |
return str(outer_list)
|
|
|
brainstroming_agent/utils/utils.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
|
| 2 |
-
from langchain_core.messages import SystemMessage
|
| 3 |
from .tools import retrieve_tool
|
| 4 |
import base64
|
| 5 |
from PIL import Image
|
|
@@ -22,12 +22,14 @@ from utils.models_loader import ST , llm
|
|
| 22 |
def generate_final_story(final_state):
|
| 23 |
if len(final_state['preferred_topics'])>0:
|
| 24 |
template = final_story_prompt(final_state)
|
| 25 |
-
messages = [SystemMessage(content=template)
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
tools = [retrieve_tool]
|
| 28 |
react_agent=create_react_agent(
|
| 29 |
-
model=llm
|
| 30 |
-
tools=
|
| 31 |
|
| 32 |
response = react_agent.invoke({'messages':messages})
|
| 33 |
response = response['messages'][-1].content
|
|
|
|
| 1 |
|
| 2 |
+
from langchain_core.messages import SystemMessage, ToolMessage, HumanMessage
|
| 3 |
from .tools import retrieve_tool
|
| 4 |
import base64
|
| 5 |
from PIL import Image
|
|
|
|
| 22 |
def generate_final_story(final_state):
|
| 23 |
if len(final_state['preferred_topics'])>0:
|
| 24 |
template = final_story_prompt(final_state)
|
| 25 |
+
messages = [SystemMessage(content=template),
|
| 26 |
+
HumanMessage(content=f'''The idea of the video is:\n{final_state['idea']}\n '''),
|
| 27 |
+
ToolMessage(content=f'''The business details is:\n{final_state['business_details']}\nThe data of influencers is:\n{final_state['retrievals'][-1]}''',tool_call_id='final_story_tool')]
|
| 28 |
+
print('The message of final story:',messages)
|
| 29 |
|
|
|
|
| 30 |
react_agent=create_react_agent(
|
| 31 |
+
model=llm,
|
| 32 |
+
tools=[])
|
| 33 |
|
| 34 |
response = react_agent.invoke({'messages':messages})
|
| 35 |
response = response['messages'][-1].content
|
human_refined_ideation/utils/nodes.py
CHANGED
|
@@ -1,15 +1,16 @@
|
|
| 1 |
from .prompts import idea_refinement_prompt
|
| 2 |
from langchain_core.messages import SystemMessage , HumanMessage, ToolMessage
|
| 3 |
from utils.models_loader import llm
|
| 4 |
-
from .state import State
|
| 5 |
|
| 6 |
def run_refiner(state:State):
|
| 7 |
template = idea_refinement_prompt()
|
| 8 |
messages = [
|
| 9 |
SystemMessage(content=template),
|
| 10 |
-
ToolMessage(content=f"The four ideas are:\n{state.final_ideation}", tool_call_id='refiner_tool'),
|
| 11 |
HumanMessage(content=str(state.query))
|
| 12 |
]
|
| 13 |
-
result = llm.invoke(messages)
|
| 14 |
-
|
|
|
|
| 15 |
return state
|
|
|
|
| 1 |
from .prompts import idea_refinement_prompt
|
| 2 |
from langchain_core.messages import SystemMessage , HumanMessage, ToolMessage
|
| 3 |
from utils.models_loader import llm
|
| 4 |
+
from .state import State, IdeationFormatter
|
| 5 |
|
| 6 |
def run_refiner(state:State):
|
| 7 |
template = idea_refinement_prompt()
|
| 8 |
messages = [
|
| 9 |
SystemMessage(content=template),
|
| 10 |
+
ToolMessage(content=f"The four ideas are:\n{state.final_ideation}.\nThe business details is:\n{state.business_details}", tool_call_id='refiner_tool'),
|
| 11 |
HumanMessage(content=str(state.query))
|
| 12 |
]
|
| 13 |
+
result = llm.with_structured_output(IdeationFormatter).invoke(messages)
|
| 14 |
+
print(result.refined_idea)
|
| 15 |
+
state.result = result.refined_idea
|
| 16 |
return state
|
human_refined_ideation/utils/prompts.py
CHANGED
|
@@ -15,6 +15,7 @@ The user will do some request to enhance their ideas. You have to creatively pro
|
|
| 15 |
|
| 16 |
📢 STRICT OUTPUT POLICY:
|
| 17 |
- **Only return the current best idea as plain text.**
|
|
|
|
| 18 |
- **No explanations, no headers, no labels.**
|
| 19 |
- **Do not ask the user anything back.**
|
| 20 |
- Remember, you have to give the response of your idea in **exactly 30 words**.
|
|
|
|
| 15 |
|
| 16 |
📢 STRICT OUTPUT POLICY:
|
| 17 |
- **Only return the current best idea as plain text.**
|
| 18 |
+
- Stick with the **business details** provided to you as a tool message. The generated idea should conclude to the business details.
|
| 19 |
- **No explanations, no headers, no labels.**
|
| 20 |
- **Do not ask the user anything back.**
|
| 21 |
- Remember, you have to give the response of your idea in **exactly 30 words**.
|
human_refined_ideation/utils/state.py
CHANGED
|
@@ -4,4 +4,8 @@ from typing import Optional
|
|
| 4 |
class State(BaseModel):
|
| 5 |
final_ideation: list
|
| 6 |
query:list
|
| 7 |
-
result: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
class State(BaseModel):
|
| 5 |
final_ideation: list
|
| 6 |
query:list
|
| 7 |
+
result: Optional[str] = None
|
| 8 |
+
business_details: dict
|
| 9 |
+
|
| 10 |
+
class IdeationFormatter(BaseModel):
|
| 11 |
+
refined_idea: str = Field(description="The refined idea after human intervention.")
|
main.py
CHANGED
|
@@ -44,6 +44,7 @@ stored_data['final_ideation']= ['''A street magician performs tricks, leaving a
|
|
| 44 |
'''A young Nepali woman discovers a hidden strength within herself while hiking the Himalayas. She returns home, and her fitness journey begins at our gym. With the help of our personal trainers, she transforms her body and mind. The gym becomes her sanctuary, and her transformation inspires others to find their inner strength.''']
|
| 45 |
|
| 46 |
stored_data['human_ideation_interactions'] = []
|
|
|
|
| 47 |
|
| 48 |
class UserMessage(BaseModel):
|
| 49 |
message: str
|
|
@@ -103,10 +104,12 @@ def human_idea_refine_endpoint(request:RefineIdeationRequest):
|
|
| 103 |
response = human_refine_graph.invoke(
|
| 104 |
{
|
| 105 |
'query': stored_data['human_ideation_interactions'],
|
| 106 |
-
'
|
|
|
|
| 107 |
},config={"configurable": {"thread_id": request.thread_id}}
|
| 108 |
)
|
| 109 |
stored_data['human_ideation_interactions'].append({"role": "assistant", "content": response['result']})
|
|
|
|
| 110 |
return {'response' : stored_data['human_ideation_interactions'][-1]['content'] }
|
| 111 |
|
| 112 |
|
|
@@ -127,7 +130,7 @@ def brainstroming_endpoint(
|
|
| 127 |
request: BrainstormRequest, # 🔥 Full JSON body here
|
| 128 |
):
|
| 129 |
result = brainstrom_graph.invoke({
|
| 130 |
-
'idea': [stored_data['
|
| 131 |
'images': request.image_base64_list,
|
| 132 |
'latest_preferred_topics': request.preferred_topics,
|
| 133 |
'business_details': (lambda d: d['business_details'] if 'business_details' in d else {})(stored_data)
|
|
|
|
| 44 |
'''A young Nepali woman discovers a hidden strength within herself while hiking the Himalayas. She returns home, and her fitness journey begins at our gym. With the help of our personal trainers, she transforms her body and mind. The gym becomes her sanctuary, and her transformation inspires others to find their inner strength.''']
|
| 45 |
|
| 46 |
stored_data['human_ideation_interactions'] = []
|
| 47 |
+
stored_data['refined_ideation'] = '''A street magician's trick fails, inspiring a fitness journey. Months later, he fuses magic with strength, showcasing transformation. Meanwhile, a fitness coach bonds with foodies over health, sparking a community workout group, blending fun and fitness.'''
|
| 48 |
|
| 49 |
class UserMessage(BaseModel):
|
| 50 |
message: str
|
|
|
|
| 104 |
response = human_refine_graph.invoke(
|
| 105 |
{
|
| 106 |
'query': stored_data['human_ideation_interactions'],
|
| 107 |
+
'business_details': stored_data["business_details"],
|
| 108 |
+
'final_ideation': stored_data['final_ideation'],
|
| 109 |
},config={"configurable": {"thread_id": request.thread_id}}
|
| 110 |
)
|
| 111 |
stored_data['human_ideation_interactions'].append({"role": "assistant", "content": response['result']})
|
| 112 |
+
stored_data['refined_ideation'] = stored_data['human_ideation_interactions'][-1]['content']
|
| 113 |
return {'response' : stored_data['human_ideation_interactions'][-1]['content'] }
|
| 114 |
|
| 115 |
|
|
|
|
| 130 |
request: BrainstormRequest, # 🔥 Full JSON body here
|
| 131 |
):
|
| 132 |
result = brainstrom_graph.invoke({
|
| 133 |
+
'idea': [stored_data['refined_ideation']],
|
| 134 |
'images': request.image_base64_list,
|
| 135 |
'latest_preferred_topics': request.preferred_topics,
|
| 136 |
'business_details': (lambda d: d['business_details'] if 'business_details' in d else {})(stored_data)
|
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/data_loader.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
|
| 4 |
# print("Loading dataset and indexing FAISS...") # Optional: for debugging
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
def load_influencer_data():
|
| 10 |
-
return
|
|
|
|
| 1 |
|
| 2 |
+
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-v2", revision="embedded")
|
| 7 |
+
data = dataset['train'].add_faiss_index('embeddings')
|
| 8 |
|
| 9 |
def load_influencer_data():
|
| 10 |
+
return data
|