brandonmusic commited on
Commit
866609c
·
verified ·
1 Parent(s): a36c8c9

Update task_processing.py

Browse files
Files changed (1) hide show
  1. task_processing.py +79 -44
task_processing.py CHANGED
@@ -1,48 +1,83 @@
1
- # task_processing.py (Fully Updated - Minor Changes for Artifact Compatibility)
2
- # Added optional artifact generation in process_task_response if task involves documents.
3
- # Minor changes: Removed retrieve_context (aligned with retrieval.py updates); set rag_context to empty.
4
- # Avoided redundant GPT calls; focused on post-processing Grok's response (e.g., formatting).
 
5
 
6
- from gpt_helpers import ask_gpt41_mini # Retained for document_creation draft (but note redundancy with app.py)
 
7
 
8
- def process_task_response(task_type, grok_response, prompt, jurisdiction):
 
 
 
 
 
 
 
9
  """
10
- Process the Grok response based on task type. Since rag_context is already prepended in app.py,
11
- this focuses on minimal post-processing (e.g., formatting headers) without redundant retrieval.
12
- If additional context is needed (rare), use retrieve_context.
 
13
  """
14
- # Fetch context only if absolutely needed for post-processing (e.g., if it's already in the prompt
15
- rag_context = "" # Default to empty; override per task if needed (no more retrieve_context)
16
- if task_type == "case_law" or task_type == "irac":
17
- # No need to prepend; Grok already has rag_context with full case text/citations
18
- return f"Case Law / IRAC Analysis ({jurisdiction}): {grok_response}"
19
- elif task_type == "statute":
20
- # No need to prepend; Grok has municipal data from retrieve_context
21
- return f"Statute Analysis ({jurisdiction}): {grok_response}"
22
- elif task_type == "document_creation":
23
- # app.py already handles draft + polish; if post-processing needed, format only
24
- # Avoid calling ask_gpt41_mini again to prevent duplication
25
- return f"Final Document ({jurisdiction}): {grok_response}"
26
- elif task_type == "document_analysis":
27
- return f"Document Analysis ({jurisdiction}): {grok_response}"
28
- elif task_type == "analogical_reasoning":
29
- return f"Analogical Reasoning ({jurisdiction}): {grok_response}"
30
- elif task_type == "deposition_questions":
31
- return f"Deposition Questions ({jurisdiction}): {grok_response}"
32
- elif task_type == "verdict_predictor":
33
- return f"Verdict Prediction ({jurisdiction}): {grok_response}"
34
- elif task_type == "damages_estimator":
35
- return f"Damages Estimate ({jurisdiction}): {grok_response}"
36
- elif task_type == "pleading_validator":
37
- return f"Pleading Validation ({jurisdiction}): {grok_response}"
38
- elif task_type == "legal_inbox":
39
- return f"Legal Inbox Processing ({jurisdiction}): {grok_response}"
40
- elif task_type == "privilege_analyzer":
41
- return f"Privilege/PII Analysis ({jurisdiction}): {grok_response}"
42
- elif task_type == "eli5":
43
- return f"ELI5 Explanation ({jurisdiction}): {grok_response}"
44
- elif task_type == "workflow_template":
45
- return f"Workflow Template ({jurisdiction}): {grok_response}"
46
- elif task_type == "legal_strategy":
47
- return f"Legal Strategy ({jurisdiction}): {grok_response}"
48
- return grok_response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # task_processing.py (Updated for new VerdictAI modes)
2
+ # - Adds labels/headers for new modes introduced in app.py
3
+ # - Keeps lightweight, post-processing-only behavior
4
+ # - No redundant model calls (no extra Grok/GPT invocations)
5
+ # - Safe default passthrough if a mode/task_type is unrecognized
6
 
7
+ # Retained import in case you reference it elsewhere; not used here.
8
+ from gpt_helpers import ask_gpt41_mini # noqa: F401
9
 
