Skip to content

Prompt

dandy.llm.Prompt dataclass

input = (None,) class-attribute instance-attribute

tag = (None,) class-attribute instance-attribute

estimated_token_count property

__post_init__

Source code in dandy/llm/prompt/prompt.py
def __post_init__(
        self,
):
    self.snippets: List[snippet.BaseSnippet] = []

    if isinstance(self.input, Prompt):
        self.text(text=self.input.to_str())

    if isinstance(self.input, str):
        self.text(text=self.input)

__str__

Source code in dandy/llm/prompt/prompt.py
def __str__(self) -> str:
    return self.to_str()

to_str

Source code in dandy/llm/prompt/prompt.py
def to_str(self) -> str:
    prompt_string = ''.join([_.to_str() for _ in self.snippets])

    if isinstance(self.tag, str):
        return f'<{self.tag}>\n{prompt_string}\n</{self.tag}>\n'
    else:
        return prompt_string

dict

Source code in dandy/llm/prompt/prompt.py
def dict(
        self,
        dictionary: Dict,
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.DictionarySnippet(
            dictionary=dictionary,
            triple_quote=triple_quote
        )
    )

    return self

divider

Source code in dandy/llm/prompt/prompt.py
def divider(self) -> Self:
    self.snippets.append(snippet.DividerSnippet())

    return self

array

Source code in dandy/llm/prompt/prompt.py
def array(self, items: List[str]) -> Self:
    self.snippets.append(snippet.ArraySnippet(items=items))

    return self

array_random_order

Source code in dandy/llm/prompt/prompt.py
def array_random_order(self, items: List[str]) -> Self:
    self.snippets.append(snippet.ArrayRandomOrderSnippet(items=items))

    return self

file

Source code in dandy/llm/prompt/prompt.py
def file(
        self,
        file_path: Union[str, Path],
        encoding: str = 'utf-8',
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.FileSnippet(
            file_path=file_path,
            encoding=encoding,
            triple_quote=triple_quote
        )
    )

    return self

heading

Source code in dandy/llm/prompt/prompt.py
def heading(
        self,
        heading: str,
) -> Self:

    self.snippets.append(
        snippet.HeadingSnippet(
            heading=heading,
        )
    )

    return self

line_break

Source code in dandy/llm/prompt/prompt.py
def line_break(self) -> Self:
    self.snippets.append(snippet.LineBreakSnippet())

    return self

list

Source code in dandy/llm/prompt/prompt.py
def list(
        self,
        items: List[str],
        triple_quote: bool = False
) -> Self:

    self.unordered_list(
        items=items,
        triple_quote=triple_quote
    )

    return self

intel

Source code in dandy/llm/prompt/prompt.py
def intel(
        self,
        intel: BaseIntel,
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.IntelSnippet(
            intel=intel,
            triple_quote=triple_quote
        )
    )

    return self

intel_schema

Source code in dandy/llm/prompt/prompt.py
def intel_schema(
        self,
        intel_class: Type[BaseIntel],
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.IntelSchemaSnippet(
            intel_class=intel_class,
            triple_quote=triple_quote
        )
    )

    return self

module_source

Source code in dandy/llm/prompt/prompt.py
def module_source(
        self,
        module_name: str,
        triple_quote: bool = True
) -> Self:

    self.snippets.append(
        snippet.ModuleSourceSnippet(
            module_name=module_name,
            triple_quote=triple_quote,
            triple_quote_label=module_name
        )
    )

    return self

object_source

Source code in dandy/llm/prompt/prompt.py
def object_source(
        self,
        object_module_name: str,
        triple_quote: bool = True
) -> Self:

    self.snippets.append(
        snippet.ObjectSourceSnippet(
            object_module_name=object_module_name,
            triple_quote=triple_quote,
            triple_quote_label=object_module_name
        )
    )

    return self

ordered_list

Source code in dandy/llm/prompt/prompt.py
def ordered_list(
        self,
        items: List[str],
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.OrderedListSnippet(
            items=items,
            triple_quote=triple_quote
        )
    )

    return self

prompt

Source code in dandy/llm/prompt/prompt.py
def prompt(
        self,
        prompt: Self | str,
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.PromptSnippet(
            prompt=prompt,
            triple_quote=triple_quote
        )
    )

    return self

random_choice

Source code in dandy/llm/prompt/prompt.py
def random_choice(
        self,
        choices: List[str],
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.RandomChoiceSnippet(
            choices=choices,
            triple_quote=triple_quote,
        )
    )

    return self

sub_heading

Source code in dandy/llm/prompt/prompt.py
def sub_heading(
        self,
        sub_heading: str,
) -> Self:

    self.snippets.append(
        snippet.SubHeadingSnippet(
            sub_heading=sub_heading,
        )
    )

    return self

text

Source code in dandy/llm/prompt/prompt.py
def text(
        self,
        text: str = '',
        label: str = '',
        triple_quote: bool = False,
        triple_quote_label: Union[str, None] = None,
) -> Self:

    self.snippets.append(
        snippet.TextSnippet(
            text=text,
            label=label,
            triple_quote=triple_quote,
            triple_quote_label=triple_quote_label,
        )
    )

    return self

title

Source code in dandy/llm/prompt/prompt.py
def title(
        self,
        title: str,
) -> Self:

    self.snippets.append(
        snippet.TitleSnippet(
            title=title,
        )
    )

    return self

unordered_list

Source code in dandy/llm/prompt/prompt.py
def unordered_list(
        self,
        items: List[str],
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.UnorderedListSnippet(
            items=items,
            triple_quote=triple_quote
        )
    )

    return self

unordered_random_list

Source code in dandy/llm/prompt/prompt.py
def unordered_random_list(
        self,
        items: List[str],
        triple_quote: bool = False
) -> Self:

    self.snippets.append(
        snippet.UnorderedRandomListSnippet(
            items=items,
            triple_quote=triple_quote
        )
    )

    return self