handle artifact bug

pull/664/head
Occupying-Mars 1 month ago
parent 82a2d8954b
commit f74f73124f

@ -2388,36 +2388,42 @@ class Agent:
) -> None: ) -> None:
"""Handle creating and saving artifacts with error handling.""" """Handle creating and saving artifacts with error handling."""
try: try:
logger.info( # Ensure file_extension starts with a dot
f"Creating artifact for file: {file_output_path}" if not file_extension.startswith('.'):
) file_extension = '.' + file_extension
# If file_output_path doesn't have an extension, treat it as a directory
# and create a default filename based on timestamp
if not os.path.splitext(file_output_path)[1]:
timestamp = time.strftime("%Y%m%d_%H%M%S")
filename = f"artifact_{timestamp}{file_extension}"
full_path = os.path.join(file_output_path, filename)
else:
full_path = file_output_path
# Create the directory if it doesn't exist
os.makedirs(os.path.dirname(full_path), exist_ok=True)
logger.info(f"Creating artifact for file: {full_path}")
artifact = Artifact( artifact = Artifact(
file_path=file_output_path, file_path=full_path,
file_type=file_extension, file_type=file_extension,
contents=text, contents=text,
edit_count=0, edit_count=0,
) )
logger.info( logger.info(f"Saving artifact with extension: {file_extension}")
f"Saving artifact with extension: {file_extension}"
)
artifact.save_as(file_extension) artifact.save_as(file_extension)
logger.success( logger.success(f"Successfully saved artifact to {full_path}")
f"Successfully saved artifact to {file_output_path}"
)
except ValueError as e: except ValueError as e:
logger.error( logger.error(f"Invalid input values for artifact: {str(e)}")
f"Invalid input values for artifact: {str(e)}"
)
raise raise
except IOError as e: except IOError as e:
logger.error(f"Error saving artifact to file: {str(e)}") logger.error(f"Error saving artifact to file: {str(e)}")
raise raise
except Exception as e: except Exception as e:
logger.error( logger.error(f"Unexpected error handling artifact: {str(e)}")
f"Unexpected error handling artifact: {str(e)}"
)
raise raise
def showcase_config(self): def showcase_config(self):

Loading…
Cancel
Save