10
+
11
+ def _wrap(title: str, jurisdiction: str, content: str) -> str:
12
+ """Minimal, consistent wrapper for returning labeled content."""
13
+ jur = f" ({jurisdiction})" if jurisdiction else ""
14
+ return f"{title}{jur}:\n\n{content}"
15
+
16
+
17
+ def process_task_response(task_type: str, grok_response: str, prompt: str, jurisdiction: str) -> str:
18
  """
19
+ Post-process Grok output for display/download. This function is intentionally lightweight:
20
+ - No additional retrieval or model calls
21
+ - Just adds consistent headings or minimal formatting per task type
22
+ - Safe passthrough for unknown types
23
  """
24
+ tt = (task_type or "").lower()
25
+
26
+ # Legacy/primary types
27
+ if tt in ("case_law", "irac"):
28
+ return _wrap("Case Law / IRAC Analysis", jurisdiction, grok_response)
29
+ if tt == "statute":
30
+ return _wrap("Statute Analysis", jurisdiction, grok_response)
31
+ if tt == "document_creation":
32
+ return _wrap("Final Document", jurisdiction, grok_response)
33
+ if tt == "document_analysis":
34
+ return _wrap("Document Analysis", jurisdiction, grok_response)
35
+ if tt == "legal_strategy":
36
+ return _wrap("Legal Strategy", jurisdiction, grok_response)
37
+
38
+ # Existing misc types (kept for compatibility with any callers you might have)
39
+ if tt == "analogical_reasoning":
40
+ return _wrap("Analogical Reasoning", jurisdiction, grok_response)
41
+ if tt in ("deposition_questions", "deposition_qs"):
42
+ return _wrap("Deposition Questions", jurisdiction, grok_response)
43
+ if tt == "verdict_predictor":
44
+ return _wrap("Verdict Prediction", jurisdiction, grok_response)
45
+ if tt == "damages_estimator":
46
+ return _wrap("Damages Estimate", jurisdiction, grok_response)
47
+ if tt == "pleading_validator":
48
+ return _wrap("Pleading Validation", jurisdiction, grok_response)
49
+ if tt == "legal_inbox":
50
+ return _wrap("Legal Inbox Processing", jurisdiction, grok_response)
51
+ if tt == "privilege_analyzer":
52
+ return _wrap("Privilege/PII Analysis", jurisdiction, grok_response)
53
+ if tt == "eli5":
54
+ return _wrap("Plain-English Explanation", jurisdiction, grok_response)
55
+ if tt == "workflow_template":
56
+ return _wrap("Workflow Template", jurisdiction, grok_response)
57
+
58
+ # New modes introduced in app.py
59
+ if tt == "citation_check":
60
+ return _wrap("Citation Check / Shepardizing-lite", jurisdiction, grok_response)
61
+ if tt == "brief_builder":
62
+ return _wrap("Brief Builder (IRAC Sections)", jurisdiction, grok_response)
63
+ if tt in ("deposition_qa",):
64
+ return _wrap("Deposition Q&A Generator", jurisdiction, grok_response)
65
+ if tt == "checklist":
66
+ return _wrap("Checklist & Red Flags", jurisdiction, grok_response)
67
+ if tt == "comparative_law":
68
+ return _wrap("Comparative Law", jurisdiction, grok_response)
69
+ if tt == "client_summary":
70
+ return _wrap("Client-Friendly Summary", jurisdiction, grok_response)
71
+ if tt == "motion_skeleton":
72
+ return _wrap("Motion Skeleton", jurisdiction, grok_response)
73
+ if tt == "opposing_argument":
74
+ return _wrap("Opposing Argument (Devil's Advocate)", jurisdiction, grok_response)
75
+ if tt == "case_extractor":
76
+ return _wrap("Case/Citation Extractor", jurisdiction, grok_response)
77
+ if tt == "judge_style":
78
+ return _wrap("Judge/County Style Adaptation", jurisdiction, grok_response)
79
+ if tt == "general_qa":
80
+ return _wrap("General Q&A", jurisdiction, grok_response)
81
+
82
+ # Fallback passthrough
83
+ return grok_response