Skip to content

topicjev.prompts

Bundled prompt templates. See Prompt Templates for what each template does and how to fill it.

list_prompts

list_prompts() -> list[str]

Return a sorted list of available prompt template names without extensions.

Source code in topicjev/prompts/__init__.py
def list_prompts() -> list[str]:
    """Return a sorted list of available prompt template names without extensions."""
    files = resources.files(__package__).iterdir()
    return sorted(f.name[:-4] for f in files if f.name.endswith(".txt"))

load_prompt

load_prompt(name: str) -> str

Load a prompt template by name (with or without the .txt extension).

Parameters:

Name Type Description Default
name str

Name of the prompt file (e.g. 'goalex' or 'goalex.txt').

required

Returns:

Type Description
str

The content of the prompt template string with trailing newline stripped.

Raises:

Type Description
FileNotFoundError

If the specified prompt template does not exist.

Source code in topicjev/prompts/__init__.py
def load_prompt(name: str) -> str:
    """Load a prompt template by name (with or without the `.txt` extension).

    Args:
        name: Name of the prompt file (e.g. 'goalex' or 'goalex.txt').

    Returns:
        The content of the prompt template string with trailing newline stripped.

    Raises:
        FileNotFoundError: If the specified prompt template does not exist.
    """
    filename = name if name.endswith(".txt") else f"{name}.txt"
    path = resources.files(__package__).joinpath(filename)
    if not path.is_file():
        available = ", ".join(repr(p) for p in list_prompts())
        raise FileNotFoundError(
            f"Prompt template {filename!r} not found in {__package__}. Available prompts: {available}"
        )
    return path.read_text(encoding="utf-8").rstrip("\n")