Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.
Python aiburrchatbot-frameworkdagsgenerative-aigraphshacktoberfestllmopsllmsmlopspersistent-data-structurestate-machinestate-managementvisibility
fix(examples): bound image telephone downloads (#879)
Rolly Calmac96b5f78f68a
diff --git a/examples/image-telephone/application.py b/examples/image-telephone/application.pyindex fa5aaf77..35ab2984 100644--- a/examples/image-telephone/application.py+++ b/examples/image-telephone/application.py@@ -42,6 +42,8 @@ from burr.core import Action, ApplicationBuilder, State, default, exprfrom burr.core.action import actionfrom burr.lifecycle import PostRunStepHook+IMAGE_DOWNLOAD_TIMEOUT_SECONDS = 30+# import hamilton modules that define the DAGs for image captioning and image generationcaption_images = dataflows.import_module("caption_images", "elijahbenizzy")generate_images = dataflows.import_module("generate_images", "elijahbenizzy")@@ -67,7 +69,11 @@ class ImageSaverHook(PostRunStepHook):image_url = state["current_image_location"]image_name = "image_" + str(state["__SEQUENCE_ID"]) + ".png"with open(os.path.join(self.path, image_name), "wb") as f:- f.write(requests.get(image_url).content)+ response = requests.get(+ image_url, timeout=IMAGE_DOWNLOAD_TIMEOUT_SECONDS+ )+ response.raise_for_status()+ f.write(response.content)print(f"Saved image to {self.path}/{image_name}")diff --git a/examples/integrations/hamilton/image-telephone/application.py b/examples/integrations/hamilton/image-telephone/application.pyindex 4f7f5fa1..44b44b5a 100644--- a/examples/integrations/hamilton/image-telephone/application.py+++ b/examples/integrations/hamilton/image-telephone/application.py@@ -33,6 +33,8 @@ from burr.core.action import actionfrom burr.integrations import hamiltonfrom burr.lifecycle import PostRunStepHook+IMAGE_DOWNLOAD_TIMEOUT_SECONDS = 30+caption_images = dataflows.import_module("caption_images", "elijahbenizzy")generate_images = dataflows.import_module("generate_images", "elijahbenizzy")@@ -53,7 +55,11 @@ class ImageSaverHook(PostRunStepHook):image_url = state["current_image_location"]image_name = "image_" + str(state["__SEQUENCE_ID"]) + ".png"with open(os.path.join(self.path, image_name), "wb") as f:- f.write(requests.get(image_url).content)+ response = requests.get(+ image_url, timeout=IMAGE_DOWNLOAD_TIMEOUT_SECONDS+ )+ response.raise_for_status()+ f.write(response.content)print(f"Saved image to {self.path}/{image_name}")