File size: 1,186 Bytes
7f611c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Base context builder interface."""

from abc import ABC, abstractmethod
from typing import Any, Dict, Union

from skydiscover.config import Config
from skydiscover.search.base_database import Program


class ContextBuilder(ABC):
    """Abstract base for building LLM prompts.

    Subclass this and implement build_prompt(). Each subclass sets up its
    own template_manager and any other resources it needs.
    """

    def __init__(self, config: Config):
        self.config = config
        self.context_config = config.context_builder

    @abstractmethod
    def build_prompt(
        self,
        current_program: Union[Program, Dict[str, Program]],
        context: Dict[str, Any] = None,
        **kwargs: Any,
    ) -> Dict[str, str]:
        """Build a prompt for the LLM.

        Args:
            current_program: Program or {info: Program} to evolve from.
                When a dict, the key is additional context about the program.
            context: optional dict with keys such as program_metrics,
                other_context_programs, etc.

        Returns:
            Dict with "system" and "user" keys containing prompt strings.
        """
        pass