Team Ai
Apppublic

24f3001764/llm_code_deployment

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
utils.py73 linesDownload Raw Back to src
1import base642import os3import re4from pathlib import Path5from typing import List6import aiofiles7from src.models import Attachment8from src.config import config9 10 11async def decode_and_save_attachments(attachments: List[Attachment], task_id: str) -> List[Path]:12    """Decode data URIs and save attachments to disk"""13    saved_paths = []14    15    # Create temp directory16    temp_dir = Path(config.TEMP_ATTACHMENTS_DIR) / task_id17    temp_dir.mkdir(parents=True, exist_ok=True)18    19    for attachment in attachments:20        # Parse data URI: data:image/png;base64,iVBORw...21        match = re.match(r'data:([^;]+);base64,(.+)', attachment.url)22        if not match:23            continue24        25        mime_type, base64_data = match.groups()26        27        # Decode base6428        file_data = base64.b64decode(base64_data)29        30        # Save to file31        file_path = temp_dir / attachment.name32        async with aiofiles.open(file_path, 'wb') as f:33            await f.write(file_data)34        35        saved_paths.append(file_path)36    37    return saved_paths38 39 40def sanitize_repo_name(task_id: str) -> str:41    """Convert task ID to valid GitHub repo name"""42    # Replace invalid characters with hyphens43    repo_name = re.sub(r'[^a-zA-Z0-9\-_.]', '-', task_id)44    # Remove leading/trailing hyphens45    repo_name = repo_name.strip('-')46    return repo_name47 48 49def get_mit_license() -> str:50    """Return MIT license text"""51    return """MIT License52 53Copyright (c) 202554 55Permission is hereby granted, free of charge, to any person obtaining a copy56of this software and associated documentation files (the "Software"), to deal57in the Software without restriction, including without limitation the rights58to use, copy, modify, merge, publish, distribute, sublicense, and/or sell59copies of the Software, and to permit persons to whom the Software is60furnished to do so, subject to the following conditions:61 62The above copyright notice and this permission notice shall be included in all63copies or substantial portions of the Software.64 65THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR66IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,67FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE68AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER69LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,70OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE71SOFTWARE.72"""73