@@ -819,7 +819,7 @@ def _modify_summary(summary: dict) -> dict:
819819 continue
820820 if confidence_level in value ["content" ].lower ():
821821 parts = re .split (rf"(?i)\b{ confidence_level } \b" , value ["content" ])
822- value ["content" ] = parts [0 ]
822+ value ["content" ] = parts [0 ]. strip () + "."
823823 value ["confidence level" ] = parts [1 ][1 :].strip ()
824824
825825 return summary
@@ -834,7 +834,7 @@ def _modify_summary(summary: dict) -> dict:
834834 def _get_or_create_summary (
835835 cls , prompt : str , prompt_hash : str , type : OpsLearningPromptResponseCache .PromptType , overwrite_prompt_cache : bool = False
836836 ) -> dict :
837- instance , created = OpsLearningPromptResponseCache .objects .get_or_create (
837+ instance , created = OpsLearningPromptResponseCache .objects .update_or_create (
838838 prompt_hash = prompt_hash ,
839839 type = type ,
840840 defaults = {"prompt" : prompt },
@@ -845,7 +845,7 @@ def _get_or_create_summary(
845845 2. If overwrite_prompt_cache is True, it regenerates the summary
846846 3. If new obj is created, it generates the summary
847847 """
848- if overwrite_prompt_cache or created or not bool (instance .response ):
848+ if overwrite_prompt_cache or created or bool (instance .response ) is False :
849849 summary = cls .generate_summary (prompt , type )
850850 instance .response = summary
851851 instance .save (update_fields = ["response" ])
@@ -984,6 +984,11 @@ def get_or_create_secondary_summary(
984984 type = OpsLearningPromptResponseCache .PromptType .SECONDARY ,
985985 overwrite_prompt_cache = overwrite_prompt_cache ,
986986 )
987+ if overwrite_prompt_cache :
988+ logger .info ("Clearing the cache for secondary summary." )
989+ # NOTE: find a better way to update the cache
990+ OpsLearningComponentCacheResponse .objects .filter (filter_response = ops_learning_summary_instance ).delete ()
991+ OpsLearningSectorCacheResponse .objects .filter (filter_response = ops_learning_summary_instance ).delete ()
987992
988993 # Saving into the database
989994 cls .secondary_response_save_to_db (
0 commit comments