File size: 1,183 Bytes
3c439f4
 
 
e8c805a
 
3c439f4
 
c8325a7
 
3c439f4
e8c805a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c439f4
 
 
 
 
 
 
 
 
 
 
 
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
"""Phoenix tracing setup for the OracleBot application."""

import logging
import shutil
from pathlib import Path
from phoenix.otel import register

DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
APP_NAME = "OracleBot"

# Define cache directory path globally
CACHE_DIR = Path(__file__).parent / "cache"

def initialize_cache_directory():
    """Initialize the cache directory for file operations."""
    # Remove existing cache directory if it exists
    if CACHE_DIR.exists():
        print(f"Removing existing cache directory: {CACHE_DIR}")
        shutil.rmtree(CACHE_DIR)
    
    # Create fresh cache directory
    CACHE_DIR.mkdir(parents=True, exist_ok=True)
    print(f"Created fresh cache directory: {CACHE_DIR}")
    
    return str(CACHE_DIR)


def start_phoenix(project_name: str = APP_NAME) -> None:
    """Setup Phoenix tracing for the agent.
    
    Args:
        project_name: Name of the project to use for Phoenix tracing
    """
    register(
        project_name=project_name,
        auto_instrument=True,
    )
    logging.getLogger("openinference").setLevel(logging.CRITICAL)
    print(f"Phoenix tracing enabled for project: {project_name}")