From 4f365bd0800ec1649ac9332cfefde675b0532a94 Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Tue, 7 May 2024 20:42:40 -0400 Subject: [PATCH] Adjusted image name to have recipe/memory uuid in name to prevent browser cache showing old images --- actions/actions_plugins/recipe-server/actions.py | 11 +++++++---- .../prompts/llm_data_recipes_plugin.jinja | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/actions/actions_plugins/recipe-server/actions.py b/actions/actions_plugins/recipe-server/actions.py index 60fd80d0..1b5bd270 100644 --- a/actions/actions_plugins/recipe-server/actions.py +++ b/actions/actions_plugins/recipe-server/actions.py @@ -118,12 +118,13 @@ db = None -def process_image(encoded_string): +def process_image(encoded_string, recipe_id): """ Takes a base64 encoded string of a picture, decodes it, and saves it as a PNG file. Args: encoded_string (str): Base64 encoded string of the image. + recipe_id (str): The recipe ID to use in the image file name. Returns: str: Full path to the saved image file. @@ -138,7 +139,7 @@ def process_image(encoded_string): image = Image.open(io.BytesIO(image_data)) # Create the full path for saving the image - full_path = os.path.join("./images", "memory_image.png") + full_path = os.path.join("./images", f"memory_image_{recipe_id}.png") # Save the image image.save(full_path, "PNG") @@ -458,10 +459,12 @@ def get_memory(user_input, chat_history, generate_intent=True) -> str: if memory_found is True: response_text = result["metadata"]["response_text"] response_image = result["metadata"]["response_image"] + recipe_id = result["metadata"]["custom_id"] + print("Recipe ID: ", recipe_id) if response_image is not None and response_image != "": - process_image(response_image.replace("data:image/png;base64,", "")) + process_image(response_image.replace("data:image/png;base64,", ""), recipe_id) #result = "http://localhost:9999/memory_image.png" - result = f"{os.getenv('IMAGE_HOST')}/memory_image.png" + result = f"{os.getenv('IMAGE_HOST')}/memory_image_{recipe_id}.png" else: result = response_text diff --git a/assistant/recipes_assistant/prompts/llm_data_recipes_plugin.jinja b/assistant/recipes_assistant/prompts/llm_data_recipes_plugin.jinja index e5bbe55c..de168c98 100644 --- a/assistant/recipes_assistant/prompts/llm_data_recipes_plugin.jinja +++ b/assistant/recipes_assistant/prompts/llm_data_recipes_plugin.jinja @@ -2,4 +2,6 @@ You are a helpful assistant. You have access to a library of humanitarian data recipes via your plugin, answer any questions about humanitarian-related data by calling the plugin -Any images returned will be hosted with this URL: https://ai-assistants-prototypes.azurewebsites.net/images \ No newline at end of file +Any images returned will be hosted with this URL: https://ai-assistants-prototypes.azurewebsites.net/images + +ALWAYS display images inline \ No newline at end of file