(no commit message)

This commit is contained in:
2025-11-04 22:51:27 -05:00
parent 22d47004cd
commit ec07718eb3
4 changed files with 50 additions and 64 deletions

View File

@@ -25,7 +25,7 @@
] ]
}, },
"lm": { "lm": {
"model": "openai/gpt-4o", "model": "openrouter/anthropic/claude-haiku-4.5",
"model_type": "chat", "model_type": "chat",
"cache": true, "cache": true,
"num_retries": 3, "num_retries": 3,

View File

@@ -5,7 +5,7 @@ from modaic import PrecompiledAgent, PrecompiledConfig
class PromptToSignatureConfig(PrecompiledConfig): class PromptToSignatureConfig(PrecompiledConfig):
lm: str = "openrouter/anthropic/claude-haiku-4.5" lm: str = "openrouter/anthropic/claude-haiku-4.5"
refine_lm: str = "openai/gpt-4o" refine_lm: str = "openrouter/anthropic/claude-haiku-4.5"
max_tokens: int = 16000 max_tokens: int = 16000
temperature: float = 1.0 temperature: float = 1.0
max_attempts_to_refine: int = 5 max_attempts_to_refine: int = 5

View File

@@ -1,6 +1,6 @@
{ {
"lm": "openrouter/anthropic/claude-haiku-4.5", "lm": "openrouter/anthropic/claude-haiku-4.5",
"refine_lm": "openai/gpt-4o", "refine_lm": "openrouter/anthropic/claude-haiku-4.5",
"max_tokens": 16000, "max_tokens": 16000,
"temperature": 1.0, "temperature": 1.0,
"max_attempts_to_refine": 5 "max_attempts_to_refine": 5

108
main.py
View File

@@ -1,87 +1,73 @@
from agent import PromptToSignatureAgent, PromptToSignatureConfig from agent import PromptToSignatureAgent, PromptToSignatureConfig
agent = PromptToSignatureAgent(PromptToSignatureConfig()) agent = PromptToSignatureAgent(PromptToSignatureConfig())
PROMPT = """**INPUT FORMAT**: Raw clinical notes in free-text format, typically 200-2000 words, containing unstructured medical documentation from patient encounters including history, examination findings, diagnoses, treatment plans, and follow-up instructions. PROMPT = """**INPUT FORMAT**: Customer product reviews in natural language text, ranging from 50-1000 words. May include informal language, slang, misspellings, emojis, and mixed sentiments. Reviews may be from various e-commerce platforms (Amazon, eBay, specialized retail sites).
**TASK DESCRIPTION**: You are a medical information extraction system. Analyze the provided clinical notes and perform comprehensive structured data extraction along with risk stratification. Your task involves multiple sub-tasks executed simultaneously. **TASK DESCRIPTION**: You are an advanced sentiment analysis and feature extraction system for e-commerce platforms. Your goal is to parse customer reviews and extract granular insights about both overall sentiment and feature-specific opinions to help businesses understand customer satisfaction at a detailed level.
**EXTRACTION REQUIREMENTS**: **EXTRACTION REQUIREMENTS**:
- **Patient Demographics**: Extract full legal name, age (in years), biological sex/gender, date of birth (format: YYYY-MM-DD), medical record number (MRN) if present - **Overall Sentiment**: Determine the general sentiment of the entire review using a 4-category classification (positive/negative/mixed/neutral). Mixed indicates both positive and negative sentiments present; neutral indicates factual statements without emotional valence.
- **Primary Diagnosis**: Identify the main diagnosis with corresponding ICD-10 code, include diagnostic certainty level (confirmed/suspected/rule-out) - **Product Features Mentioned**: Identify which of these standard e-commerce features are discussed: product quality, value for money, delivery/shipping experience, customer service interactions, packaging quality, product description accuracy, ease of use, durability, aesthetics/appearance, size/fit accuracy
- **Secondary Diagnoses**: List all comorbidities and additional conditions mentioned, each with ICD-10 codes where applicable - **Feature-Specific Sentiment**: For each feature mentioned, assign a sentiment score (-2 very negative, -1 negative, 0 neutral, +1 positive, +2 very positive)
- **Medications**: Extract complete medication list including generic and brand names, dosages with units (mg, mcg, mL), frequency (BID, TID, QID, PRN), route of administration (PO, IV, IM, topical), and duration if specified - **Star Rating Prediction**: Based on the text sentiment and feature analysis, predict what star rating (1-5 stars) the customer likely gave, with confidence score (0-100%)
- **Allergies**: Document all allergies with allergen name, reaction type (rash, anaphylaxis, nausea, etc.), and severity classification (mild/moderate/severe/life-threatening) - **Purchase Verification**: Detect phrases indicating verified purchase ("verified purchase", "bought this", "received this product", "purchased from") vs. uncertain authenticity
- **Vital Signs**: Extract most recent measurements - blood pressure (systolic/diastolic in mmHg), heart rate (bpm), temperature (°F or °C with unit), respiratory rate (breaths/min), oxygen saturation (%), and pain score (0-10 scale) - **Competitor Comparison**: Identify if the review compares the product to competitors, extract competitor names/products mentioned, and determine if comparison is favorable or unfavorable
- **Laboratory Results**: Identify all lab values mentioned with test name, numerical result, unit of measurement, reference range, and flag if abnormal (high/low/critical) - **Specific Issues**: Extract concrete complaints (e.g., "broke after 2 weeks", "arrived damaged", "wrong color sent", "missing parts")
- **Appointments**: Extract scheduled follow-up dates, appointment types (follow-up, specialist referral, procedure), and provider names - **Specific Praise**: Extract concrete positive mentions (e.g., "excellent battery life", "fast shipping", "exceeded expectations")
- **Review Helpfulness Indicators**: Classify review as "likely helpful" or "not helpful" based on linguistic markers (specificity, length, balanced perspective, constructive criticism vs. pure emotion)
**CLASSIFICATION REQUIREMENTS**: **CLASSIFICATION REQUIREMENTS**:
- **Urgency Level**: Classify the case into one of four categories: - **Review Quality Score**: Rate the review quality from 1-5 where:
- ROUTINE: Stable patient, chronic condition management, no acute concerns - 1 = Unhelpful (pure emotion, no details, spam-like)
- URGENT: Requires attention within 24-48 hours, acute but not life-threatening condition - 2 = Minimal info (very brief, vague)
- EMERGENCY: Immediate intervention required, potentially life-threatening presentation - 3 = Moderate (some useful details)
- CRITICAL: Life-threatening emergency requiring immediate intervention (ICU-level care) - 4 = Good (specific, balanced, informative)
- 5 = Excellent (detailed, comprehensive, fair assessment)
**OUTPUT FORMAT**: Return the following schema: **OUTPUT FORMAT**: Return the following schema:
{ {
"patient_demographics": { "overall_sentiment": {
"name": "string", "classification": "positive|negative|mixed|neutral",
"age": "integer", "confidence_score": "float (0-1)"
"gender": "string",
"dob": "YYYY-MM-DD",
"mrn": "string or null"
}, },
"primary_diagnosis": { "predicted_star_rating": {
"condition": "string", "stars": "integer (1-5)",
"icd10_code": "string", "confidence": "integer (0-100)"
"certainty": "confirmed|suspected|rule-out"
}, },
"secondary_diagnoses": [ "features_analyzed": [
{"condition": "string", "icd10_code": "string"}
],
"medications": [
{ {
"name": "string", "feature_name": "string",
"dosage": "string", "mentioned": "boolean",
"frequency": "string", "sentiment_score": "integer (-2 to +2)",
"route": "string", "supporting_quote": "string (relevant excerpt from review)"
"duration": "string or null"
} }
], ],
"allergies": [ "purchase_verification": {
{ "appears_verified": "boolean",
"allergen": "string", "indicators": ["array of strings showing evidence"]
"reaction": "string",
"severity": "mild|moderate|severe|life-threatening"
}
],
"vital_signs": {
"blood_pressure": "string (systolic/diastolic)",
"heart_rate": "integer",
"temperature": "float with unit",
"respiratory_rate": "integer",
"oxygen_saturation": "integer",
"pain_score": "integer (0-10)"
}, },
"lab_results": [ "competitor_comparison": {
"present": "boolean",
"competitors_mentioned": ["array of strings"],
"comparison_favorability": "favorable|unfavorable|neutral"
},
"specific_issues": [
{ {
"test_name": "string", "issue": "string",
"value": "float", "severity": "minor|moderate|major",
"unit": "string", "quote": "string"
"reference_range": "string",
"flag": "normal|high|low|critical"
} }
], ],
"appointments": [ "specific_praise": [
{ {
"date": "YYYY-MM-DD", "praise_point": "string",
"type": "string", "quote": "string"
"provider": "string"
} }
], ],
"urgency_classification": { "review_helpfulness": {
"level": "ROUTINE|URGENT|EMERGENCY|CRITICAL", "classification": "likely_helpful|not_helpful",
"reasoning": "string (brief explanation for classification)" "quality_score": "integer (1-5)",
"reasoning": "string"
} }
} }
""" """