Skip to content

LLM Function

Optimizable llm functions.

Classes:

  • AssistantOutput

    Describes an output of an LLM-based function.

  • Input

    Describes an input to an LLM-based function.

  • KindRef

    Refer to the input by the step kind. Refers the last step with the given kind.

  • Output

    Describes an output of an LLM-based function.

  • Variable

    Base class for all LLM function inputs and outputs

AssistantOutput

Bases: Output

Describes an output of an LLM-based function.

Source code in tapeagents/llm_function.py
60
61
62
63
64
class AssistantOutput(Output):
    """Describes an output of an LLM-based function."""

    def parse(self, text: str) -> Step:
        return AssistantStep(content=text)

Input

Bases: Variable

Describes an input to an LLM-based function.

Source code in tapeagents/llm_function.py
47
48
49
50
class Input(Variable):
    """Describes an input to an LLM-based function."""

    pass

KindRef

Bases: BaseModel

Refer to the input by the step kind. Refers the last step with the given kind.

Source code in tapeagents/llm_function.py
156
157
158
159
class KindRef(BaseModel):
    """Refer to the input by the step kind. Refers the last step with the given kind."""

    kind: str

Output

Bases: Variable

Describes an output of an LLM-based function.

Source code in tapeagents/llm_function.py
53
54
55
56
57
class Output(Variable):
    """Describes an output of an LLM-based function."""

    def parse(self, text: str) -> Step:
        raise NotImplementedError()

Variable

Bases: BaseModel

Base class for all LLM function inputs and outputs

Source code in tapeagents/llm_function.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Variable(BaseModel):
    """Base class for all LLM function inputs and outputs"""

    name: str
    prefix: str = ""
    desc: str = ""
    separator: str = " "

    def get_prefix(self):
        return self.prefix or f"{self.name.title()}:"

    def get_desc(self):
        return self.desc or f"${{{self.name}}}"

    def render(self, value: Step):
        return value.content  # type: ignore