File size: 7,970 Bytes
2c5e855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59de368
 
 
2c5e855
 
 
59de368
 
 
2c5e855
 
59de368
 
 
 
f36fcc8
 
59de368
 
 
 
624de5a
 
59de368
 
 
 
 
2c5e855
59de368
 
 
 
 
624de5a
59de368
 
 
 
 
624de5a
59de368
 
 
 
 
624de5a
59de368
 
 
 
 
2c5e855
59de368
 
 
 
 
2c5e855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59de368
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# utils/prompts.py - Custom prompt management for PDF Analysis & Orchestrator
import json
import os
from pathlib import Path
from typing import Dict, List, Optional
from config import Config

class PromptManager:
    """Manage custom prompts for analysis"""
    
    def __init__(self, prompts_dir: str = None):
        self.prompts_dir = Path(prompts_dir or Config.PROMPTS_DIR)
        self.prompts_dir.mkdir(parents=True, exist_ok=True)
        self.prompts_file = self.prompts_dir / "custom_prompts.json"
        self._load_prompts()
    
    def _load_prompts(self) -> None:
        """Load prompts from file"""
        if self.prompts_file.exists():
            try:
                with open(self.prompts_file, 'r', encoding='utf-8') as f:
                    self.prompts = json.load(f)
            except Exception:
                self.prompts = {}
        else:
            self.prompts = self._get_default_prompts()
            self._save_prompts()
    
    def _get_default_prompts(self) -> Dict[str, Dict[str, str]]:
        """Get default prompt templates"""
        return {
            "summarize": {
                "name": "Summarize Document",
                "description": "Create a concise summary of the document",
                "template": "Summarize this document in 3-5 key points, highlighting the main ideas and conclusions.",
                "category": "basic"
            },
            "explain_simple": {
                "name": "Explain Simply",
                "description": "Explain complex content for a general audience",
                "template": "Explain this document in simple terms that a 10-year-old could understand. Use analogies and examples where helpful.",
                "category": "explanation"
            },
            "executive_summary": {
                "name": "Executive Summary",
                "description": "Create an executive summary for decision makers",
                "template": "Create an executive summary of this document, focusing on key findings, recommendations, and business implications.",
                "category": "business"
            },
            "technical_analysis": {
                "name": "Technical Analysis",
                "description": "Provide detailed technical analysis",
                "template": "Provide a detailed technical analysis of this document, including methodology, data analysis, and technical conclusions.",
                "category": "technical"
            },
            "theme_segmentation": {
                "name": "Theme Segmentation",
                "description": "Break down document by themes and topics",
                "template": "Segment this document by main themes and topics. Identify key themes and provide a brief summary of each section.",
                "category": "organization"
            },
            "key_findings": {
                "name": "Key Findings",
                "description": "Extract key findings and insights",
                "template": "Extract and analyze the key findings, insights, and recommendations from this document. Highlight the most important points.",
                "category": "analysis"
            },
            "research_pipeline": {
                "name": "R&D Pipeline Analysis",
                "description": "Extract high-value insights for R&D pipeline development",
                "template": "Act as a senior research analyst: identify novel ideas, breakthrough concepts, and innovative approaches with high product/engineering impact. Convert insights into concrete R&D pipeline outcomes: specific experiments to test, prototypes to build, and product decisions to make. Prioritize by transformative potential and measurable business value.",
                "category": "research"
            },
            "innovation_assessment": {
                "name": "Innovation Opportunity Assessment",
                "description": "Assess commercial viability and innovation potential",
                "template": "Analyze this document for breakthrough innovation opportunities. Identify novel technical concepts, assess their commercial viability, market readiness, and competitive advantage potential. Generate specific recommendations for experimental validation, prototype development, and strategic product decisions.",
                "category": "research"
            },
            "experimental_design": {
                "name": "Experimental Design Framework",
                "description": "Design specific experiments and validation methodologies",
                "template": "Extract technical concepts and methodologies from this document. Design specific experimental frameworks to validate key hypotheses, including success metrics, validation criteria, and implementation timelines. Focus on experiments that could drive significant product/engineering advancement.",
                "category": "research"
            },
            "prototype_roadmap": {
                "name": "Prototype Development Roadmap",
                "description": "Create technical implementation roadmap for prototypes",
                "template": "Identify technical concepts suitable for prototype development. Create a structured roadmap for building technical implementations that demonstrate key innovations. Include technical specifications, development phases, resource requirements, and success criteria for each prototype.",
                "category": "research"
            }
        }
    
    def _save_prompts(self) -> None:
        """Save prompts to file"""
        try:
            with open(self.prompts_file, 'w', encoding='utf-8') as f:
                json.dump(self.prompts, f, indent=2, ensure_ascii=False)
        except Exception as e:
            print(f"Error saving prompts: {e}")
    
    def get_prompt(self, prompt_id: str) -> Optional[str]:
        """Get a specific prompt template"""
        return self.prompts.get(prompt_id, {}).get("template")
    
    def get_all_prompts(self) -> Dict[str, Dict[str, str]]:
        """Get all available prompts"""
        return self.prompts.copy()
    
    def get_prompts_by_category(self, category: str) -> Dict[str, Dict[str, str]]:
        """Get prompts filtered by category"""
        return {
            pid: prompt for pid, prompt in self.prompts.items()
            if prompt.get("category") == category
        }
    
    def add_prompt(self, prompt_id: str, name: str, description: str, 
                   template: str, category: str = "custom") -> bool:
        """Add a new custom prompt"""
        try:
            self.prompts[prompt_id] = {
                "name": name,
                "description": description,
                "template": template,
                "category": category
            }
            self._save_prompts()
            return True
        except Exception:
            return False
    
    def update_prompt(self, prompt_id: str, **kwargs) -> bool:
        """Update an existing prompt"""
        if prompt_id not in self.prompts:
            return False
        
        try:
            self.prompts[prompt_id].update(kwargs)
            self._save_prompts()
            return True
        except Exception:
            return False
    
    def delete_prompt(self, prompt_id: str) -> bool:
        """Delete a custom prompt (cannot delete default prompts)"""
        if prompt_id in self.prompts and self.prompts[prompt_id].get("category") == "custom":
            try:
                del self.prompts[prompt_id]
                self._save_prompts()
                return True
            except Exception:
                return False
        return False
    
    def get_categories(self) -> List[str]:
        """Get all available categories"""
        categories = set()
        for prompt in self.prompts.values():
            categories.add(prompt.get("category", "uncategorized"))
        return sorted(list(categories))