-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
69 lines (61 loc) · 2.35 KB
/
utils.py
File metadata and controls
69 lines (61 loc) · 2.35 KB
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
61
62
63
64
65
66
67
68
69
import yaml
import json
import logging
import boto3
from boto3.session import Session
from datetime import datetime
from pathlib import Path
from typing import Union, Dict, Optional, Any, List, Tuple
# set a logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
def load_config(config_file: Union[Path, str]) -> Optional[Dict]:
"""
Load configuration from a local file.
:param config_file: Path to the local file
:return: Dictionary with the loaded configuration
"""
try:
config_data: Optional[Dict] = None
logger.info(f"Loading config from local file system: {config_file}")
content = Path(config_file).read_text()
config_data = yaml.safe_load(content)
logger.info(f"Loaded config from local file system: {config_data}")
except Exception as e:
logger.error(f"Error loading config from local file system: {e}")
config_data = None
return config_data
# Load the admin agent system prompt from the config file
def load_system_prompt(
prompt_path: str
) -> str:
"""
Load the system prompt from a file path.
Args:
prompt_path: Relative or absolute path to the system prompt file
Returns:
The system prompt as a string
"""
try:
# First try absolute path or relative to current directory
prompt_file = Path(prompt_path)
if prompt_file.exists():
prompt_content = prompt_file.read_text()
logger.info(f"Successfully loaded system prompt from {prompt_path}")
return prompt_content
# If not found, try relative to project root
# (assuming utils.py is in the root of the project)
project_root = Path(__file__).parent
project_prompt_path = project_root / prompt_path
if project_prompt_path.exists():
prompt_content = project_prompt_path.read_text()
logger.info(f"Successfully loaded system prompt from project root: {project_prompt_path}")
return prompt_content
# If still not found, raise error
raise FileNotFoundError(f"System prompt file not found at {prompt_path}")
except FileNotFoundError:
logger.error(f"System prompt file not found at {prompt_path}")
raise
except Exception as e:
logger.error(f"Error loading system prompt from {prompt_path}: {str(e)}")
raise