File size: 1,861 Bytes
3370983
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Prompt Registry Module
======================

Centralized prompt management using PromptLayer with optional local files.
Provides a singleton PromptManager instance for loading prompts from:
1. Local prompt files (if local_prompt_path is provided)
2. PromptLayer cloud service (if PROMPTLAYER_API_KEY is set)
"""

import os
from .prompt_layer import PromptManager

# Path to the templates folder inside the package
TEMPLATES_DIR = os.path.join(os.path.dirname(__file__), "templates")

# Singleton PromptManager instance
_prompt_manager = PromptManager(environment=os.getenv("PROMPT_ENVIRONMENT", "production"))
# Force local-only prompts; disable remote PromptLayer client if present
_prompt_manager.client = None


def get_prompt(
    template_name: str,
    version: int = None,
    label: str = None,
    local_prompt_path: str = None,
    latest_version: bool = False,
) -> str:
    """
    Load a prompt from local templates only (PromptLayer disabled here).

    Strategy:
    - If local_prompt_path is provided, use it.
    - Otherwise, use the default templates directory.
    """
    # Normalize template name to match folder names (lowercase)
    if template_name:
        template_name = template_name.lower()

    if local_prompt_path:
        if not os.path.isabs(local_prompt_path):
            local_prompt_path = os.path.join(TEMPLATES_DIR, local_prompt_path)
    else:
        local_prompt_path = TEMPLATES_DIR

    return _prompt_manager.get_prompt(
        template_name=template_name,
        version=version,
        label=label,
        local_prompt_path=local_prompt_path,
        latest_version=latest_version,
    )


def get_prompt_manager() -> PromptManager:
    """Return singleton PromptManager."""
    return _prompt_manager


__all__ = [
    "get_prompt",
    "get_prompt_manager",
    "PromptManager",
    "TEMPLATES_DIR"
]