Spaces:
Sleeping
Sleeping
Update app/utils/groq_client.py
Browse files- app/utils/groq_client.py +12 -7
app/utils/groq_client.py
CHANGED
|
@@ -94,12 +94,8 @@ class GroqClient:
|
|
| 94 |
|
| 95 |
Example JSON structure (fill with relevant details based on input):
|
| 96 |
{{
|
| 97 |
-
"caseSummary": {{ "
|
| 98 |
-
|
| 99 |
-
"personsInvolved": {{ "suspects": [{{ "name": "Suspect Name", "role": "Suspect", "details": "Relevant details" }}], "victims": [{{ "name": "Victim Name", "role": "Victim", "details": "Relevant details" }}], "witnesses": [{{ "name": "Witness Name", "role": "Witness", "details": "Relevant details" }}] }},
|
| 100 |
-
"evidenceCollected": {{ "physical": ["Item 1", "Item 2"], "testimonial": ["Statement 1"], "digital": ["File A.jpg"] }},
|
| 101 |
-
"interrogationSummary": {{ "subjectName": "Suspect Name", "dateOfInterrogation": "YYYY-MM-DD", "keyStatements": ["Statement A", "Statement B"], "observations": "Behavioral observations during interrogation." }},
|
| 102 |
-
"findingsAndInferences": {{ "keyFindings": ["Finding 1", "Finding 2"], "inferences": ["Inference A", "Inference B"], "investigatorAnalysis": "Overall analysis by the investigator." }},
|
| 103 |
"recommendations": {{ "chargesToBeFiled": ["Charge 1 (Specific to {selected_country_name} law)"], "furtherActions": ["Action A", "Action B (Consider {selected_country_name} procedures)"], "legalConsiderations_{selected_country_name}": "Specific legal points relevant to {selected_country_name}." }}
|
| 104 |
}}
|
| 105 |
"""
|
|
@@ -122,7 +118,9 @@ class GroqClient:
|
|
| 122 |
top_p=1,
|
| 123 |
stop=None,
|
| 124 |
)
|
| 125 |
-
|
|
|
|
|
|
|
| 126 |
# Validate if the output is valid JSON
|
| 127 |
try:
|
| 128 |
json.loads(json_output)
|
|
@@ -145,6 +143,13 @@ class GroqClient:
|
|
| 145 |
"details": str(e)
|
| 146 |
}}
|
| 147 |
return json.dumps(error_json)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
# Example usage (for testing outside Flask app context):
|
| 150 |
if __name__ == '__main__':
|
|
|
|
| 94 |
|
| 95 |
Example JSON structure (fill with relevant details based on input):
|
| 96 |
{{
|
| 97 |
+
"caseSummary": {{ "observations": "Behavioral observations during interrogation." }},
|
| 98 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
"recommendations": {{ "chargesToBeFiled": ["Charge 1 (Specific to {selected_country_name} law)"], "furtherActions": ["Action A", "Action B (Consider {selected_country_name} procedures)"], "legalConsiderations_{selected_country_name}": "Specific legal points relevant to {selected_country_name}." }}
|
| 100 |
}}
|
| 101 |
"""
|
|
|
|
| 118 |
top_p=1,
|
| 119 |
stop=None,
|
| 120 |
)
|
| 121 |
+
text_output = chat_completion.choices[0].message.content
|
| 122 |
+
print(text_output)
|
| 123 |
+
json_output = extract_json(text_output)
|
| 124 |
# Validate if the output is valid JSON
|
| 125 |
try:
|
| 126 |
json.loads(json_output)
|
|
|
|
| 143 |
"details": str(e)
|
| 144 |
}}
|
| 145 |
return json.dumps(error_json)
|
| 146 |
+
def extract_json(text):
|
| 147 |
+
start = text.find('{')
|
| 148 |
+
end = text.rfind('}') + 1
|
| 149 |
+
if start != -1 and end != -1:
|
| 150 |
+
json_str = text[start:end]
|
| 151 |
+
return json.loads(json_str)
|
| 152 |
+
raise ValueError("Valid JSON not found in text.")
|
| 153 |
|
| 154 |
# Example usage (for testing outside Flask app context):
|
| 155 |
if __name__ == '__main__':
|