Spaces:
Running
Running
Update features/insight_and_tasks/agents/task_extraction_model.py
Browse files
features/insight_and_tasks/agents/task_extraction_model.py
CHANGED
@@ -24,6 +24,36 @@ from features.insight_and_tasks.data_models.tasks import (
|
|
24 |
DataSubject # Ensure all are imported
|
25 |
)
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# --- Helper Function for Date Calculations ---
|
28 |
def get_quarter_info():
|
29 |
"""Calculates current quarter, year, and days remaining in the quarter."""
|
@@ -93,6 +123,8 @@ def extract_tasks_from_text(user_text_input: str, api_key: str) -> TaskExtractio
|
|
93 |
prompt = f"""You are a Time-Aware Task Extraction Specialist, an AI expert in meticulously analyzing strategic insights (e.g., from LinkedIn analytics) and transforming them into a structured set of actionable tasks, organized within an Objectives and KeyResults (OKRs) framework.
|
94 |
|
95 |
Your output MUST be a valid JSON object that strictly conforms to the 'TaskExtractionOutput' schema provided.
|
|
|
|
|
96 |
|
97 |
CURRENT CONTEXTUAL INFORMATION (CRITICAL - Use these exact values in your output where specified):
|
98 |
- Current Quarter: Q{quarter}
|
@@ -102,11 +134,12 @@ CURRENT CONTEXTUAL INFORMATION (CRITICAL - Use these exact values in your output
|
|
102 |
|
103 |
When populating the 'current_quarter_info' field in the TaskExtractionOutput, use the format: 'Q{quarter} {year}, {days_remaining} days remaining'.
|
104 |
|
105 |
-
|
106 |
-
1.
|
107 |
-
2.
|
108 |
-
3.
|
109 |
-
4.
|
|
|
110 |
|
111 |
Now, analyze the following text and generate the structured output:
|
112 |
---
|
@@ -122,6 +155,7 @@ TEXT TO ANALYZE:
|
|
122 |
config={
|
123 |
'response_mime_type': 'application/json',
|
124 |
'response_schema': TaskExtractionOutput, # Pass the Pydantic model class
|
|
|
125 |
},
|
126 |
)
|
127 |
except Exception as e:
|
|
|
24 |
DataSubject # Ensure all are imported
|
25 |
)
|
26 |
|
27 |
+
def create_example_structure():
|
28 |
+
"""Creates an example structure to show the AI what the output should look like."""
|
29 |
+
return {
|
30 |
+
"current_quarter_info": "Q2 2025, 24 days remaining",
|
31 |
+
"okrs": [
|
32 |
+
{
|
33 |
+
"objective": "Improve LinkedIn employer branding performance",
|
34 |
+
"data_subject": "linkedin_performance",
|
35 |
+
"key_results": [
|
36 |
+
{
|
37 |
+
"description": "Increase monthly follower growth by 50%",
|
38 |
+
"target_value": "50% increase",
|
39 |
+
"current_value": "22 followers/month",
|
40 |
+
"tasks": [
|
41 |
+
{
|
42 |
+
"title": "Increase posting frequency",
|
43 |
+
"description": "Post 2-3 times per week consistently",
|
44 |
+
"task_type": "content_creation",
|
45 |
+
"priority": "high",
|
46 |
+
"effort_level": "medium",
|
47 |
+
"timeline": "this_quarter",
|
48 |
+
"data_subject": "linkedin_performance"
|
49 |
+
}
|
50 |
+
]
|
51 |
+
}
|
52 |
+
]
|
53 |
+
}
|
54 |
+
]
|
55 |
+
}
|
56 |
+
|
57 |
# --- Helper Function for Date Calculations ---
|
58 |
def get_quarter_info():
|
59 |
"""Calculates current quarter, year, and days remaining in the quarter."""
|
|
|
123 |
prompt = f"""You are a Time-Aware Task Extraction Specialist, an AI expert in meticulously analyzing strategic insights (e.g., from LinkedIn analytics) and transforming them into a structured set of actionable tasks, organized within an Objectives and KeyResults (OKRs) framework.
|
124 |
|
125 |
Your output MUST be a valid JSON object that strictly conforms to the 'TaskExtractionOutput' schema provided.
|
126 |
+
EXAMPLE STRUCTURE (follow this pattern exactly):
|
127 |
+
{json.dumps(example_structure, indent=2)}
|
128 |
|
129 |
CURRENT CONTEXTUAL INFORMATION (CRITICAL - Use these exact values in your output where specified):
|
130 |
- Current Quarter: Q{quarter}
|
|
|
134 |
|
135 |
When populating the 'current_quarter_info' field in the TaskExtractionOutput, use the format: 'Q{quarter} {year}, {days_remaining} days remaining'.
|
136 |
|
137 |
+
GENERATION RULES:
|
138 |
+
1. Create 1-3 OKR objects based on the input text
|
139 |
+
2. For each OKR, create 1-3 KeyResult objects (MANDATORY - cannot be empty)
|
140 |
+
3. For each KeyResult, create 1-3 Task objects (MANDATORY - cannot be empty)
|
141 |
+
4. Make tasks specific, actionable, and directly related to the insights in the input text
|
142 |
+
5. Ensure all required fields are populated with valid enum values
|
143 |
|
144 |
Now, analyze the following text and generate the structured output:
|
145 |
---
|
|
|
155 |
config={
|
156 |
'response_mime_type': 'application/json',
|
157 |
'response_schema': TaskExtractionOutput, # Pass the Pydantic model class
|
158 |
+
'temperature': 0.1,
|
159 |
},
|
160 |
)
|
161 |
except Exception as e:
|