@@ -831,13 +831,21 @@ def _modify_summary(summary: dict) -> dict:
831831 return processed_summary
832832
833833 @classmethod
834- def _get_or_create_summary (cls , prompt : str , prompt_hash : str , type : OpsLearningPromptResponseCache .PromptType ) -> dict :
834+ def _get_or_create_summary (
835+ cls , prompt : str , prompt_hash : str , type : OpsLearningPromptResponseCache .PromptType , overwrite_prompt_cache : bool = False
836+ ) -> dict :
835837 instance , created = OpsLearningPromptResponseCache .objects .get_or_create (
836838 prompt_hash = prompt_hash ,
837839 type = type ,
838840 defaults = {"prompt" : prompt },
839841 )
840- if created or not bool (instance .response ):
842+ """
843+ NOTE:
844+ 1. If the prompt response is not found in the cache, it regenerates the summary
845+ 2. If overwrite_prompt_cache is True, it regenerates the summary
846+ 3. If new obj is created, it generates the summary
847+ """
848+ if overwrite_prompt_cache or created or not bool (instance .response ):
841849 summary = cls .generate_summary (prompt , type )
842850 instance .response = summary
843851 instance .save (update_fields = ["response" ])
@@ -926,6 +934,7 @@ def get_or_create_primary_summary(
926934 cls ,
927935 ops_learning_summary_instance : OpsLearningCacheResponse ,
928936 primary_learning_prompt : str ,
937+ overwrite_prompt_cache : bool = False ,
929938 ):
930939 """Retrieves or Generates the primary summary based on the provided prompt."""
931940 logger .info ("Retrieving or generating primary summary." )
@@ -938,6 +947,7 @@ def get_or_create_primary_summary(
938947 prompt = primary_learning_prompt ,
939948 prompt_hash = primary_prompt_hash ,
940949 type = OpsLearningPromptResponseCache .PromptType .PRIMARY ,
950+ overwrite_prompt_cache = overwrite_prompt_cache ,
941951 )
942952
943953 # Saving into the database
@@ -959,6 +969,7 @@ def get_or_create_secondary_summary(
959969 cls ,
960970 ops_learning_summary_instance : OpsLearningCacheResponse ,
961971 secondary_learning_prompt : str ,
972+ overwrite_prompt_cache : bool = False ,
962973 ):
963974 """Retrieves or Generates the summary based on the provided prompts."""
964975 logger .info ("Retrieving or generating secondary summary." )
@@ -971,6 +982,7 @@ def get_or_create_secondary_summary(
971982 prompt = secondary_learning_prompt ,
972983 prompt_hash = secondary_prompt_hash ,
973984 type = OpsLearningPromptResponseCache .PromptType .SECONDARY ,
985+ overwrite_prompt_cache = overwrite_prompt_cache ,
974986 )
975987
976988 # Saving into the database
0 commit comments