Spaces:
Sleeping
Sleeping
File size: 1,594 Bytes
55b0a04 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import os
import json
import uuid
from datetime import datetime
from pathlib import Path
from dotenv import load_dotenv
from typing import Dict, Any, List, Optional
# Load environment variables
load_dotenv()
# Create directory for saving results if it doesn't exist
def ensure_directories():
"""Create necessary directories if they don't exist."""
os.makedirs("ibfs_results", exist_ok=True)
def generate_user_id() -> str:
"""Generate a unique user ID."""
return str(uuid.uuid4())
def save_results(user_id: str, query: str, final_answer: str, method: str = "ibfs",
strategy_path: Optional[List[str]] = None) -> str:
"""
Save the results to a file.
Args:
user_id: Unique identifier for the user
query: Original query
final_answer: Final answer generated
method: Method used (ibfs or zero_shot)
strategy_path: Path of selected strategies (for IBFS)
Returns:
Filename where results were saved
"""
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
result = {
"user_id": user_id,
"timestamp": timestamp,
"method": method,
"query": query,
"final_answer": final_answer
}
# Add strategy path for IBFS method
if method == "ibfs" and strategy_path:
result["strategy_path"] = strategy_path
filename = f"ibfs_results/{user_id}_{method}_{timestamp}.json"
with open(filename, "w") as f:
json.dump(result, f, indent=2)
return filename
# Initialize directories when module is imported
ensure_directories() |