Spaces:
Sleeping
Sleeping
Commit
·
9acd478
1
Parent(s):
b623e6c
added human refinements block
Browse files- __pycache__/main.cpython-312.pyc +0 -0
- brainstroming_agent/__pycache__/agent.cpython-312.pyc +0 -0
- brainstroming_agent/agent.py +1 -2
- brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/prompts.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/state.cpython-312.pyc +0 -0
- brainstroming_agent/utils/__pycache__/tools.cpython-312.pyc +0 -0
- brainstroming_agent/utils/nodes.py +2 -44
- brainstroming_agent/utils/prompts.py +11 -11
- brainstroming_agent/utils/state.py +1 -1
- brainstroming_agent/utils/tools.py +1 -1
- context_analysis_agent/utils/__pycache__/utils.cpython-312.pyc +0 -0
- context_analysis_agent/utils/utils.py +1 -1
- human_refined_ideation/__init__.py +0 -0
- human_refined_ideation/agent.py +13 -0
- human_refined_ideation/utils/__init__.py +0 -0
- human_refined_ideation/utils/nodes.py +15 -0
- human_refined_ideation/utils/prompts.py +24 -0
- human_refined_ideation/utils/state.py +7 -0
- human_refined_ideation/utils/tools.py +0 -0
- idea_to_budget_agent/utils/tools.py +2 -0
- ideation_agent/__pycache__/agent.cpython-312.pyc +0 -0
- ideation_agent/agent.py +12 -2
- ideation_agent/utils/__pycache__/nodes.cpython-312.pyc +0 -0
- ideation_agent/utils/__pycache__/prompts.cpython-312.pyc +0 -0
- ideation_agent/utils/__pycache__/state.cpython-312.pyc +0 -0
- ideation_agent/utils/__pycache__/tools.cpython-312.pyc +0 -0
- ideation_agent/utils/nodes.py +10 -11
- ideation_agent/utils/prompts.py +31 -17
- ideation_agent/utils/state.py +4 -8
- ideation_agent/utils/tools.py +3 -3
- main.py +26 -6
- utils/__pycache__/data_loader.cpython-312.pyc +0 -0
- utils/__pycache__/models_loader.cpython-312.pyc +0 -0
- utils/data_loader.py +5 -5
- utils/models_loader.py +8 -9
__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
|
| 4 |
from langgraph.checkpoint.memory import MemorySaver
|
| 5 |
|
| 6 |
memory = MemorySaver()
|
|
@@ -12,7 +12,6 @@ def brainstroming_graph():
|
|
| 12 |
builder.add_node(retrieve)
|
| 13 |
builder.add_node(generate_story)
|
| 14 |
builder.add_node(generate_brainstroming)
|
| 15 |
-
builder.add_node(select_preferred_topics)
|
| 16 |
|
| 17 |
|
| 18 |
# Normal edges
|
|
|
|
| 1 |
from langgraph.graph import StateGraph, START, END
|
| 2 |
from .utils.state import State
|
| 3 |
+
from .utils.nodes import retrieve, generate_story, generate_brainstroming,caption_image
|
| 4 |
from langgraph.checkpoint.memory import MemorySaver
|
| 5 |
|
| 6 |
memory = MemorySaver()
|
|
|
|
| 12 |
builder.add_node(retrieve)
|
| 13 |
builder.add_node(generate_story)
|
| 14 |
builder.add_node(generate_brainstroming)
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
# Normal edges
|
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__/state.cpython-312.pyc
CHANGED
|
Binary files a/brainstroming_agent/utils/__pycache__/state.cpython-312.pyc and b/brainstroming_agent/utils/__pycache__/state.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
|
@@ -99,11 +99,11 @@ def generate_story(state:State)-> State:
|
|
| 99 |
# and {state.image_captions[-1]}
|
| 100 |
|
| 101 |
messages = [SystemMessage(content=template),
|
| 102 |
-
HumanMessage(content=f'''The
|
| 103 |
|
| 104 |
response = react_agent.invoke({'messages':messages})
|
| 105 |
response = response['messages'][-1].content
|
| 106 |
-
print('The
|
| 107 |
state.stories.append(response)
|
| 108 |
# return State(messages="Story generated", topic=state.topic,stories=state.stories)
|
| 109 |
return state
|
|
@@ -124,48 +124,6 @@ def generate_brainstroming(state:State)-> State:
|
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
-
def select_preferred_topics(state: State)-> State:
|
| 128 |
-
print("---human_feedback---")
|
| 129 |
-
|
| 130 |
-
topic_values = list(state.brainstroming_topics[-1].values())
|
| 131 |
-
|
| 132 |
-
print("Available topics:")
|
| 133 |
-
for idx, topic in enumerate(topic_values, 1):
|
| 134 |
-
print(f"{idx}. {topic}")
|
| 135 |
-
|
| 136 |
-
raw_input_str = input("Enter the numbers of your preferred topics (comma-separated), or press Enter to skip: ").strip()
|
| 137 |
-
|
| 138 |
-
if not raw_input_str:
|
| 139 |
-
state.carry_on=False
|
| 140 |
-
print("No topics selected. Ending process.")
|
| 141 |
-
return state
|
| 142 |
-
|
| 143 |
-
try:
|
| 144 |
-
preferred_indices = [int(i.strip()) for i in raw_input_str.split(",")]
|
| 145 |
-
preferred_topics = [topic_values[i - 1] for i in preferred_indices if 0 < i <= len(topic_values)]
|
| 146 |
-
# preferred_topics = user_input
|
| 147 |
-
state.preferred_topics.append(preferred_topics)
|
| 148 |
-
except Exception:
|
| 149 |
-
state.carry_on=False
|
| 150 |
-
print("Invalid input. Please try again.")
|
| 151 |
-
return state
|
| 152 |
-
|
| 153 |
-
if not preferred_topics:
|
| 154 |
-
state.carry_on=False
|
| 155 |
-
print("No valid topics selected. Ending process.")
|
| 156 |
-
return state
|
| 157 |
-
|
| 158 |
-
print("You selected:")
|
| 159 |
-
print(preferred_topics)
|
| 160 |
-
state.carry_on=True
|
| 161 |
-
return state
|
| 162 |
-
|
| 163 |
-
def route_after_selection(state:State):
|
| 164 |
-
if len(state.latest_preferred_topics)==0:
|
| 165 |
-
return False
|
| 166 |
-
elif len(state.latest_preferred_topics)>0:
|
| 167 |
-
return True
|
| 168 |
-
|
| 169 |
|
| 170 |
|
| 171 |
|
|
|
|
| 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
|
| 106 |
+
print('The genrated story: ', response)
|
| 107 |
state.stories.append(response)
|
| 108 |
# return State(messages="Story generated", topic=state.topic,stories=state.stories)
|
| 109 |
return state
|
|
|
|
| 124 |
|
| 125 |
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
|
brainstroming_agent/utils/prompts.py
CHANGED
|
@@ -19,14 +19,14 @@ def initial_story_prompt(state):
|
|
| 19 |
return f"""
|
| 20 |
You are an expert video content strategist who generates the storyline of a video in exactly 300 words..
|
| 21 |
|
| 22 |
-
Your task is to generate a **detailed and creative storyline** for a promotional video on the **given
|
| 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
|
| 29 |
-
{state.
|
| 30 |
|
| 31 |
**Business Details**:
|
| 32 |
{state.business_details}
|
|
@@ -42,21 +42,21 @@ Use that responses of tool for your reference. You can use your creativity but i
|
|
| 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
|
| 46 |
"""
|
| 47 |
|
| 48 |
def refined_story_prompt(state):
|
| 49 |
return f"""
|
| 50 |
You are an expert video content strategist who generates the storyline of a video in exactly 300 words..
|
| 51 |
|
| 52 |
-
Your task is to generate a **detailed and creative storyline** for a promotional video on the **given
|
| 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
|
| 59 |
-
{state.
|
| 60 |
|
| 61 |
**Business Details**:
|
| 62 |
{state.business_details}
|
|
@@ -74,7 +74,7 @@ Use that responses of tool for your reference. You can use your creativity but i
|
|
| 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
|
| 78 |
"""
|
| 79 |
|
| 80 |
def brainstroming_prompt(state):
|
|
@@ -103,9 +103,9 @@ Now, here is the detailed video story:
|
|
| 103 |
def final_story_prompt(final_state):
|
| 104 |
return(
|
| 105 |
f'''
|
| 106 |
-
I want to create a detailed storyline for a video in the given
|
| 107 |
-
Now, i am giving you the
|
| 108 |
-
\n\n Now let's start creating the storyline for my
|
| 109 |
|
| 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 |
)
|
|
|
|
| 19 |
return f"""
|
| 20 |
You are an expert video content strategist who generates the storyline of a video in exactly 300 words..
|
| 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}
|
|
|
|
| 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 an expert video content strategist who generates the storyline of a video in exactly 300 words..
|
| 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}
|
|
|
|
| 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):
|
|
|
|
| 103 |
def final_story_prompt(final_state):
|
| 104 |
return(
|
| 105 |
f'''
|
| 106 |
+
I want to create a detailed storyline for a video in the given idea. You have to provide me that storyline what to include in the video.But the need is to generate the story focusing on the response of the tool provided to you..
|
| 107 |
+
Now, i am giving you the idea of the video.
|
| 108 |
+
\n\n Now let's start creating the storyline for my idea. The idea of the video is: \n\n{final_state['idea']}\n\n
|
| 109 |
|
| 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 |
)
|
brainstroming_agent/utils/state.py
CHANGED
|
@@ -5,7 +5,7 @@ import pandas as pd
|
|
| 5 |
class State(BaseModel):
|
| 6 |
carry_on: Optional[bool]=False
|
| 7 |
messages: Optional[str] = None
|
| 8 |
-
|
| 9 |
brainstroming_topics: Optional[list] = []
|
| 10 |
preferred_topics: Optional[list] = []
|
| 11 |
stories : Optional[list]=[]
|
|
|
|
| 5 |
class State(BaseModel):
|
| 6 |
carry_on: Optional[bool]=False
|
| 7 |
messages: Optional[str] = None
|
| 8 |
+
idea: list
|
| 9 |
brainstroming_topics: Optional[list] = []
|
| 10 |
preferred_topics: Optional[list] = []
|
| 11 |
stories : Optional[list]=[]
|
brainstroming_agent/utils/tools.py
CHANGED
|
@@ -5,7 +5,7 @@ load_dotenv()
|
|
| 5 |
import os
|
| 6 |
import numpy as np
|
| 7 |
from langchain_core.tools import tool
|
| 8 |
-
from utils.data_loader import load_influencer_data
|
| 9 |
from utils.models_loader import ST , llm
|
| 10 |
import numpy as np
|
| 11 |
from langchain_core.messages import SystemMessage
|
|
|
|
| 5 |
import os
|
| 6 |
import numpy as np
|
| 7 |
from langchain_core.tools import tool
|
| 8 |
+
# from utils.data_loader import load_influencer_data
|
| 9 |
from utils.models_loader import ST , llm
|
| 10 |
import numpy as np
|
| 11 |
from langchain_core.messages import SystemMessage
|
context_analysis_agent/utils/__pycache__/utils.cpython-312.pyc
CHANGED
|
Binary files a/context_analysis_agent/utils/__pycache__/utils.cpython-312.pyc and b/context_analysis_agent/utils/__pycache__/utils.cpython-312.pyc differ
|
|
|
context_analysis_agent/utils/utils.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from utils.data_loader import load_dataset
|
| 2 |
import pandas as pd
|
| 3 |
from utils.data_loader import load_influencer_data
|
| 4 |
|
|
|
|
| 1 |
+
# from utils.data_loader import load_dataset
|
| 2 |
import pandas as pd
|
| 3 |
from utils.data_loader import load_influencer_data
|
| 4 |
|
human_refined_ideation/__init__.py
ADDED
|
File without changes
|
human_refined_ideation/agent.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langgraph.graph import StateGraph, START, END , MessagesState
|
| 2 |
+
from langgraph.checkpoint.memory import MemorySaver
|
| 3 |
+
from .utils.nodes import run_refiner
|
| 4 |
+
from .utils.state import State
|
| 5 |
+
memory = MemorySaver()
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def human_refined_idea():
|
| 9 |
+
graph_builder= StateGraph(State)
|
| 10 |
+
graph_builder.add_node(run_refiner)
|
| 11 |
+
graph_builder.add_edge(START, "run_refiner")
|
| 12 |
+
graph_builder.add_edge("run_refiner",END)
|
| 13 |
+
return graph_builder.compile(checkpointer=memory)
|
human_refined_ideation/utils/__init__.py
ADDED
|
File without changes
|
human_refined_ideation/utils/nodes.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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).content
|
| 14 |
+
state.result = result
|
| 15 |
+
return state
|
human_refined_ideation/utils/prompts.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def idea_refinement_prompt():
|
| 2 |
+
return """
|
| 3 |
+
You are a creative idea refinement assistant. Your goal is to help the user finalize a single powerful short-form video idea for Instagram or TikTok by analyzing the four given ideas.
|
| 4 |
+
The user will do some request to enhance their ideas. You have to creatively process their query analyzing the four given ideas and return the edited best idea.
|
| 5 |
+
|
| 6 |
+
🎯 Your Rules:
|
| 7 |
+
1. Clearly interpret the user's instruction.
|
| 8 |
+
2. Modify or combine ideas strictly based on what the user says.
|
| 9 |
+
3. If the user says "undo" or "go back", return the previous version exactly as it was.
|
| 10 |
+
4. **NEVER ask the user questions.** You only act and respond with an idea.
|
| 11 |
+
5. Do not generate random or new ideas. Only improve, combine, or revert.
|
| 12 |
+
6. Maintain a strong, clear, creative narrative in every version.
|
| 13 |
+
7. Ensure each output is refined, realistic, and aligned with promotional goals.
|
| 14 |
+
9. If you're processing more than one idea, make sure the plot flows very smoothly relating them.
|
| 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**.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
You must function like a deterministic idea-refiner — each input must result in a single, story-rich output idea.
|
| 24 |
+
"""
|
human_refined_ideation/utils/state.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel, Field
|
| 2 |
+
from typing import Optional
|
| 3 |
+
|
| 4 |
+
class State(BaseModel):
|
| 5 |
+
final_ideation: list
|
| 6 |
+
query:list
|
| 7 |
+
result: Optional[str] = None
|
human_refined_ideation/utils/tools.py
ADDED
|
File without changes
|
idea_to_budget_agent/utils/tools.py
CHANGED
|
@@ -99,3 +99,5 @@ budget_tiers_schema = {
|
|
| 99 |
}
|
| 100 |
|
| 101 |
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
|
| 101 |
|
| 102 |
+
|
| 103 |
+
|
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,4 +1,4 @@
|
|
| 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
|
|
@@ -31,4 +31,14 @@ 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langgraph.graph import StateGraph, START, END , MessagesState
|
| 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
|
|
|
|
| 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)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
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
|
@@ -1,9 +1,9 @@
|
|
| 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
|
| 5 |
-
from langchain_core.messages import SystemMessage , HumanMessage
|
| 6 |
-
from .prompts import ideator_prompt , critic_prompt , improver_prompt , validator_prompt
|
| 7 |
|
| 8 |
|
| 9 |
|
|
@@ -25,7 +25,7 @@ improver_agent = create_react_agent(
|
|
| 25 |
def ideator(state:State):
|
| 26 |
template = ideator_prompt(state)
|
| 27 |
messages = [SystemMessage(content=template),
|
| 28 |
-
|
| 29 |
try:
|
| 30 |
response = ideator_agent.invoke({'messages':messages})
|
| 31 |
response = response['messages'][-1].content
|
|
@@ -43,7 +43,7 @@ def ideator(state:State):
|
|
| 43 |
def critic(state:State):
|
| 44 |
template = critic_prompt(state)
|
| 45 |
messages = [SystemMessage(content=template),
|
| 46 |
-
HumanMessage(content=f'''The
|
| 47 |
|
| 48 |
try:
|
| 49 |
response = critic_agent.invoke({'messages':messages})
|
|
@@ -64,7 +64,7 @@ def improver(state:State):
|
|
| 64 |
response_list = []
|
| 65 |
template = improver_prompt(state)
|
| 66 |
messages = [SystemMessage(content=template),
|
| 67 |
-
HumanMessage(content=f'''The
|
| 68 |
print('Improver Prompt:',messages)
|
| 69 |
response = improver_llm.with_structured_output(ImproverResponseFormatter).invoke(messages)
|
| 70 |
response_list.append(response.improved_idea1)
|
|
@@ -82,7 +82,7 @@ def improver(state:State):
|
|
| 82 |
def validator1(state:State):
|
| 83 |
template = validator_prompt(state)
|
| 84 |
messages = [SystemMessage(content=template),
|
| 85 |
-
HumanMessage(content=f'''The
|
| 86 |
|
| 87 |
response = validator_llm.with_structured_output(ValidationFormatter).invoke(messages)
|
| 88 |
print(f'Validator 1 response: {response}')
|
|
@@ -95,7 +95,7 @@ def validator1(state:State):
|
|
| 95 |
def validator2(state:State):
|
| 96 |
template = validator_prompt(state)
|
| 97 |
messages = [SystemMessage(content=template),
|
| 98 |
-
HumanMessage(content=f'''The
|
| 99 |
|
| 100 |
response = ideator_llm.with_structured_output(ValidationFormatter).invoke(messages)
|
| 101 |
print(f'Validator 2 response: {response}')
|
|
@@ -108,7 +108,7 @@ def validator2(state:State):
|
|
| 108 |
def validator3(state:State):
|
| 109 |
template = validator_prompt(state)
|
| 110 |
messages = [SystemMessage(content=template),
|
| 111 |
-
HumanMessage(content=f'''The
|
| 112 |
|
| 113 |
response = critic_llm.with_structured_output(ValidationFormatter).invoke(messages)
|
| 114 |
print(f'Validator 3 response: {response}')
|
|
@@ -121,7 +121,7 @@ def validator3(state:State):
|
|
| 121 |
def validator4(state:State):
|
| 122 |
template = validator_prompt(state)
|
| 123 |
messages = [SystemMessage(content=template),
|
| 124 |
-
HumanMessage(content=f'''The
|
| 125 |
|
| 126 |
response = improver_llm.with_structured_output(ValidationFormatter).invoke(messages)
|
| 127 |
print(f'Validator 4 response: {response}')
|
|
@@ -157,4 +157,3 @@ def route4_after_validation(state:State):
|
|
| 157 |
return False
|
| 158 |
else:
|
| 159 |
return True
|
| 160 |
-
|
|
|
|
| 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, llm
|
| 5 |
+
from langchain_core.messages import SystemMessage , HumanMessage, ToolMessage
|
| 6 |
+
from .prompts import ideator_prompt , critic_prompt , improver_prompt , validator_prompt, idea_refinement_prompt
|
| 7 |
|
| 8 |
|
| 9 |
|
|
|
|
| 25 |
def ideator(state:State):
|
| 26 |
template = ideator_prompt(state)
|
| 27 |
messages = [SystemMessage(content=template),
|
| 28 |
+
HumanMessage(content=f'''The business_details is\n{state.business_details[-1]}\n''')]
|
| 29 |
try:
|
| 30 |
response = ideator_agent.invoke({'messages':messages})
|
| 31 |
response = response['messages'][-1].content
|
|
|
|
| 43 |
def critic(state:State):
|
| 44 |
template = critic_prompt(state)
|
| 45 |
messages = [SystemMessage(content=template),
|
| 46 |
+
HumanMessage(content=f'''The business_details is\n{state.business_details[-1]}\n''')]
|
| 47 |
|
| 48 |
try:
|
| 49 |
response = critic_agent.invoke({'messages':messages})
|
|
|
|
| 64 |
response_list = []
|
| 65 |
template = improver_prompt(state)
|
| 66 |
messages = [SystemMessage(content=template),
|
| 67 |
+
HumanMessage(content=f'''The business_details is:\n{state.business_details[-1]}''')]
|
| 68 |
print('Improver Prompt:',messages)
|
| 69 |
response = improver_llm.with_structured_output(ImproverResponseFormatter).invoke(messages)
|
| 70 |
response_list.append(response.improved_idea1)
|
|
|
|
| 82 |
def validator1(state:State):
|
| 83 |
template = validator_prompt(state)
|
| 84 |
messages = [SystemMessage(content=template),
|
| 85 |
+
HumanMessage(content=f'''The business_details is:\n{state.business_details[-1]}''')]
|
| 86 |
|
| 87 |
response = validator_llm.with_structured_output(ValidationFormatter).invoke(messages)
|
| 88 |
print(f'Validator 1 response: {response}')
|
|
|
|
| 95 |
def validator2(state:State):
|
| 96 |
template = validator_prompt(state)
|
| 97 |
messages = [SystemMessage(content=template),
|
| 98 |
+
HumanMessage(content=f'''The business_details is:\n{state.business_details[-1]}''')]
|
| 99 |
|
| 100 |
response = ideator_llm.with_structured_output(ValidationFormatter).invoke(messages)
|
| 101 |
print(f'Validator 2 response: {response}')
|
|
|
|
| 108 |
def validator3(state:State):
|
| 109 |
template = validator_prompt(state)
|
| 110 |
messages = [SystemMessage(content=template),
|
| 111 |
+
HumanMessage(content=f'''The business_details is:\n{state.business_details[-1]}''')]
|
| 112 |
|
| 113 |
response = critic_llm.with_structured_output(ValidationFormatter).invoke(messages)
|
| 114 |
print(f'Validator 3 response: {response}')
|
|
|
|
| 121 |
def validator4(state:State):
|
| 122 |
template = validator_prompt(state)
|
| 123 |
messages = [SystemMessage(content=template),
|
| 124 |
+
HumanMessage(content=f'''The business_details is:\n{state.business_details[-1]}''')]
|
| 125 |
|
| 126 |
response = improver_llm.with_structured_output(ValidationFormatter).invoke(messages)
|
| 127 |
print(f'Validator 4 response: {response}')
|
|
|
|
| 157 |
return False
|
| 158 |
else:
|
| 159 |
return True
|
|
|
ideation_agent/utils/prompts.py
CHANGED
|
@@ -32,9 +32,9 @@ This differs from a full story in that:
|
|
| 32 |
|
| 33 |
---
|
| 34 |
### Very Important Reminder:
|
| 35 |
-
- Do not start or potray the idea directly by context of the
|
| 36 |
- Every 4 ideas must be very diverse. They have to be completely different from each other.
|
| 37 |
-
- NEVER use the contexts of
|
| 38 |
- Avoid repeating similar character types - **Do not use same characters , or same workplace scenarios, or same situations etc across the 4 ideas**.
|
| 39 |
- Please think **Out of the box** ideas. Surprise like a creative genius. Your idea can never be thought by a simple human.
|
| 40 |
|
|
@@ -44,9 +44,6 @@ This differs from a full story in that:
|
|
| 44 |
|
| 45 |
### Your Assignment:
|
| 46 |
|
| 47 |
-
**Video Topic**:
|
| 48 |
-
{state.topic[-1]}
|
| 49 |
-
|
| 50 |
**Business Details**:
|
| 51 |
{state.business_details[-1]}
|
| 52 |
|
|
@@ -72,7 +69,7 @@ A security guard watches a woman silently admire expensive western outfits daily
|
|
| 72 |
|
| 73 |
---
|
| 74 |
|
| 75 |
-
Now, based on the video
|
| 76 |
"""
|
| 77 |
|
| 78 |
|
|
@@ -92,7 +89,7 @@ Your job is twofold:
|
|
| 92 |
|
| 93 |
- **Each idea must be exactly 40 words**.
|
| 94 |
- Ideas must start with an **unrelated or abstract plot, character, or situation** — never directly with the business context.
|
| 95 |
-
- Please **Don't potray the
|
| 96 |
- Every 4 ideas must be very diverse. They have to be completely different from each other.
|
| 97 |
- Each idea must **creatively conclude** by connecting to the business.
|
| 98 |
- **Avoid repeating** characters, locations, or similar scenarios across the four ideas.
|
|
@@ -103,8 +100,6 @@ Your job is twofold:
|
|
| 103 |
|
| 104 |
---
|
| 105 |
|
| 106 |
-
### Video Topic:
|
| 107 |
-
{state.topic[-1]}
|
| 108 |
|
| 109 |
### Business Details:
|
| 110 |
{state.business_details[-1]}
|
|
@@ -165,11 +160,11 @@ You do **not need to critique the ideator again** — focus **only on identifyin
|
|
| 165 |
---
|
| 166 |
|
| 167 |
### Very Important Reminder:
|
| 168 |
-
- Do not start or potray the idea directly by context of the
|
| 169 |
- Every 4 ideas must be very diverse. They have to be completely different from each other.
|
| 170 |
-
- NEVER use the contexts of
|
| 171 |
- Avoid repeating similar character types - **Do not use same characters , or same workplace scenarios, or same situations etc across the 4 ideas**.
|
| 172 |
-
- Please **Don't potray the
|
| 173 |
- Please think **Out of the box** ideas. Surprise like a creative genius. Your idea can never be thought by a simple human.
|
| 174 |
---
|
| 175 |
|
|
@@ -188,9 +183,6 @@ Improved Ideas from Improver:
|
|
| 188 |
|
| 189 |
### Input:
|
| 190 |
|
| 191 |
-
**Video Topic**:
|
| 192 |
-
{state.topic[-1]}
|
| 193 |
-
|
| 194 |
**Business Details**:
|
| 195 |
{state.business_details[-1]}
|
| 196 |
|
|
@@ -223,8 +215,6 @@ Each idea creatively tells a short story that connects indirectly to the busines
|
|
| 223 |
|
| 224 |
---
|
| 225 |
|
| 226 |
-
**Video Topic**:
|
| 227 |
-
{state.topic[-1]}
|
| 228 |
|
| 229 |
**Business Details**:
|
| 230 |
{state.business_details[-1]}
|
|
@@ -252,3 +242,27 @@ Return exactly 2 things:
|
|
| 252 |
2.**If not validated**, give a short, kind explanation (under 40 words) of what could be improved, or why isn't it validated.
|
| 253 |
'''
|
| 254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
---
|
| 34 |
### Very Important Reminder:
|
| 35 |
+
- Do not start or potray the idea directly by context of the business details. Start from entirely different plot , event or character and conclude to the details at last making it creative and unique just like in the example that includes coffee slipping before the date , earthquake surviving , security guard in the luxury mall etc. These starting plots differs from the clothing business but they creatively concluded at the end.
|
| 36 |
- Every 4 ideas must be very diverse. They have to be completely different from each other.
|
| 37 |
+
- NEVER use the contexts of business details as opening scenarios - Begin with completely unrelated situations like accidents, mysteries, competitions, discoveries, or social experiments. For eg: If the context is about restaurant don't start with chef, restaurant or related things directly.
|
| 38 |
- Avoid repeating similar character types - **Do not use same characters , or same workplace scenarios, or same situations etc across the 4 ideas**.
|
| 39 |
- Please think **Out of the box** ideas. Surprise like a creative genius. Your idea can never be thought by a simple human.
|
| 40 |
|
|
|
|
| 44 |
|
| 45 |
### Your Assignment:
|
| 46 |
|
|
|
|
|
|
|
|
|
|
| 47 |
**Business Details**:
|
| 48 |
{state.business_details[-1]}
|
| 49 |
|
|
|
|
| 69 |
|
| 70 |
---
|
| 71 |
|
| 72 |
+
Now, based on the video business details above, generate **four original, 40-word promotional video ideas** that can inspire unforgettable video content.
|
| 73 |
"""
|
| 74 |
|
| 75 |
|
|
|
|
| 89 |
|
| 90 |
- **Each idea must be exactly 40 words**.
|
| 91 |
- Ideas must start with an **unrelated or abstract plot, character, or situation** — never directly with the business context.
|
| 92 |
+
- Please **Don't potray the business details in the beginning of the idea**. The business details have to come into picture as the main conclusion of the idea.
|
| 93 |
- Every 4 ideas must be very diverse. They have to be completely different from each other.
|
| 94 |
- Each idea must **creatively conclude** by connecting to the business.
|
| 95 |
- **Avoid repeating** characters, locations, or similar scenarios across the four ideas.
|
|
|
|
| 100 |
|
| 101 |
---
|
| 102 |
|
|
|
|
|
|
|
| 103 |
|
| 104 |
### Business Details:
|
| 105 |
{state.business_details[-1]}
|
|
|
|
| 160 |
---
|
| 161 |
|
| 162 |
### Very Important Reminder:
|
| 163 |
+
- Do not start or potray the idea directly by context of the business details. Start from entirely different plot , event or character and conclude to the details at last making it creative and unique just like in the example that includes coffee slipping before the date , earthquake surviving , security guard in the luxury mall etc. These starting plots differs from the clothing business but they creatively concluded at the end.
|
| 164 |
- Every 4 ideas must be very diverse. They have to be completely different from each other.
|
| 165 |
+
- NEVER use the contexts of business details as opening scenarios - Begin with completely unrelated situations like accidents, mysteries, competitions, discoveries, or social experiments. For eg: If the context is about restaurant don't start with chef, restaurant or related things directly.
|
| 166 |
- Avoid repeating similar character types - **Do not use same characters , or same workplace scenarios, or same situations etc across the 4 ideas**.
|
| 167 |
+
- Please **Don't potray the business details in the beginning of the idea**. The context of business details have to come into picture as the main conclusion of the idea.
|
| 168 |
- Please think **Out of the box** ideas. Surprise like a creative genius. Your idea can never be thought by a simple human.
|
| 169 |
---
|
| 170 |
|
|
|
|
| 183 |
|
| 184 |
### Input:
|
| 185 |
|
|
|
|
|
|
|
|
|
|
| 186 |
**Business Details**:
|
| 187 |
{state.business_details[-1]}
|
| 188 |
|
|
|
|
| 215 |
|
| 216 |
---
|
| 217 |
|
|
|
|
|
|
|
| 218 |
|
| 219 |
**Business Details**:
|
| 220 |
{state.business_details[-1]}
|
|
|
|
| 242 |
2.**If not validated**, give a short, kind explanation (under 40 words) of what could be improved, or why isn't it validated.
|
| 243 |
'''
|
| 244 |
|
| 245 |
+
def idea_refinement_prompt():
|
| 246 |
+
return """
|
| 247 |
+
You are a creative idea refinement assistant. Your goal is to help the user finalize a single powerful short-form video idea for Instagram or TikTok by analyzing the four given ideas.
|
| 248 |
+
The user will do some request to enhance their ideas. You have to creatively process their query analyzing the four given ideas and return the edited best idea.
|
| 249 |
+
|
| 250 |
+
🎯 Your Rules:
|
| 251 |
+
1. Clearly interpret the user's instruction.
|
| 252 |
+
2. Modify or combine ideas strictly based on what the user says.
|
| 253 |
+
3. If the user says "undo" or "go back", return the previous version exactly as it was.
|
| 254 |
+
4. **NEVER ask the user questions.** You only act and respond with an idea.
|
| 255 |
+
5. Do not generate random or new ideas. Only improve, combine, or revert.
|
| 256 |
+
6. Maintain a strong, clear, creative narrative in every version.
|
| 257 |
+
7. Ensure each output is refined, realistic, and aligned with promotional goals.
|
| 258 |
+
9. If you're processing more than one idea, make sure the plot flows very smoothly relating them.
|
| 259 |
+
|
| 260 |
+
📢 STRICT OUTPUT POLICY:
|
| 261 |
+
- **Only return the current best idea as plain text.**
|
| 262 |
+
- **No explanations, no headers, no labels.**
|
| 263 |
+
- **Do not ask the user anything back.**
|
| 264 |
+
- Remember, you have to give the response of your idea in **exactly 30 words**.
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
You must function like a deterministic idea-refiner — each input must result in a single, story-rich output idea.
|
| 268 |
+
"""
|
ideation_agent/utils/state.py
CHANGED
|
@@ -4,7 +4,6 @@ import operator
|
|
| 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] = []
|
|
@@ -16,9 +15,8 @@ class State(BaseModel):
|
|
| 16 |
validator4_response: Annotated[list[str],operator.add] = []
|
| 17 |
disagreement_reason: Annotated[list[str],operator.add] = []
|
| 18 |
|
| 19 |
-
|
| 20 |
class QueryFormatter(BaseModel):
|
| 21 |
-
|
| 22 |
|
| 23 |
class ImproverResponseFormatter(BaseModel):
|
| 24 |
faults: str= Field(description="Returns the faults of the critic's response if any.")
|
|
@@ -27,10 +25,8 @@ class ImproverResponseFormatter(BaseModel):
|
|
| 27 |
improved_idea3: str = Field(description="Returns the third improved idea of exactly 40 words. If no faults found, repeat the critic's version.")
|
| 28 |
improved_idea4: str = Field(description="Returns the fourth improved idea of exactly 40 words. If no faults found, repeat the critic's version.")
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
class ValidationFormatter(BaseModel):
|
| 35 |
-
result: str = Field(description="Returns **validated** if the story is validated. Returns **not validated** if story is not validated.")
|
| 36 |
-
reason: str = Field(description="Returns the reason why the story is validated or not validated.")
|
|
|
|
| 4 |
from typing import Annotated
|
| 5 |
|
| 6 |
class State(BaseModel):
|
|
|
|
| 7 |
business_details : Annotated[list[dict],operator.add] = []
|
| 8 |
ideator_response: Annotated[list[str],operator.add] = []
|
| 9 |
critic_response: Annotated[list[str],operator.add] = []
|
|
|
|
| 15 |
validator4_response: Annotated[list[str],operator.add] = []
|
| 16 |
disagreement_reason: Annotated[list[str],operator.add] = []
|
| 17 |
|
|
|
|
| 18 |
class QueryFormatter(BaseModel):
|
| 19 |
+
business_details: str = Field(description="The details of the business that user passes to the agent")
|
| 20 |
|
| 21 |
class ImproverResponseFormatter(BaseModel):
|
| 22 |
faults: str= Field(description="Returns the faults of the critic's response if any.")
|
|
|
|
| 25 |
improved_idea3: str = Field(description="Returns the third improved idea of exactly 40 words. If no faults found, repeat the critic's version.")
|
| 26 |
improved_idea4: str = Field(description="Returns the fourth improved idea of exactly 40 words. If no faults found, repeat the critic's version.")
|
| 27 |
|
| 28 |
+
class ValidationFormatter(BaseModel):
|
| 29 |
+
result: str = Field(description="Returns **validated** if the idea is validated. Returns **not validated** if story is not validated.")
|
| 30 |
+
reason: str = Field(description="If the idea is **not validated**, it returns the reason why it is not validated.")
|
| 31 |
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ideation_agent/utils/tools.py
CHANGED
|
@@ -8,10 +8,10 @@ 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(
|
| 12 |
'''
|
| 13 |
Always invoke this tool.
|
| 14 |
-
Retrieve influencer's data by semantic search of **
|
| 15 |
'''
|
| 16 |
# === Load CSV ===
|
| 17 |
csv_path = 'extracted_data.csv'
|
|
@@ -29,7 +29,7 @@ def retrieve_tool(video_topic):
|
|
| 29 |
# === Load SentenceTransformer model ===
|
| 30 |
|
| 31 |
# === Encode the query and search ===
|
| 32 |
-
query_embedding = ST.encode(str(
|
| 33 |
top_k=7
|
| 34 |
distances, indices = index.search(query_embedding, top_k)
|
| 35 |
|
|
|
|
| 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(business_details):
|
| 12 |
'''
|
| 13 |
Always invoke this tool.
|
| 14 |
+
Retrieve influencer's data by semantic search of **business details**.
|
| 15 |
'''
|
| 16 |
# === Load CSV ===
|
| 17 |
csv_path = 'extracted_data.csv'
|
|
|
|
| 29 |
# === Load SentenceTransformer model ===
|
| 30 |
|
| 31 |
# === Encode the query and search ===
|
| 32 |
+
query_embedding = ST.encode(str(business_details)).reshape(1, -1).astype('float32')
|
| 33 |
top_k=7
|
| 34 |
distances, indices = index.search(query_embedding, top_k)
|
| 35 |
|
main.py
CHANGED
|
@@ -12,6 +12,7 @@ from brainstroming_agent.utils.utils import encode_image_to_base64 , generate_fi
|
|
| 12 |
from idea_to_budget_agent.agent import budget_calculator
|
| 13 |
from ideation_agent.agent import ideation_graph
|
| 14 |
from langgraph.errors import GraphRecursionError
|
|
|
|
| 15 |
|
| 16 |
import json
|
| 17 |
|
|
@@ -22,6 +23,7 @@ context_analysis_graph = IntroductionChatbot()
|
|
| 22 |
business_interaction_graph = BusinessInteractionChatbot()
|
| 23 |
idea_graph = ideation_graph()
|
| 24 |
brainstrom_graph = brainstroming_graph()
|
|
|
|
| 25 |
|
| 26 |
stored_data={}
|
| 27 |
# stored_data['business_details']={"business_type": "fitness and gym", "platform": "instagram, tiktok", "target_audience": "every software needed clients", "business_goals": "to expand in every cities of nepal", "offerings": "nepali cloths and products", "Challenges_faced": "finding new customers, attracting large customers"}
|
|
@@ -39,7 +41,10 @@ stored_data['business_details'] = {
|
|
| 39 |
stored_data['final_ideation']= ['''A street magician performs tricks, leaving a crowd awestruck. One trick falters, inspiring him to hit the gym. Months later, he fuses fitness with magic, showcasing strength through performance, proving that transformation can captivate and inspire a community''',
|
| 40 |
'''A group of strangers attends a quirky food festival, each trying bizarre dishes. One adventurer finds a fitness coach among them. They bond over health, sparking a weekly workout group that brings the community together, blending fun and fitness effortlessly.''',
|
| 41 |
'''A lost hiker discovers a hidden waterfall, but slips on the rocks, nearly falling. A passing fitness enthusiast helps him up, encouraging regular exercise for safety and strength. Together, they start a hiking club, uniting fitness and nature lovers in their city''',
|
| 42 |
-
'''A
|
|
|
|
|
|
|
|
|
|
| 43 |
class UserMessage(BaseModel):
|
| 44 |
message: str
|
| 45 |
@app.post("/context-analysis")
|
|
@@ -70,12 +75,11 @@ class IdeationRequest(BaseModel):
|
|
| 70 |
topic : List[str]
|
| 71 |
|
| 72 |
@app.post("/ideation")
|
| 73 |
-
def ideation_endpoint(
|
| 74 |
config={"recursion_limit":15, "configurable": {"thread_id": "ideation_thread123"}}
|
| 75 |
try:
|
| 76 |
result = idea_graph.invoke(
|
| 77 |
{
|
| 78 |
-
'topic': request.topic,
|
| 79 |
'business_details': [stored_data['business_details']]
|
| 80 |
},
|
| 81 |
config=config,
|
|
@@ -88,8 +92,24 @@ def ideation_endpoint(request:IdeationRequest):
|
|
| 88 |
result = idea_graph.get_state({"configurable": {"thread_id": "ideation_thread123"}})
|
| 89 |
return {'response': result[0]}
|
| 90 |
|
| 91 |
-
class
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
@app.post("/budget-mapping")
|
| 95 |
def budget_mapping_endpoint():
|
|
@@ -107,7 +127,7 @@ def brainstroming_endpoint(
|
|
| 107 |
request: BrainstormRequest, # 🔥 Full JSON body here
|
| 108 |
):
|
| 109 |
result = brainstrom_graph.invoke({
|
| 110 |
-
'
|
| 111 |
'images': request.image_base64_list,
|
| 112 |
'latest_preferred_topics': request.preferred_topics,
|
| 113 |
'business_details': (lambda d: d['business_details'] if 'business_details' in d else {})(stored_data)
|
|
|
|
| 12 |
from idea_to_budget_agent.agent import budget_calculator
|
| 13 |
from ideation_agent.agent import ideation_graph
|
| 14 |
from langgraph.errors import GraphRecursionError
|
| 15 |
+
from human_refined_ideation.agent import human_refined_idea
|
| 16 |
|
| 17 |
import json
|
| 18 |
|
|
|
|
| 23 |
business_interaction_graph = BusinessInteractionChatbot()
|
| 24 |
idea_graph = ideation_graph()
|
| 25 |
brainstrom_graph = brainstroming_graph()
|
| 26 |
+
human_refine_graph = human_refined_idea()
|
| 27 |
|
| 28 |
stored_data={}
|
| 29 |
# stored_data['business_details']={"business_type": "fitness and gym", "platform": "instagram, tiktok", "target_audience": "every software needed clients", "business_goals": "to expand in every cities of nepal", "offerings": "nepali cloths and products", "Challenges_faced": "finding new customers, attracting large customers"}
|
|
|
|
| 41 |
stored_data['final_ideation']= ['''A street magician performs tricks, leaving a crowd awestruck. One trick falters, inspiring him to hit the gym. Months later, he fuses fitness with magic, showcasing strength through performance, proving that transformation can captivate and inspire a community''',
|
| 42 |
'''A group of strangers attends a quirky food festival, each trying bizarre dishes. One adventurer finds a fitness coach among them. They bond over health, sparking a weekly workout group that brings the community together, blending fun and fitness effortlessly.''',
|
| 43 |
'''A lost hiker discovers a hidden waterfall, but slips on the rocks, nearly falling. A passing fitness enthusiast helps him up, encouraging regular exercise for safety and strength. Together, they start a hiking club, uniting fitness and nature lovers in their city''',
|
| 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
|
| 50 |
@app.post("/context-analysis")
|
|
|
|
| 75 |
topic : List[str]
|
| 76 |
|
| 77 |
@app.post("/ideation")
|
| 78 |
+
def ideation_endpoint():
|
| 79 |
config={"recursion_limit":15, "configurable": {"thread_id": "ideation_thread123"}}
|
| 80 |
try:
|
| 81 |
result = idea_graph.invoke(
|
| 82 |
{
|
|
|
|
| 83 |
'business_details': [stored_data['business_details']]
|
| 84 |
},
|
| 85 |
config=config,
|
|
|
|
| 92 |
result = idea_graph.get_state({"configurable": {"thread_id": "ideation_thread123"}})
|
| 93 |
return {'response': result[0]}
|
| 94 |
|
| 95 |
+
class RefineIdeationRequest(BaseModel):
|
| 96 |
+
query: str
|
| 97 |
+
thread_id: Optional[str]="refine_ideas_thread"
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
@app.post("/human-idea-refining")
|
| 101 |
+
def human_idea_refine_endpoint(request:RefineIdeationRequest):
|
| 102 |
+
stored_data['human_ideation_interactions'].append({"role": "user", "content": request.query})
|
| 103 |
+
response = human_refine_graph.invoke(
|
| 104 |
+
{
|
| 105 |
+
'query': stored_data['human_ideation_interactions'],
|
| 106 |
+
'final_ideation': stored_data['final_ideation']
|
| 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 |
+
|
| 113 |
|
| 114 |
@app.post("/budget-mapping")
|
| 115 |
def budget_mapping_endpoint():
|
|
|
|
| 127 |
request: BrainstormRequest, # 🔥 Full JSON body here
|
| 128 |
):
|
| 129 |
result = brainstrom_graph.invoke({
|
| 130 |
+
'idea': [stored_data['final_ideation'][0]],
|
| 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)
|
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
|
@@ -1,10 +1,10 @@
|
|
| 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
|
|
|
|
| 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 ""
|
utils/models_loader.py
CHANGED
|
@@ -67,18 +67,17 @@ ST = HFEmbeddingAPI(
|
|
| 67 |
|
| 68 |
# )
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
# temperature=0.7,
|
| 73 |
-
# max_tokens=500,
|
| 74 |
-
# )
|
| 75 |
-
|
| 76 |
-
improver_llm = ChatGroq(
|
| 77 |
-
model="llama3-8b-8192",
|
| 78 |
temperature=0.7,
|
| 79 |
max_tokens=500,
|
| 80 |
-
|
| 81 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
ideator_llm = improver_llm
|
| 83 |
critic_llm = improver_llm
|
| 84 |
validator_llm = improver_llm
|
|
|
|
| 67 |
|
| 68 |
# )
|
| 69 |
|
| 70 |
+
improver_llm = ChatOpenAI(
|
| 71 |
+
model="gpt-4o-mini",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
temperature=0.7,
|
| 73 |
max_tokens=500,
|
|
|
|
| 74 |
)
|
| 75 |
+
|
| 76 |
+
# improver_llm = ChatGroq(
|
| 77 |
+
# model="llama3-8b-8192",
|
| 78 |
+
# temperature=0.7,
|
| 79 |
+
# max_tokens=500,
|
| 80 |
+
# )
|
| 81 |
ideator_llm = improver_llm
|
| 82 |
critic_llm = improver_llm
|
| 83 |
validator_llm = improver_llm
|