Improve LLM and CSV processing
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"""Helpers for assigning stable, collision-free output filenames."""
|
||||
|
||||
import os
|
||||
from typing import Dict, Optional
|
||||
|
||||
|
||||
def resolve_name(name: str, content: bytes, seen: Dict[str, bytes]) -> Optional[str]:
|
||||
"""Return a unique name, or None when the same name and content were seen.
|
||||
|
||||
Name collisions with different content receive numeric suffixes before
|
||||
the extension, while exact duplicates are omitted.
|
||||
"""
|
||||
if name not in seen:
|
||||
seen[name] = content
|
||||
return name
|
||||
if seen[name] == content:
|
||||
return None
|
||||
|
||||
base, ext = os.path.splitext(name)
|
||||
index = 2
|
||||
while f"{base}_{index}{ext}" in seen:
|
||||
index += 1
|
||||
resolved = f"{base}_{index}{ext}"
|
||||
seen[resolved] = content
|
||||
return resolved
|
||||
Reference in New Issue
Block a user