File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1515 extract_candidate_data_with_openai ,
1616 extract_job_data_with_openai ,
1717 clean_cv_text ,
18- reformat_cv_text_with_openai
18+ reformat_cv_text_with_openai ,
19+ parse_json_result
1920)
2021
2122from core .utils import generate_unique_slug
Original file line number Diff line number Diff line change @@ -291,4 +291,18 @@ def generate():
291291 if delta :
292292 yield delta
293293
294- return StreamingHttpResponse (generate (), content_type = 'text/plain' )
294+ return StreamingHttpResponse (generate (), content_type = 'text/plain' )
295+
296+
297+ def parse_json_result (result ):
298+ """
299+ Tar en sträng från OpenAI som kan innehålla ```json-taggar,
300+ rensar dessa och returnerar resultatet som en Python-dict.
301+ """
302+ try :
303+ # Ta bort ev. ```json-taggar och onödiga whitespace
304+ cleaned = re .sub (r"```json|```" , "" , result ).strip ()
305+ return json .loads (cleaned )
306+ except json .JSONDecodeError as e :
307+ print ("❌ JSONDecodeError i parse_json_result:" , e )
308+ return {}
You can’t perform that action at this time.
0 commit comments