# from langchain_core.prompts import ChatPromptTemplate # from src.config.llm import llm_2_0 as llm, llm_2_5_flash_preview # from pydantic import BaseModel, Field # from langchain_community.tools import DuckDuckGoSearchResults # from langgraph.prebuilt import create_react_agent # duckduckgo_search = DuckDuckGoSearchResults(max_results=10, output_format="json") # script_structure_analyzer_prompt = ChatPromptTemplate.from_messages( # [ # ( # "system", # """ # Vai trò: Bạn là Script Structure Analyzer trong một workflow của một nhóm các agent. # Instruction: # - Tự động phân tích kịch bản gốc, tách các phần (Mở bài, Thân bài, Điểm chốt, CTA) # - Xác định công thức cấu trúc (AIDA, PAS, BFB,...) # - Trích xuất hook, câu chuyển đoạn, CTA # - Phát hiện điểm mạnh/yếu/chỗ lạc nhịp # Input: Script gốc # Output: # - Outline: # - Mở bài # - Thân bài # - Điểm chốt # - CTA # - Công thức cấu trúc # - AIDA: Attention, Interest, Desire, Action # - PAS: Problem, Agitation, Solution # - BFB: Belief, Feeling, Behavior # - Hook # - Câu chuyển đoạn # - CTA # - Điểm mạnh/yếu/chỗ lạc nhịp # """, # ), # ("user", "input script: {script}"), # ] # ) # comment_insight_extractor_prompt = ChatPromptTemplate.from_messages( # [ # ( # "system", # """ # Vai trò: Bạn là Comment Insight Extractor trong một workflow của một nhóm các agent phân tích youtube video. # Instruction: # - Đọc, phân tích tất cả comment, trích xuất insight # - lọc ra các câu hỏi lặp lại, nỗi sợ/mong muốn/lợi ích/ngôn ngữ quen thuộc # - So sánh insight với script gốc và xác định thiếu sót. # Input: # - Output từ Script Structure Analyzer Agent Youtube Video # - Comment # Output: # - Insights Table: # - Insight # - Original Comment # - Pain or Benefit # - Suggest for Script # - Missing From Script # - Repeated Questions # - Audience Language # """, # ), # ("user", "input comment: {comment}"), # ( # "user", # "input script_structure_analyzer_response: {script_structure_analyzer_response}", # ), # ] # ) # scientific_fact_finder_prompt = ChatPromptTemplate.from_messages( # [ # ( # "system", # """ # Vai trò: Bạn là Scientific Fact Finder trong một workflow của một nhóm các agent phân tích youtube video. # Instruction: # - Tự động research 3-5 nghiên cứu khoa học thực tế (PubMed, JAMA, Circulation, Nutrients…), tóm tắt số liệu, trích nguồn, gợi ý số liệu phù hợp cho từng đoạn trong script mới. # - So sánh fact science với script gốc và xác định thiếu sót. # Input: # - Output từ Script Structure Analyzer Agent Youtube Video # - Output từ Comment Insight Extractor Agent Youtube Video # Output List: # - Title: Tên nghiên cứu # - Summary: Tóm tắt nghiên cứu # - Source: Nguồn nghiên cứu # - Relevant for Section: Relevant cho section nào trong script mới # """, # ), # ("placeholder", "{messages}"), # ] # ) # script_re_outline_prompt = ChatPromptTemplate.from_messages( # [ # ( # "system", # """ # Vai trò: Bạn là Script Re-Outline Agent trong một workflow của một nhóm các agent. # Instruction: # Kết hợp outline cũ, insight từ comment, fact từ research để lập outline mới: Hook mới, thứ tự section mới, CTA mới, các ý chuyển mạch rõ ràng, phân bổ fact/nghiên cứu vào các section. # Input: # - Output từ Script Structure Analyzer Agent # - Output từ Comment Insight Extractor Agent # - Output từ Scientific Fact Finder Agent # Output: # - Outline mới: (Section, summary, suggested length, facts to include) # - Hook mở bài # - Thân bài 1 # - Thân bài 2 # - Điểm chốt # - CTA # - CTA position # - Transitions # - Order Logic # """, # ), # ("placeholder", "{messages}"), # ] # ) # script_writer_prompt = ChatPromptTemplate.from_messages( # [ # ( # "system", # """ # Vai trò: Bạn là Script Writer dựa trên các nội dung, insight được cung cấp. # Instruction: # - Viết lại từng phần dựa theo outline mới, dữ liệu nghiên cứu, insight comment, giữ văn liền mạch - cảm xúc - kể chuyện, format cho video YouTube (dạng văn nói, không dùng icon, chỉ text). # - Viết theo hội thoại chỉ có một người nói, không có người khác. # Input: # - Output từ Script Re-Outline Agent (Important) # - Output từ Scientific Fact Finder Agent # - Output từ Comment Insight Extractor Agent # Processing: # - Sau khi viết 1 phần, ngừng ngay. # - Output phải liền mạch, không có gạch đầu dòng. # - Tone giọng thân thiện, kể truyện, truyền cảm xúc, không dùng icon, chỉ dùng text. # - Cài hook cảm xúc, ví dụ thực tế # - Kể mở ra CTA hoặc dẫn sang phần tiếp theo. # - Có câu hỏi tu từ nhẹ nhàng # - Nhắc lại lợi ích quan trọng # - So sánh "thay vì... thì..." để khán giả thấy rõ "why" # - Không dùng icon, emoji # - Kết thúc phải là kết thúc mở đề người dùng có thể yêu cầu viết tiếp thay vì kết thúc sau khi hoàn thành đủ hook, thân bài, điểm chốt, CTA. # Output: # - Title: Tên của phần nội dung # - Content: Script content # Lưu ý: # - Chỉ gen ra một phần nội dung. # - Script được gen phả bám sát cấu trúc và có tính liền mạch, không được lủng củng, lăp lại nội dung. # - Nếu user nhập 'ok, viết cho tôi phần tiếp theo, bám sát cấu trúc, số lượng từ cho mỗi mục trong outline, các công thức tạo cảm xúc và đừng quên đối tượng khán giả là người Mỹ,giới tính nữ, trên 20 tuổi, bắt đầu, trình bày thành dạng câu văn liền mạch, dùng để làm văn nói cho video YouTube, không dùng icon' thì tiếp tục viết tiếp. # """, # ), # ("placeholder", "{messages}"), # ] # ) # chain_script_structure_analyzer = script_structure_analyzer_prompt | llm # chain_comment_insight_extractor = comment_insight_extractor_prompt | llm # scientific_fact_agent = create_react_agent( # model=llm, # tools=[duckduckgo_search], # prompt=scientific_fact_finder_prompt, # ) # chain_script_re_outline = script_re_outline_prompt | llm # chain_script_writer = script_writer_prompt | llm_2_5_flash_preview from langchain_core.prompts import ChatPromptTemplate from src.config.llm import llm_2_0 as llm, llm_2_5_flash_preview from pydantic import BaseModel, Field from langchain_community.tools import DuckDuckGoSearchResults from langgraph.prebuilt import create_react_agent duckduckgo_search = DuckDuckGoSearchResults(max_results=10, output_format="json") script_structure_analyzer_prompt = ChatPromptTemplate.from_messages( [ ( "system", "{prompt}", ), ("user", "input script: {script}"), ] ) comment_insight_extractor_prompt = ChatPromptTemplate.from_messages( [ ( "system", "{prompt}", ), ("user", "input comment: {comment}"), ( "user", "input script_structure_analyzer_response: {script_structure_analyzer_response}", ), ] ) scientific_fact_finder_prompt = ChatPromptTemplate.from_messages( [ ( "system", "{prompt}", ), ("placeholder", "{messages}"), ] ) script_re_outline_prompt = ChatPromptTemplate.from_messages( [ ( "system", "{prompt}", ), ("placeholder", "{messages}"), ] ) script_writer_prompt = ChatPromptTemplate.from_messages( [ ( "system", "{prompt}", ), ("placeholder", "{messages}"), ] ) chain_script_structure_analyzer = script_structure_analyzer_prompt | llm chain_comment_insight_extractor = comment_insight_extractor_prompt | llm def scientific_fact_finder_agent(prompt: str): prompt_template = ChatPromptTemplate.from_messages( [ ( "system", "{prompt}", ), ("placeholder", "{messages}"), ] ).partial(prompt=prompt) return create_react_agent( model=llm, tools=[duckduckgo_search], prompt=prompt_template, ) chain_script_re_outline = script_re_outline_prompt | llm chain_script_writer = script_writer_prompt | llm_2_5_flash_preview