Spaces:
Sleeping
Sleeping
| # Message customization logic | |
| from dataclasses import dataclass | |
| from typing import Any, TypeVar | |
| from langchain.output_parsers import OutputFixingParser | |
| from langchain.output_parsers.prompts import NAIVE_FIX_PROMPT | |
| from langchain_core.output_parsers import StrOutputParser | |
| from langchain_core.runnables import RunnableSerializable | |
| from .config import settings | |
| from .model import gpt4o | |
| T = TypeVar("T") | |
| extraction_messages = [ | |
| ( | |
| "system", | |
| """あなたは企業情報の分析に優れた専門家です。 | |
| 与えられた情報を元に、可能な限り詳細で有益な企業概要を**日本語**で作成してください。 | |
| ### **概要に含めるべき内容:** | |
| 1. **会社名とアイデンティティ** | |
| - 会社名、設立背景、歴史、特徴など。 | |
| - もし背景情報が不足している場合、**可能な推測(例: 業界や関連事業の一般的な傾向)** を交えながら説明する。 | |
| 2. **コアビジネスとミッション** | |
| - 事業内容、主要サービス、企業の使命や目標。 | |
| - もしミッションが明確でない場合、事業内容から推測できる可能性のある方向性を述べる。 | |
| 3. **主要プロジェクトやイニシアティブ** | |
| - 企業が取り組んでいる重要なプロジェクトや技術。 | |
| - **具体的な情報がない場合でも、企業の業界における一般的な取り組みを補足し、可能な活動内容を示唆する。** | |
| 4. **業界と市場での地位** | |
| - 企業が属する業界、市場での競争環境、主な競合企業。 | |
| - **業界情報を活用して、可能な市場ポジションを考察する。** | |
| ### **重要なルール** | |
| - **与えられた情報を最大限活用し、不完全な場合もできる限り推測を交えて説明する。** | |
| - **決して情報を捏造せず、信頼できる情報源が不足している場合は、その旨を明示する。** | |
| - **単なる「情報が不足しています」という回答ではなく、読者が次に取るべき調査ステップを提案する。** | |
| """ | |
| ), | |
| ( | |
| "human", | |
| """以下の企業情報を分析し、可能な限り詳細な企業概要を **日本語** で作成してください。 | |
| **提供された企業情報:** | |
| {scraped_message} | |
| **要求事項:** | |
| - 企業の業界、事業内容、競争環境を考慮した **具体的な説明** を記述すること。 | |
| - 情報が不足している場合でも、 **業界の一般的な知識を活用し、可能な考察を加えること**。 | |
| - もし詳細情報が不足している場合は、 **読者が追加情報を得るための推奨アクション(例: 公式サイトの確認、ニュースリリースのチェック)** を明示すること。 | |
| """ | |
| ) | |
| ] | |
| generation_messages = [ | |
| ( | |
| "system", | |
| """You are an expert in writing **personalized, compelling, and persuasive sales messages** in Japanese. | |
| Your task is to craft a customized message based on the company's business summary and the provided generic message. | |
| ### **Guidelines:** | |
| 1. **Personalize the message** using the company's industry, goals, and key projects. | |
| 2. **Make a strong connection** between the company's mission and the value proposition in the generic message. | |
| 3. **Keep the core intent** of the generic message intact while making it highly relevant. | |
| 4. **Ensure the message flows naturally** and does not feel robotic or forced. | |
| 5. **If the company summary lacks details**, return the generic message **without forced personalization**. | |
| """ | |
| ), | |
| ( | |
| "human", | |
| """Generate a well-structured and persuasive sales message in **Japanese** based on the following details: | |
| **Company Summary:** | |
| {summary_output} | |
| **Generic Message:** | |
| {generic_message} | |
| ### **Instructions:** | |
| - Begin with: **"貴社は [business field/service] に従事しており、"** | |
| - Clearly highlight how the company's **projects and goals** align with the proposed solution. | |
| - Use a **smooth, engaging, and persuasive tone** without making it sound artificial. | |
| - If the summary lacks sufficient details, simply **return the generic message as it is** without attempting to force customization. | |
| """ | |
| ) | |
| ] | |
| def build_output_fixing_parser( | |
| *, parser: Any, llm: Any = gpt4o | |
| ) -> OutputFixingParser[Any]: | |
| """Build output fixing parser with retry capability""" | |
| retry_chain: RunnableSerializable[dict[str, Any], str] = NAIVE_FIX_PROMPT | llm | StrOutputParser() | |
| return OutputFixingParser( | |
| parser=parser, | |
| retry_chain=retry_chain, | |
| max_retries=settings.LANGCHAIN_RETRY_LIMIT, | |
| ) | |