Skip to content

Commit

Permalink
Adjusted image name to have recipe/memory uuid in name to prevent bro…
Browse files Browse the repository at this point in the history
…wser cache showing old images
  • Loading branch information
dividor committed May 8, 2024
1 parent 78786bf commit 4f365bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions actions/actions_plugins/recipe-server/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Any images returned will be hosted with this URL: https://ai-assistants-prototypes.azurewebsites.net/images

ALWAYS display images inline

0 comments on commit 4f365bd

Please sign in to comment.