Skip to content

Commit

Permalink
🐛 fix(metadata): Ensure valid hash when forcing regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultyou committed Sep 30, 2024
1 parent 3ddf088 commit f391e49
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions .github/scripts/generate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ def generate_metadata(prompt_content):
def should_update_metadata(prompt_file, metadata_file):
"""Check if metadata should be updated based on content hash or force flag."""
force_regenerate = os.environ.get('FORCE_REGENERATE', 'false').lower() == 'true'

if force_regenerate:
logger.info("Forcing metadata regeneration due to system prompt changes.")
return True, None

# Generate hash of the prompt file content
with open(prompt_file, 'rb') as f:
prompt_content = f.read()
prompt_hash = hashlib.md5(prompt_content).hexdigest()

if force_regenerate:
logger.info("Forcing metadata regeneration due to system prompt changes.")
return True, prompt_hash

# If metadata file doesn't exist, update is needed
if not os.path.exists(metadata_file):
logger.info(f"Metadata file {metadata_file} does not exist. Update needed.")
Expand Down Expand Up @@ -214,6 +214,12 @@ def update_prompt_metadata():
with open(metadata_path, 'w') as f:
yaml.dump(metadata, f, sort_keys=False)

# Ensure we have a valid hash
if new_hash is None:
with open(prompt_file, 'rb') as f:
prompt_content = f.read()
new_hash = hashlib.md5(prompt_content).hexdigest()

# Update content hash
update_metadata_hash(metadata_path, new_hash)
else:
Expand Down

0 comments on commit f391e49

Please sign in to comment.