ibfs_demo / prompts.py
MarginallyEffective's picture
Upload folder using huggingface_hub
55b0a04 verified
import yaml
from pathlib import Path
from typing import Dict, Any
import os
# Global prompts dictionary
PROMPTS = {}
def load_prompts(yaml_file="prompts.yaml"):
"""Load prompt templates from the YAML file or use defaults if file doesn't exist."""
global PROMPTS
yaml_path = Path(yaml_file)
if yaml_path.exists():
try:
with open(yaml_path, "r") as f:
prompts = yaml.safe_load(f)
print(f"Successfully loaded prompts from {yaml_file}")
PROMPTS = prompts
return prompts
except Exception as e:
print(f"Error loading prompts from file: {e}")
else:
print(f"Prompts file {yaml_file} not found, using default prompts")
raise FileNotFoundError(f"Prompts file {yaml_file} not found")
def format_prompt(prompt_template, **kwargs):
"""Format a prompt template with the provided kwargs."""
try:
return prompt_template.format(**kwargs)
except KeyError as e:
print(f"Missing key in prompt template: {e}")
return prompt_template
except Exception as e:
print(f"Error formatting prompt: {e}")
return prompt_template
# Initialize prompts when module is imported
load_prompts()