CRiY<dZddlZddlZddlmZmZGddZy)zI MemorySummarizer - Usa Claude per sintetizzare blocchi di conversazione N)ListDictcveZdZdZdej defdZdee de fdZ dee defdZ dee defd Z y ) MemorySummarizerz4Usa Claude per sintetizzare blocchi di conversazioneclient model_namec ||_||_y)N)rr)selfrrs X/mnt/ssd/data/python-lab/Jarvis-Cognitive/services/cognitiveservice/memory_summarizer.py__init__zMemorySummarizer.__init__ s $messagesreturnc f|j|}d|d} |jjj|jddd|dg}|j dj j}|jd rV|jd }g}d }|D]+} | jd r| }|s|j| -d j|}tj|} | S#tjtf$r"} t!d | d id d d ggdcYd } ~ Sd } ~ wwxYw)z?Estrae informazioni strutturate dall'utente dalle conversazionizbAnalizza questa conversazione e estrai SOLO le informazioni fattuali sull'utente. Conversazione: u Restituisci un JSON con questa struttura (compila solo i campi per cui hai info certe): { "name": "nome utente o null", "family": { "spouse": "nome coniuge o null", "children": ["nome1", "nome2"] o [], "other": "altre info familiari" }, "residence": "città/indirizzo o null", "company": "azienda dove lavora o null", "role": "ruolo professionale o null", "colleagues": ["nome1", "nome2"] o [], "interests": ["interesse1", "interesse2"] o [] } IMPORTANTE: Se non hai informazioni certe per un campo, usa null o []. Non inventare. Rispondi SOLO con il JSON, senza testo aggiuntivo.g333333?userrolecontentmodel max_tokens temperaturerrz``` Fz)[WARNING] Errore estrazione info utente: N)namefamily residencecompanyr colleagues interests)_format_messagesrrcreaterrtextstrip startswithsplitappendjoinjsonloadsJSONDecodeError Exceptionprint) r rconversation_textpromptresponse response_textlines json_linesin_jsonline extractedes r extract_user_infoz"MemorySummarizer.extract_user_infos[!11(;36.' {{++22oo#)f=> 3H%,,Q/44:: 3H##A&++113 3 Z 8< =&s8}o5XY Y ZsAA77 B'B"B'"B'cg}|D]L}|ddk(rdnd}|jdd}t|dkDr|ddd z}|j|d |Nd j|S) zFormatta messaggi per promptrrUtentez Marco AureliorrNz...z: z )getr:r'r()r rr2msgrrs r r!z!MemorySummarizer._format_messagesss~ /C"6{f48/Dggi,G7|c!!$3-%/ LLD6G9- . /{{5!!r N) __name__ __module__ __qualname____doc__ anthropic Anthropicstrr rrr8r;r!r r rrsj>%y22%%D$t*DDLZDJZ3Z< "d " "r r)rDrEr)typingrrrrHr r rJs! x"x"r