import os from modules.company_score import score_company from modules.rag_retriever import retrieve_contexts # ← ここを修正(modules) from modules.proposal_generator import make_proposal, suggest_next_actions from modules.exporters import export_docx, export_pptx from modules.emailer import build_tracking_url from modules.utils import truncate def _make_email(company_name: str, lead_email: str, proposal_md: str) -> dict: tracking = build_tracking_url( identifier=f"{company_name}", payload={ "company": company_name, "redirect": os.getenv("PUBLIC_BASE_URL", "/") }, ) subject = f"{company_name}様向けご提案(無料PoCのご案内)" body = ( f"{company_name} ご担当者様\n\n" "突然のご連絡失礼いたします。貴社向けに要点を1枚にまとめた提案書を作成しました。\n\n" f"▼提案要旨\n{truncate(proposal_md, 800)}\n\n" f"詳細はこちら(クリック計測用リンク):\n{tracking}\n\n" "30分ほどオンラインでディスカッションできれば嬉しいです。\n" "ご検討のほど、よろしくお願いいたします。\n" "\n--\nAgent Studio" ) return {"subject": subject, "body": body} def run_full_workflow(company_name: str, company_website: str, lead_email: str | None, objective: str, temperature: float=0.4) -> dict: # 1) スコアリング score = score_company(company_name, company_website) # 2) コンテキスト検索(RAG) query = f"{company_name} {objective} {company_website}" top_contexts = retrieve_contexts(query, k=5) # 3) 提案生成 proposal_md = make_proposal(company_name, objective, top_contexts, temperature=temperature) # 4) エクスポート docx_path = export_docx(proposal_md, company_name) pptx_path = export_pptx(proposal_md, company_name) # 5) メール作成 email = _make_email(company_name, lead_email or "", proposal_md) # 6) 次アクション提案 next_actions = suggest_next_actions(proposal_md, score["overall"]) return { "score": score, "top_contexts": top_contexts, "proposal_markdown": proposal_md, "exports": { "docx_path": docx_path, "pptx_path": pptx_path }, "email": email, "next_actions": next_actions }