empathy-framework 4.6.6__py3-none-any.whl → 4.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/METADATA +7 -6
- empathy_framework-4.7.0.dist-info/RECORD +354 -0
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/top_level.txt +0 -2
- empathy_healthcare_plugin/monitors/monitoring/__init__.py +9 -9
- empathy_llm_toolkit/agent_factory/__init__.py +6 -6
- empathy_llm_toolkit/agent_factory/adapters/wizard_adapter.py +7 -10
- empathy_llm_toolkit/agents_md/__init__.py +22 -0
- empathy_llm_toolkit/agents_md/loader.py +218 -0
- empathy_llm_toolkit/agents_md/parser.py +271 -0
- empathy_llm_toolkit/agents_md/registry.py +307 -0
- empathy_llm_toolkit/commands/__init__.py +51 -0
- empathy_llm_toolkit/commands/context.py +375 -0
- empathy_llm_toolkit/commands/loader.py +301 -0
- empathy_llm_toolkit/commands/models.py +231 -0
- empathy_llm_toolkit/commands/parser.py +371 -0
- empathy_llm_toolkit/commands/registry.py +429 -0
- empathy_llm_toolkit/config/__init__.py +8 -8
- empathy_llm_toolkit/config/unified.py +3 -7
- empathy_llm_toolkit/context/__init__.py +22 -0
- empathy_llm_toolkit/context/compaction.py +455 -0
- empathy_llm_toolkit/context/manager.py +434 -0
- empathy_llm_toolkit/hooks/__init__.py +24 -0
- empathy_llm_toolkit/hooks/config.py +306 -0
- empathy_llm_toolkit/hooks/executor.py +289 -0
- empathy_llm_toolkit/hooks/registry.py +302 -0
- empathy_llm_toolkit/hooks/scripts/__init__.py +39 -0
- empathy_llm_toolkit/hooks/scripts/evaluate_session.py +201 -0
- empathy_llm_toolkit/hooks/scripts/first_time_init.py +285 -0
- empathy_llm_toolkit/hooks/scripts/pre_compact.py +207 -0
- empathy_llm_toolkit/hooks/scripts/session_end.py +183 -0
- empathy_llm_toolkit/hooks/scripts/session_start.py +163 -0
- empathy_llm_toolkit/hooks/scripts/suggest_compact.py +225 -0
- empathy_llm_toolkit/learning/__init__.py +30 -0
- empathy_llm_toolkit/learning/evaluator.py +438 -0
- empathy_llm_toolkit/learning/extractor.py +514 -0
- empathy_llm_toolkit/learning/storage.py +560 -0
- empathy_llm_toolkit/providers.py +4 -11
- empathy_llm_toolkit/security/__init__.py +17 -17
- empathy_llm_toolkit/utils/tokens.py +2 -5
- empathy_os/__init__.py +202 -70
- empathy_os/cache_monitor.py +5 -3
- empathy_os/cli/__init__.py +11 -55
- empathy_os/cli/__main__.py +29 -15
- empathy_os/cli/commands/inspection.py +21 -12
- empathy_os/cli/commands/memory.py +4 -12
- empathy_os/cli/commands/profiling.py +198 -0
- empathy_os/cli/commands/utilities.py +27 -7
- empathy_os/cli.py +28 -57
- empathy_os/cli_unified.py +525 -1164
- empathy_os/cost_tracker.py +9 -3
- empathy_os/dashboard/server.py +200 -2
- empathy_os/hot_reload/__init__.py +7 -7
- empathy_os/hot_reload/config.py +6 -7
- empathy_os/hot_reload/integration.py +35 -35
- empathy_os/hot_reload/reloader.py +57 -57
- empathy_os/hot_reload/watcher.py +28 -28
- empathy_os/hot_reload/websocket.py +2 -2
- empathy_os/memory/__init__.py +11 -4
- empathy_os/memory/claude_memory.py +1 -1
- empathy_os/memory/cross_session.py +8 -12
- empathy_os/memory/edges.py +6 -6
- empathy_os/memory/file_session.py +770 -0
- empathy_os/memory/graph.py +30 -30
- empathy_os/memory/nodes.py +6 -6
- empathy_os/memory/short_term.py +15 -9
- empathy_os/memory/unified.py +606 -140
- empathy_os/meta_workflows/agent_creator.py +3 -9
- empathy_os/meta_workflows/cli_meta_workflows.py +113 -53
- empathy_os/meta_workflows/form_engine.py +6 -18
- empathy_os/meta_workflows/intent_detector.py +64 -24
- empathy_os/meta_workflows/models.py +3 -1
- empathy_os/meta_workflows/pattern_learner.py +13 -31
- empathy_os/meta_workflows/plan_generator.py +55 -47
- empathy_os/meta_workflows/session_context.py +2 -3
- empathy_os/meta_workflows/workflow.py +20 -51
- empathy_os/models/cli.py +2 -2
- empathy_os/models/tasks.py +1 -2
- empathy_os/models/telemetry.py +4 -1
- empathy_os/models/token_estimator.py +3 -1
- empathy_os/monitoring/alerts.py +938 -9
- empathy_os/monitoring/alerts_cli.py +346 -183
- empathy_os/orchestration/execution_strategies.py +12 -29
- empathy_os/orchestration/pattern_learner.py +20 -26
- empathy_os/orchestration/real_tools.py +6 -15
- empathy_os/platform_utils.py +2 -1
- empathy_os/plugins/__init__.py +2 -2
- empathy_os/plugins/base.py +64 -64
- empathy_os/plugins/registry.py +32 -32
- empathy_os/project_index/index.py +49 -15
- empathy_os/project_index/models.py +1 -2
- empathy_os/project_index/reports.py +1 -1
- empathy_os/project_index/scanner.py +1 -0
- empathy_os/redis_memory.py +10 -7
- empathy_os/resilience/__init__.py +1 -1
- empathy_os/resilience/health.py +10 -10
- empathy_os/routing/__init__.py +7 -7
- empathy_os/routing/chain_executor.py +37 -37
- empathy_os/routing/classifier.py +36 -36
- empathy_os/routing/smart_router.py +40 -40
- empathy_os/routing/{wizard_registry.py → workflow_registry.py} +47 -47
- empathy_os/scaffolding/__init__.py +8 -8
- empathy_os/scaffolding/__main__.py +1 -1
- empathy_os/scaffolding/cli.py +28 -28
- empathy_os/socratic/__init__.py +3 -19
- empathy_os/socratic/ab_testing.py +25 -36
- empathy_os/socratic/blueprint.py +38 -38
- empathy_os/socratic/cli.py +34 -20
- empathy_os/socratic/collaboration.py +30 -28
- empathy_os/socratic/domain_templates.py +9 -1
- empathy_os/socratic/embeddings.py +17 -13
- empathy_os/socratic/engine.py +135 -70
- empathy_os/socratic/explainer.py +70 -60
- empathy_os/socratic/feedback.py +24 -19
- empathy_os/socratic/forms.py +15 -10
- empathy_os/socratic/generator.py +51 -35
- empathy_os/socratic/llm_analyzer.py +25 -23
- empathy_os/socratic/mcp_server.py +99 -159
- empathy_os/socratic/session.py +19 -13
- empathy_os/socratic/storage.py +98 -67
- empathy_os/socratic/success.py +38 -27
- empathy_os/socratic/visual_editor.py +51 -39
- empathy_os/socratic/web_ui.py +99 -66
- empathy_os/telemetry/cli.py +3 -1
- empathy_os/telemetry/usage_tracker.py +1 -3
- empathy_os/test_generator/__init__.py +3 -3
- empathy_os/test_generator/cli.py +28 -28
- empathy_os/test_generator/generator.py +64 -66
- empathy_os/test_generator/risk_analyzer.py +11 -11
- empathy_os/vscode_bridge.py +173 -0
- empathy_os/workflows/__init__.py +212 -120
- empathy_os/workflows/batch_processing.py +8 -24
- empathy_os/workflows/bug_predict.py +1 -1
- empathy_os/workflows/code_review.py +20 -5
- empathy_os/workflows/code_review_pipeline.py +13 -8
- empathy_os/workflows/keyboard_shortcuts/workflow.py +6 -2
- empathy_os/workflows/manage_documentation.py +1 -0
- empathy_os/workflows/orchestrated_health_check.py +6 -11
- empathy_os/workflows/orchestrated_release_prep.py +3 -3
- empathy_os/workflows/pr_review.py +18 -10
- empathy_os/workflows/progressive/__init__.py +2 -12
- empathy_os/workflows/progressive/cli.py +14 -37
- empathy_os/workflows/progressive/core.py +12 -12
- empathy_os/workflows/progressive/orchestrator.py +166 -144
- empathy_os/workflows/progressive/reports.py +22 -31
- empathy_os/workflows/progressive/telemetry.py +8 -14
- empathy_os/workflows/progressive/test_gen.py +29 -48
- empathy_os/workflows/progressive/workflow.py +31 -70
- empathy_os/workflows/release_prep.py +21 -6
- empathy_os/workflows/release_prep_crew.py +1 -0
- empathy_os/workflows/secure_release.py +13 -6
- empathy_os/workflows/security_audit.py +8 -3
- empathy_os/workflows/test_coverage_boost_crew.py +3 -2
- empathy_os/workflows/test_maintenance_crew.py +1 -0
- empathy_os/workflows/test_runner.py +16 -12
- empathy_software_plugin/SOFTWARE_PLUGIN_README.md +25 -703
- empathy_software_plugin/cli.py +0 -122
- coach_wizards/__init__.py +0 -45
- coach_wizards/accessibility_wizard.py +0 -91
- coach_wizards/api_wizard.py +0 -91
- coach_wizards/base_wizard.py +0 -209
- coach_wizards/cicd_wizard.py +0 -91
- coach_wizards/code_reviewer_README.md +0 -60
- coach_wizards/code_reviewer_wizard.py +0 -180
- coach_wizards/compliance_wizard.py +0 -91
- coach_wizards/database_wizard.py +0 -91
- coach_wizards/debugging_wizard.py +0 -91
- coach_wizards/documentation_wizard.py +0 -91
- coach_wizards/generate_wizards.py +0 -347
- coach_wizards/localization_wizard.py +0 -173
- coach_wizards/migration_wizard.py +0 -91
- coach_wizards/monitoring_wizard.py +0 -91
- coach_wizards/observability_wizard.py +0 -91
- coach_wizards/performance_wizard.py +0 -91
- coach_wizards/prompt_engineering_wizard.py +0 -661
- coach_wizards/refactoring_wizard.py +0 -91
- coach_wizards/scaling_wizard.py +0 -90
- coach_wizards/security_wizard.py +0 -92
- coach_wizards/testing_wizard.py +0 -91
- empathy_framework-4.6.6.dist-info/RECORD +0 -410
- empathy_llm_toolkit/wizards/__init__.py +0 -43
- empathy_llm_toolkit/wizards/base_wizard.py +0 -364
- empathy_llm_toolkit/wizards/customer_support_wizard.py +0 -190
- empathy_llm_toolkit/wizards/healthcare_wizard.py +0 -378
- empathy_llm_toolkit/wizards/patient_assessment_README.md +0 -64
- empathy_llm_toolkit/wizards/patient_assessment_wizard.py +0 -193
- empathy_llm_toolkit/wizards/technology_wizard.py +0 -209
- empathy_os/wizard_factory_cli.py +0 -170
- empathy_software_plugin/wizards/__init__.py +0 -42
- empathy_software_plugin/wizards/advanced_debugging_wizard.py +0 -395
- empathy_software_plugin/wizards/agent_orchestration_wizard.py +0 -511
- empathy_software_plugin/wizards/ai_collaboration_wizard.py +0 -503
- empathy_software_plugin/wizards/ai_context_wizard.py +0 -441
- empathy_software_plugin/wizards/ai_documentation_wizard.py +0 -503
- empathy_software_plugin/wizards/base_wizard.py +0 -288
- empathy_software_plugin/wizards/book_chapter_wizard.py +0 -519
- empathy_software_plugin/wizards/code_review_wizard.py +0 -604
- empathy_software_plugin/wizards/debugging/__init__.py +0 -50
- empathy_software_plugin/wizards/debugging/bug_risk_analyzer.py +0 -414
- empathy_software_plugin/wizards/debugging/config_loaders.py +0 -446
- empathy_software_plugin/wizards/debugging/fix_applier.py +0 -469
- empathy_software_plugin/wizards/debugging/language_patterns.py +0 -385
- empathy_software_plugin/wizards/debugging/linter_parsers.py +0 -470
- empathy_software_plugin/wizards/debugging/verification.py +0 -369
- empathy_software_plugin/wizards/enhanced_testing_wizard.py +0 -537
- empathy_software_plugin/wizards/memory_enhanced_debugging_wizard.py +0 -816
- empathy_software_plugin/wizards/multi_model_wizard.py +0 -501
- empathy_software_plugin/wizards/pattern_extraction_wizard.py +0 -422
- empathy_software_plugin/wizards/pattern_retriever_wizard.py +0 -400
- empathy_software_plugin/wizards/performance/__init__.py +0 -9
- empathy_software_plugin/wizards/performance/bottleneck_detector.py +0 -221
- empathy_software_plugin/wizards/performance/profiler_parsers.py +0 -278
- empathy_software_plugin/wizards/performance/trajectory_analyzer.py +0 -429
- empathy_software_plugin/wizards/performance_profiling_wizard.py +0 -305
- empathy_software_plugin/wizards/prompt_engineering_wizard.py +0 -425
- empathy_software_plugin/wizards/rag_pattern_wizard.py +0 -461
- empathy_software_plugin/wizards/security/__init__.py +0 -32
- empathy_software_plugin/wizards/security/exploit_analyzer.py +0 -290
- empathy_software_plugin/wizards/security/owasp_patterns.py +0 -241
- empathy_software_plugin/wizards/security/vulnerability_scanner.py +0 -604
- empathy_software_plugin/wizards/security_analysis_wizard.py +0 -322
- empathy_software_plugin/wizards/security_learning_wizard.py +0 -740
- empathy_software_plugin/wizards/tech_debt_wizard.py +0 -726
- empathy_software_plugin/wizards/testing/__init__.py +0 -27
- empathy_software_plugin/wizards/testing/coverage_analyzer.py +0 -459
- empathy_software_plugin/wizards/testing/quality_analyzer.py +0 -525
- empathy_software_plugin/wizards/testing/test_suggester.py +0 -533
- empathy_software_plugin/wizards/testing_wizard.py +0 -274
- wizards/__init__.py +0 -82
- wizards/admission_assessment_wizard.py +0 -644
- wizards/care_plan.py +0 -321
- wizards/clinical_assessment.py +0 -769
- wizards/discharge_planning.py +0 -77
- wizards/discharge_summary_wizard.py +0 -468
- wizards/dosage_calculation.py +0 -497
- wizards/incident_report_wizard.py +0 -454
- wizards/medication_reconciliation.py +0 -85
- wizards/nursing_assessment.py +0 -171
- wizards/patient_education.py +0 -654
- wizards/quality_improvement.py +0 -705
- wizards/sbar_report.py +0 -324
- wizards/sbar_wizard.py +0 -608
- wizards/shift_handoff_wizard.py +0 -535
- wizards/soap_note_wizard.py +0 -679
- wizards/treatment_plan.py +0 -15
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/WHEEL +0 -0
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/entry_points.txt +0 -0
- {empathy_framework-4.6.6.dist-info → empathy_framework-4.7.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,661 +0,0 @@
|
|
|
1
|
-
"""Prompt Engineering Wizard
|
|
2
|
-
|
|
3
|
-
Helps developers craft better prompts for any AI task.
|
|
4
|
-
Can also optimize prompts used internally by other wizards.
|
|
5
|
-
|
|
6
|
-
Features:
|
|
7
|
-
1. Role & Context Setting - Define AI persona and background
|
|
8
|
-
2. Few-Shot Examples - Generate effective examples
|
|
9
|
-
3. Output Constraints - Format, length, structure
|
|
10
|
-
4. Token Optimization - Reduce costs while maintaining quality
|
|
11
|
-
5. Chain-of-Thought - Scaffolding for complex reasoning
|
|
12
|
-
|
|
13
|
-
Copyright 2025 Smart AI Memory, LLC
|
|
14
|
-
Licensed under Fair Source 0.9
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
import os
|
|
18
|
-
import re
|
|
19
|
-
from dataclasses import dataclass, field
|
|
20
|
-
from datetime import datetime, timedelta
|
|
21
|
-
from typing import Any
|
|
22
|
-
|
|
23
|
-
from .base_wizard import BaseCoachWizard, WizardIssue, WizardPrediction
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
@dataclass
|
|
27
|
-
class PromptAnalysis:
|
|
28
|
-
"""Analysis of a prompt's quality and effectiveness."""
|
|
29
|
-
|
|
30
|
-
overall_score: float # 0.0 - 1.0
|
|
31
|
-
clarity_score: float
|
|
32
|
-
specificity_score: float
|
|
33
|
-
structure_score: float
|
|
34
|
-
token_count: int
|
|
35
|
-
estimated_cost: float
|
|
36
|
-
|
|
37
|
-
issues: list[str] = field(default_factory=list)
|
|
38
|
-
suggestions: list[str] = field(default_factory=list)
|
|
39
|
-
|
|
40
|
-
has_role: bool = False
|
|
41
|
-
has_context: bool = False
|
|
42
|
-
has_examples: bool = False
|
|
43
|
-
has_constraints: bool = False
|
|
44
|
-
has_output_format: bool = False
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
@dataclass
|
|
48
|
-
class OptimizedPrompt:
|
|
49
|
-
"""Result of prompt optimization."""
|
|
50
|
-
|
|
51
|
-
original_prompt: str
|
|
52
|
-
optimized_prompt: str
|
|
53
|
-
original_tokens: int
|
|
54
|
-
optimized_tokens: int
|
|
55
|
-
token_reduction: float
|
|
56
|
-
quality_preserved: bool
|
|
57
|
-
changes_made: list[str] = field(default_factory=list)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
class PromptEngineeringWizard(BaseCoachWizard):
|
|
61
|
-
"""Wizard for crafting and optimizing prompts.
|
|
62
|
-
|
|
63
|
-
Provides tools for:
|
|
64
|
-
- Analyzing existing prompts for improvements
|
|
65
|
-
- Generating optimized prompts for tasks
|
|
66
|
-
- Adding few-shot examples
|
|
67
|
-
- Token optimization
|
|
68
|
-
- Chain-of-thought scaffolding
|
|
69
|
-
"""
|
|
70
|
-
|
|
71
|
-
# Keywords that indicate good prompt structure
|
|
72
|
-
ROLE_INDICATORS = [
|
|
73
|
-
"you are",
|
|
74
|
-
"act as",
|
|
75
|
-
"role:",
|
|
76
|
-
"persona:",
|
|
77
|
-
"as a",
|
|
78
|
-
"expert",
|
|
79
|
-
"specialist",
|
|
80
|
-
]
|
|
81
|
-
|
|
82
|
-
CONTEXT_INDICATORS = [
|
|
83
|
-
"context:",
|
|
84
|
-
"background:",
|
|
85
|
-
"situation:",
|
|
86
|
-
"given that",
|
|
87
|
-
"considering",
|
|
88
|
-
]
|
|
89
|
-
|
|
90
|
-
EXAMPLE_INDICATORS = [
|
|
91
|
-
"example:",
|
|
92
|
-
"for example",
|
|
93
|
-
"e.g.",
|
|
94
|
-
"such as",
|
|
95
|
-
"here is an example",
|
|
96
|
-
"input:",
|
|
97
|
-
"output:",
|
|
98
|
-
]
|
|
99
|
-
|
|
100
|
-
CONSTRAINT_INDICATORS = [
|
|
101
|
-
"must",
|
|
102
|
-
"should",
|
|
103
|
-
"don't",
|
|
104
|
-
"do not",
|
|
105
|
-
"avoid",
|
|
106
|
-
"ensure",
|
|
107
|
-
"never",
|
|
108
|
-
"always",
|
|
109
|
-
"constraint:",
|
|
110
|
-
"rule:",
|
|
111
|
-
]
|
|
112
|
-
|
|
113
|
-
OUTPUT_INDICATORS = [
|
|
114
|
-
"format:",
|
|
115
|
-
"output:",
|
|
116
|
-
"respond in",
|
|
117
|
-
"return as",
|
|
118
|
-
"json",
|
|
119
|
-
"markdown",
|
|
120
|
-
"structured",
|
|
121
|
-
"format your response",
|
|
122
|
-
]
|
|
123
|
-
|
|
124
|
-
# Token estimation (rough approximation)
|
|
125
|
-
CHARS_PER_TOKEN = 4
|
|
126
|
-
|
|
127
|
-
def __init__(self):
|
|
128
|
-
super().__init__(
|
|
129
|
-
name="prompt-engineering",
|
|
130
|
-
category="prompt_optimization",
|
|
131
|
-
languages=["natural_language"],
|
|
132
|
-
)
|
|
133
|
-
self._client = None
|
|
134
|
-
self._api_key = os.getenv("ANTHROPIC_API_KEY")
|
|
135
|
-
|
|
136
|
-
def _get_client(self):
|
|
137
|
-
"""Lazy-load the Anthropic client."""
|
|
138
|
-
if self._client is None and self._api_key:
|
|
139
|
-
try:
|
|
140
|
-
import anthropic
|
|
141
|
-
|
|
142
|
-
self._client = anthropic.Anthropic(api_key=self._api_key)
|
|
143
|
-
except ImportError:
|
|
144
|
-
pass
|
|
145
|
-
return self._client
|
|
146
|
-
|
|
147
|
-
def analyze_code(self, code: str, file_path: str, language: str) -> list[WizardIssue]:
|
|
148
|
-
"""Analyze a prompt (passed as 'code') for issues."""
|
|
149
|
-
return self._analyze_prompt_issues(code, file_path)
|
|
150
|
-
|
|
151
|
-
def _analyze_prompt_issues(self, prompt: str, source: str = "") -> list[WizardIssue]:
|
|
152
|
-
"""Convert prompt analysis to WizardIssues."""
|
|
153
|
-
analysis = self.analyze_prompt(prompt)
|
|
154
|
-
issues = []
|
|
155
|
-
|
|
156
|
-
if analysis.overall_score < 0.5:
|
|
157
|
-
issues.append(
|
|
158
|
-
WizardIssue(
|
|
159
|
-
severity="error",
|
|
160
|
-
message="Prompt has significant quality issues",
|
|
161
|
-
file_path=source,
|
|
162
|
-
line_number=None,
|
|
163
|
-
code_snippet=prompt[:200] + "..." if len(prompt) > 200 else prompt,
|
|
164
|
-
fix_suggestion="Consider restructuring with role, context, and output format",
|
|
165
|
-
category="prompt_quality",
|
|
166
|
-
confidence=0.9,
|
|
167
|
-
),
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
if not analysis.has_role:
|
|
171
|
-
issues.append(
|
|
172
|
-
WizardIssue(
|
|
173
|
-
severity="warning",
|
|
174
|
-
message="Prompt lacks a clear role definition",
|
|
175
|
-
file_path=source,
|
|
176
|
-
line_number=None,
|
|
177
|
-
code_snippet=None,
|
|
178
|
-
fix_suggestion="Add 'You are a...' or 'Act as a...' at the start",
|
|
179
|
-
category="prompt_structure",
|
|
180
|
-
confidence=0.8,
|
|
181
|
-
),
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
if not analysis.has_output_format:
|
|
185
|
-
issues.append(
|
|
186
|
-
WizardIssue(
|
|
187
|
-
severity="warning",
|
|
188
|
-
message="Prompt doesn't specify output format",
|
|
189
|
-
file_path=source,
|
|
190
|
-
line_number=None,
|
|
191
|
-
code_snippet=None,
|
|
192
|
-
fix_suggestion="Add output format specification (JSON, markdown, etc.)",
|
|
193
|
-
category="prompt_structure",
|
|
194
|
-
confidence=0.7,
|
|
195
|
-
),
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
for suggestion in analysis.suggestions:
|
|
199
|
-
issues.append(
|
|
200
|
-
WizardIssue(
|
|
201
|
-
severity="info",
|
|
202
|
-
message=suggestion,
|
|
203
|
-
file_path=source,
|
|
204
|
-
line_number=None,
|
|
205
|
-
code_snippet=None,
|
|
206
|
-
fix_suggestion=None,
|
|
207
|
-
category="prompt_improvement",
|
|
208
|
-
confidence=0.6,
|
|
209
|
-
),
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
return issues
|
|
213
|
-
|
|
214
|
-
def predict_future_issues(
|
|
215
|
-
self,
|
|
216
|
-
code: str,
|
|
217
|
-
file_path: str,
|
|
218
|
-
project_context: dict[str, Any],
|
|
219
|
-
timeline_days: int = 90,
|
|
220
|
-
) -> list[WizardPrediction]:
|
|
221
|
-
"""Predict future prompt-related issues."""
|
|
222
|
-
predictions = []
|
|
223
|
-
analysis = self.analyze_prompt(code)
|
|
224
|
-
|
|
225
|
-
# Predict maintenance issues for unclear prompts
|
|
226
|
-
if analysis.clarity_score < 0.5:
|
|
227
|
-
predictions.append(
|
|
228
|
-
WizardPrediction(
|
|
229
|
-
predicted_date=datetime.now() + timedelta(days=30),
|
|
230
|
-
issue_type="prompt_drift",
|
|
231
|
-
probability=0.7,
|
|
232
|
-
impact="medium",
|
|
233
|
-
prevention_steps=[
|
|
234
|
-
"Document the prompt's purpose",
|
|
235
|
-
"Add version comments",
|
|
236
|
-
"Create test cases for expected outputs",
|
|
237
|
-
],
|
|
238
|
-
reasoning="Low clarity prompts tend to drift from intended behavior over time",
|
|
239
|
-
),
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
# Predict cost issues for verbose prompts
|
|
243
|
-
if analysis.token_count > 1000:
|
|
244
|
-
predictions.append(
|
|
245
|
-
WizardPrediction(
|
|
246
|
-
predicted_date=datetime.now() + timedelta(days=14),
|
|
247
|
-
issue_type="cost_escalation",
|
|
248
|
-
probability=0.8,
|
|
249
|
-
impact="high",
|
|
250
|
-
prevention_steps=[
|
|
251
|
-
"Optimize prompt tokens",
|
|
252
|
-
"Use cheaper models for routing",
|
|
253
|
-
"Cache common responses",
|
|
254
|
-
],
|
|
255
|
-
reasoning=f"Prompt uses {analysis.token_count} tokens - costs will escalate with scale",
|
|
256
|
-
),
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
return predictions
|
|
260
|
-
|
|
261
|
-
def suggest_fixes(self, issue: WizardIssue) -> str:
|
|
262
|
-
"""Suggest how to fix a prompt issue."""
|
|
263
|
-
if issue.category == "prompt_quality":
|
|
264
|
-
return """To improve overall prompt quality:
|
|
265
|
-
|
|
266
|
-
1. Start with a clear role:
|
|
267
|
-
"You are an expert software engineer specializing in..."
|
|
268
|
-
|
|
269
|
-
2. Add relevant context:
|
|
270
|
-
"Context: The user is working on a Python web application..."
|
|
271
|
-
|
|
272
|
-
3. Specify the output format:
|
|
273
|
-
"Respond in JSON format with the following fields: ..."
|
|
274
|
-
|
|
275
|
-
4. Include constraints:
|
|
276
|
-
"Important: Focus only on security-related issues. Do not suggest style changes."
|
|
277
|
-
"""
|
|
278
|
-
|
|
279
|
-
if issue.category == "prompt_structure":
|
|
280
|
-
if "role" in issue.message.lower():
|
|
281
|
-
return """Add a role definition at the start of your prompt:
|
|
282
|
-
|
|
283
|
-
Examples:
|
|
284
|
-
- "You are a senior code reviewer with expertise in Python best practices."
|
|
285
|
-
- "Act as a security auditor analyzing this code for vulnerabilities."
|
|
286
|
-
- "As an experienced technical writer, help document this API."
|
|
287
|
-
"""
|
|
288
|
-
|
|
289
|
-
if "output" in issue.message.lower():
|
|
290
|
-
return """Specify the output format clearly:
|
|
291
|
-
|
|
292
|
-
Examples:
|
|
293
|
-
- "Respond in JSON format: {\"issues\": [], \"suggestions\": []}"
|
|
294
|
-
- "Format your response as a markdown checklist."
|
|
295
|
-
- "Return a numbered list of actionable recommendations."
|
|
296
|
-
"""
|
|
297
|
-
|
|
298
|
-
return issue.fix_suggestion or "Review and improve the prompt structure."
|
|
299
|
-
|
|
300
|
-
def analyze_prompt(self, prompt: str) -> PromptAnalysis:
|
|
301
|
-
"""Analyze an existing prompt for improvements.
|
|
302
|
-
|
|
303
|
-
Args:
|
|
304
|
-
prompt: The prompt to analyze
|
|
305
|
-
|
|
306
|
-
Returns:
|
|
307
|
-
PromptAnalysis with scores and suggestions
|
|
308
|
-
|
|
309
|
-
"""
|
|
310
|
-
prompt_lower = prompt.lower()
|
|
311
|
-
token_count = len(prompt) // self.CHARS_PER_TOKEN
|
|
312
|
-
|
|
313
|
-
# Check for structural elements
|
|
314
|
-
has_role = any(ind in prompt_lower for ind in self.ROLE_INDICATORS)
|
|
315
|
-
has_context = any(ind in prompt_lower for ind in self.CONTEXT_INDICATORS)
|
|
316
|
-
has_examples = any(ind in prompt_lower for ind in self.EXAMPLE_INDICATORS)
|
|
317
|
-
has_constraints = any(ind in prompt_lower for ind in self.CONSTRAINT_INDICATORS)
|
|
318
|
-
has_output_format = any(ind in prompt_lower for ind in self.OUTPUT_INDICATORS)
|
|
319
|
-
|
|
320
|
-
# Calculate scores
|
|
321
|
-
clarity_score = self._calculate_clarity(prompt)
|
|
322
|
-
specificity_score = self._calculate_specificity(prompt)
|
|
323
|
-
structure_score = (
|
|
324
|
-
sum([has_role, has_context, has_examples, has_constraints, has_output_format]) / 5
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
# Overall score
|
|
328
|
-
overall_score = (clarity_score + specificity_score + structure_score) / 3
|
|
329
|
-
|
|
330
|
-
# Generate issues and suggestions
|
|
331
|
-
issues = []
|
|
332
|
-
suggestions = []
|
|
333
|
-
|
|
334
|
-
if not has_role:
|
|
335
|
-
issues.append("Missing role definition")
|
|
336
|
-
suggestions.append("Add 'You are a...' to define the AI's role")
|
|
337
|
-
|
|
338
|
-
if not has_context and len(prompt) > 100:
|
|
339
|
-
issues.append("Missing context section")
|
|
340
|
-
suggestions.append("Add background context for better results")
|
|
341
|
-
|
|
342
|
-
if not has_output_format:
|
|
343
|
-
issues.append("No output format specified")
|
|
344
|
-
suggestions.append("Specify the desired response format")
|
|
345
|
-
|
|
346
|
-
if token_count > 500 and not has_examples:
|
|
347
|
-
suggestions.append("Consider adding examples for clearer expectations")
|
|
348
|
-
|
|
349
|
-
if clarity_score < 0.5:
|
|
350
|
-
issues.append("Prompt clarity is low")
|
|
351
|
-
suggestions.append("Use shorter sentences and clearer instructions")
|
|
352
|
-
|
|
353
|
-
# Estimate cost (using Claude pricing approximation)
|
|
354
|
-
estimated_cost = (token_count / 1_000_000) * 3.0 # ~$3/MTok for Sonnet
|
|
355
|
-
|
|
356
|
-
return PromptAnalysis(
|
|
357
|
-
overall_score=overall_score,
|
|
358
|
-
clarity_score=clarity_score,
|
|
359
|
-
specificity_score=specificity_score,
|
|
360
|
-
structure_score=structure_score,
|
|
361
|
-
token_count=token_count,
|
|
362
|
-
estimated_cost=estimated_cost,
|
|
363
|
-
issues=issues,
|
|
364
|
-
suggestions=suggestions,
|
|
365
|
-
has_role=has_role,
|
|
366
|
-
has_context=has_context,
|
|
367
|
-
has_examples=has_examples,
|
|
368
|
-
has_constraints=has_constraints,
|
|
369
|
-
has_output_format=has_output_format,
|
|
370
|
-
)
|
|
371
|
-
|
|
372
|
-
def _calculate_clarity(self, prompt: str) -> float:
|
|
373
|
-
"""Calculate clarity score based on sentence structure."""
|
|
374
|
-
sentences = re.split(r"[.!?]+", prompt)
|
|
375
|
-
sentences = [s.strip() for s in sentences if s.strip()]
|
|
376
|
-
|
|
377
|
-
if not sentences:
|
|
378
|
-
return 0.5
|
|
379
|
-
|
|
380
|
-
# Average sentence length (shorter is clearer)
|
|
381
|
-
avg_length = sum(len(s.split()) for s in sentences) / len(sentences)
|
|
382
|
-
|
|
383
|
-
# Optimal is 10-20 words per sentence
|
|
384
|
-
if 10 <= avg_length <= 20:
|
|
385
|
-
length_score = 1.0
|
|
386
|
-
elif avg_length < 5 or avg_length > 40:
|
|
387
|
-
length_score = 0.3
|
|
388
|
-
else:
|
|
389
|
-
length_score = 0.7
|
|
390
|
-
|
|
391
|
-
# Check for clear instruction verbs
|
|
392
|
-
instruction_verbs = [
|
|
393
|
-
"analyze",
|
|
394
|
-
"review",
|
|
395
|
-
"generate",
|
|
396
|
-
"create",
|
|
397
|
-
"explain",
|
|
398
|
-
"describe",
|
|
399
|
-
"list",
|
|
400
|
-
"identify",
|
|
401
|
-
"compare",
|
|
402
|
-
"summarize",
|
|
403
|
-
]
|
|
404
|
-
has_verbs = any(v in prompt.lower() for v in instruction_verbs)
|
|
405
|
-
verb_score = 1.0 if has_verbs else 0.5
|
|
406
|
-
|
|
407
|
-
return (length_score + verb_score) / 2
|
|
408
|
-
|
|
409
|
-
def _calculate_specificity(self, prompt: str) -> float:
|
|
410
|
-
"""Calculate how specific the prompt is."""
|
|
411
|
-
# Check for specific terms
|
|
412
|
-
specific_indicators = [
|
|
413
|
-
r"\d+", # Numbers
|
|
414
|
-
r"\b(python|javascript|typescript|java|go|rust)\b", # Languages
|
|
415
|
-
r"\b(json|xml|yaml|csv|markdown)\b", # Formats
|
|
416
|
-
r"\b(api|function|class|method|variable)\b", # Code terms
|
|
417
|
-
]
|
|
418
|
-
|
|
419
|
-
specificity = 0.0
|
|
420
|
-
for pattern in specific_indicators:
|
|
421
|
-
if re.search(pattern, prompt.lower()):
|
|
422
|
-
specificity += 0.25
|
|
423
|
-
|
|
424
|
-
return min(specificity, 1.0)
|
|
425
|
-
|
|
426
|
-
def generate_prompt(
|
|
427
|
-
self,
|
|
428
|
-
task: str,
|
|
429
|
-
role: str | None = None,
|
|
430
|
-
context: str | None = None,
|
|
431
|
-
output_format: str | None = None,
|
|
432
|
-
constraints: list[str] | None = None,
|
|
433
|
-
examples: list[dict[str, str]] | None = None,
|
|
434
|
-
) -> str:
|
|
435
|
-
"""Generate an optimized prompt for a task.
|
|
436
|
-
|
|
437
|
-
Args:
|
|
438
|
-
task: The main task to accomplish
|
|
439
|
-
role: Optional role definition
|
|
440
|
-
context: Optional context/background
|
|
441
|
-
output_format: Desired output format
|
|
442
|
-
constraints: List of constraints/rules
|
|
443
|
-
examples: List of input/output examples
|
|
444
|
-
|
|
445
|
-
Returns:
|
|
446
|
-
Generated prompt string
|
|
447
|
-
|
|
448
|
-
"""
|
|
449
|
-
parts = []
|
|
450
|
-
|
|
451
|
-
# Role definition
|
|
452
|
-
if role:
|
|
453
|
-
parts.append(f"You are {role}.")
|
|
454
|
-
else:
|
|
455
|
-
parts.append("You are a helpful AI assistant.")
|
|
456
|
-
|
|
457
|
-
# Context
|
|
458
|
-
if context:
|
|
459
|
-
parts.append(f"\n## Context\n{context}")
|
|
460
|
-
|
|
461
|
-
# Main task
|
|
462
|
-
parts.append(f"\n## Task\n{task}")
|
|
463
|
-
|
|
464
|
-
# Constraints
|
|
465
|
-
if constraints:
|
|
466
|
-
parts.append("\n## Constraints")
|
|
467
|
-
for c in constraints:
|
|
468
|
-
parts.append(f"- {c}")
|
|
469
|
-
|
|
470
|
-
# Examples
|
|
471
|
-
if examples:
|
|
472
|
-
parts.append("\n## Examples")
|
|
473
|
-
for i, ex in enumerate(examples, 1):
|
|
474
|
-
parts.append(f"\nExample {i}:")
|
|
475
|
-
if "input" in ex:
|
|
476
|
-
parts.append(f"Input: {ex['input']}")
|
|
477
|
-
if "output" in ex:
|
|
478
|
-
parts.append(f"Output: {ex['output']}")
|
|
479
|
-
|
|
480
|
-
# Output format
|
|
481
|
-
if output_format:
|
|
482
|
-
parts.append(f"\n## Output Format\n{output_format}")
|
|
483
|
-
|
|
484
|
-
return "\n".join(parts)
|
|
485
|
-
|
|
486
|
-
def add_few_shot_examples(
|
|
487
|
-
self,
|
|
488
|
-
prompt: str,
|
|
489
|
-
examples: list[dict[str, str]],
|
|
490
|
-
position: str = "end",
|
|
491
|
-
) -> str:
|
|
492
|
-
"""Add few-shot examples to a prompt.
|
|
493
|
-
|
|
494
|
-
Args:
|
|
495
|
-
prompt: Original prompt
|
|
496
|
-
examples: List of input/output example dicts
|
|
497
|
-
position: Where to add examples ("start", "end", "after_context")
|
|
498
|
-
|
|
499
|
-
Returns:
|
|
500
|
-
Prompt with examples added
|
|
501
|
-
|
|
502
|
-
"""
|
|
503
|
-
example_section = "\n## Examples\n"
|
|
504
|
-
for i, ex in enumerate(examples, 1):
|
|
505
|
-
example_section += f"\n### Example {i}\n"
|
|
506
|
-
if "input" in ex:
|
|
507
|
-
example_section += f"Input: {ex['input']}\n"
|
|
508
|
-
if "output" in ex:
|
|
509
|
-
example_section += f"Output: {ex['output']}\n"
|
|
510
|
-
|
|
511
|
-
if position == "start":
|
|
512
|
-
return example_section + "\n" + prompt
|
|
513
|
-
if position == "after_context" and "Context" in prompt:
|
|
514
|
-
# Insert after context section
|
|
515
|
-
parts = prompt.split("## Task")
|
|
516
|
-
if len(parts) == 2:
|
|
517
|
-
return parts[0] + example_section + "## Task" + parts[1]
|
|
518
|
-
# Default: end
|
|
519
|
-
return prompt + "\n" + example_section
|
|
520
|
-
|
|
521
|
-
def optimize_tokens(
|
|
522
|
-
self,
|
|
523
|
-
prompt: str,
|
|
524
|
-
target_reduction: float = 0.2,
|
|
525
|
-
) -> OptimizedPrompt:
|
|
526
|
-
"""Reduce token count while preserving intent.
|
|
527
|
-
|
|
528
|
-
Args:
|
|
529
|
-
prompt: Original prompt
|
|
530
|
-
target_reduction: Target reduction percentage (0.0 - 1.0)
|
|
531
|
-
|
|
532
|
-
Returns:
|
|
533
|
-
OptimizedPrompt with original and optimized versions
|
|
534
|
-
|
|
535
|
-
"""
|
|
536
|
-
original_tokens = len(prompt) // self.CHARS_PER_TOKEN
|
|
537
|
-
changes = []
|
|
538
|
-
|
|
539
|
-
optimized = prompt
|
|
540
|
-
|
|
541
|
-
# Remove redundant whitespace
|
|
542
|
-
optimized = re.sub(r"\n\n\n+", "\n\n", optimized)
|
|
543
|
-
optimized = re.sub(r" +", " ", optimized)
|
|
544
|
-
if optimized != prompt:
|
|
545
|
-
changes.append("Removed redundant whitespace")
|
|
546
|
-
|
|
547
|
-
# Shorten common phrases
|
|
548
|
-
shortenings = {
|
|
549
|
-
"in order to": "to",
|
|
550
|
-
"for the purpose of": "for",
|
|
551
|
-
"in the event that": "if",
|
|
552
|
-
"with respect to": "regarding",
|
|
553
|
-
"prior to": "before",
|
|
554
|
-
"subsequent to": "after",
|
|
555
|
-
"in addition to": "also",
|
|
556
|
-
"as a result of": "due to",
|
|
557
|
-
"at this point in time": "now",
|
|
558
|
-
"it is important to note that": "note:",
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
for long, short in shortenings.items():
|
|
562
|
-
if long in optimized.lower():
|
|
563
|
-
optimized = re.sub(re.escape(long), short, optimized, flags=re.IGNORECASE)
|
|
564
|
-
changes.append(f"Shortened '{long}' to '{short}'")
|
|
565
|
-
|
|
566
|
-
# Remove filler words
|
|
567
|
-
fillers = ["basically", "essentially", "actually", "literally", "really", "just"]
|
|
568
|
-
for filler in fillers:
|
|
569
|
-
pattern = rf"\b{filler}\b\s*"
|
|
570
|
-
if re.search(pattern, optimized, re.IGNORECASE):
|
|
571
|
-
optimized = re.sub(pattern, "", optimized, flags=re.IGNORECASE)
|
|
572
|
-
changes.append(f"Removed filler word '{filler}'")
|
|
573
|
-
|
|
574
|
-
optimized_tokens = len(optimized) // self.CHARS_PER_TOKEN
|
|
575
|
-
reduction = (
|
|
576
|
-
(original_tokens - optimized_tokens) / original_tokens if original_tokens > 0 else 0
|
|
577
|
-
)
|
|
578
|
-
|
|
579
|
-
return OptimizedPrompt(
|
|
580
|
-
original_prompt=prompt,
|
|
581
|
-
optimized_prompt=optimized.strip(),
|
|
582
|
-
original_tokens=original_tokens,
|
|
583
|
-
optimized_tokens=optimized_tokens,
|
|
584
|
-
token_reduction=reduction,
|
|
585
|
-
quality_preserved=True, # Basic optimization preserves quality
|
|
586
|
-
changes_made=changes,
|
|
587
|
-
)
|
|
588
|
-
|
|
589
|
-
def add_chain_of_thought(
|
|
590
|
-
self,
|
|
591
|
-
prompt: str,
|
|
592
|
-
reasoning_type: str = "step_by_step",
|
|
593
|
-
) -> str:
|
|
594
|
-
"""Add Chain-of-Thought scaffolding for complex reasoning.
|
|
595
|
-
|
|
596
|
-
Args:
|
|
597
|
-
prompt: Original prompt
|
|
598
|
-
reasoning_type: Type of reasoning scaffold
|
|
599
|
-
- "step_by_step": General step-by-step reasoning
|
|
600
|
-
- "pros_cons": Evaluate options
|
|
601
|
-
- "debug": Debugging thought process
|
|
602
|
-
- "analysis": Analytical breakdown
|
|
603
|
-
|
|
604
|
-
Returns:
|
|
605
|
-
Prompt with CoT scaffolding
|
|
606
|
-
|
|
607
|
-
"""
|
|
608
|
-
cot_scaffolds = {
|
|
609
|
-
"step_by_step": """
|
|
610
|
-
Before providing your final answer, think through the problem step by step:
|
|
611
|
-
|
|
612
|
-
1. First, understand what is being asked
|
|
613
|
-
2. Identify the key components and constraints
|
|
614
|
-
3. Consider each requirement systematically
|
|
615
|
-
4. Formulate your approach
|
|
616
|
-
5. Execute and verify each step
|
|
617
|
-
6. Provide your final answer
|
|
618
|
-
|
|
619
|
-
Show your reasoning process clearly.""",
|
|
620
|
-
"pros_cons": """
|
|
621
|
-
Analyze the options by considering:
|
|
622
|
-
|
|
623
|
-
For each option:
|
|
624
|
-
- List the advantages (pros)
|
|
625
|
-
- List the disadvantages (cons)
|
|
626
|
-
- Consider edge cases
|
|
627
|
-
- Evaluate trade-offs
|
|
628
|
-
|
|
629
|
-
Then make your recommendation based on the analysis.""",
|
|
630
|
-
"debug": """
|
|
631
|
-
Follow this debugging process:
|
|
632
|
-
|
|
633
|
-
1. What is the expected behavior?
|
|
634
|
-
2. What is the actual behavior?
|
|
635
|
-
3. What are the possible causes?
|
|
636
|
-
4. How can we verify each hypothesis?
|
|
637
|
-
5. What is the root cause?
|
|
638
|
-
6. What is the fix?
|
|
639
|
-
|
|
640
|
-
Work through each step methodically.""",
|
|
641
|
-
"analysis": """
|
|
642
|
-
Perform a structured analysis:
|
|
643
|
-
|
|
644
|
-
1. Define the scope and boundaries
|
|
645
|
-
2. Identify key components
|
|
646
|
-
3. Analyze relationships and dependencies
|
|
647
|
-
4. Evaluate current state
|
|
648
|
-
5. Identify patterns or anomalies
|
|
649
|
-
6. Draw conclusions
|
|
650
|
-
7. Make recommendations
|
|
651
|
-
|
|
652
|
-
Present your findings systematically.""",
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
scaffold = cot_scaffolds.get(reasoning_type, cot_scaffolds["step_by_step"])
|
|
656
|
-
|
|
657
|
-
# Insert before the task or at the end
|
|
658
|
-
if "## Task" in prompt:
|
|
659
|
-
parts = prompt.split("## Task")
|
|
660
|
-
return parts[0] + "\n## Reasoning Process" + scaffold + "\n\n## Task" + parts[1]
|
|
661
|
-
return prompt + "\n\n## Reasoning Process" + scaffold
|