Skip to content

Base Strategy

BaseStrategy(llm_client=None, api_key=None, model=None, temperature=None, **kwargs)

Bases: ABC

Abstract base class for all prompt refinement strategies.

Initializes with OpenAI API credentials (defaults to global config).

Source code in promptrefiner/base.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def __init__(
    self,
    llm_client=None,
    api_key=None,
    model=None,
    temperature=None,
    **kwargs,
):
    """
    Initializes with OpenAI API credentials (defaults to global config).
    """
    if llm_client:
        self.llm_client = llm_client
    else:
        config = load_config(api_key, model, temperature)
        self.llm_client = get_llm_client(
            config["api_key"], config["model"], temperature, **kwargs
        )

get_system_prompt() abstractmethod

Each strategy must define its own system prompt.

Source code in promptrefiner/base.py
28
29
30
31
@abstractmethod
def get_system_prompt(self) -> str:  # pragma: no cover
    """Each strategy must define its own system prompt."""
    pass

refine(prompt)

Refine a prompt using OpenAI API, applying strategy-specific system instructions.

Source code in promptrefiner/base.py
33
34
35
def refine(self, prompt: str) -> str:
    """Refine a prompt using OpenAI API, applying strategy-specific system instructions."""
    return self.llm_client(self.get_system_prompt(), prompt)