Mirascopev2
Lilypad

prompts

Class AsyncContextPrompt

Protocol for an AsyncContextPrompt, which returns list[Message].

Bases:

Protocol[P, DepsT]

Class AsyncContextPromptable

Protocol for an AsyncContextPromptable that returns UserContent or list[Message].

May be converted by the prompt decorator into an AsyncContextPrompt.

Bases:

Protocol[P, DepsT]

Class AsyncPrompt

Protocol for an AsyncPrompt, which returns list[Message].

Bases:

Protocol[P]

Class AsyncPromptable

Protocol for an AsyncPromptable that returns UserContent or list[Message].

May be converted by the prompt decorator into an AsyncPrompt.

Bases:

Protocol[P]

Class ContextPrompt

Protocol for a ContextPrompt, which returns list[Message].

Bases:

Protocol[P, DepsT]

Class ContextPromptable

Protocol for a ContextPromptable that returns UserContent or list[Message].

May be converted by the prompt decorator into a ContextPrompt.

Bases:

Protocol[P, DepsT]

Class Prompt

Protocol for a Prompt, which returns list[Message].

Bases:

Protocol[P]

Attribute PromptT

Type: TypeVar('PromptT', bound='Prompt | AsyncPrompt | ContextPrompt | AsyncContextPrompt')

Type variable for prompt types.

This type var represents a resolved prompt, i.e. one that returns a list of messages.

Class Promptable

Protocol for a Promptable that returns UserContent or list[Message].

May be be converted by the prompt decorator into a Prompt.

Bases:

Protocol[P]

Function prompt

Prompt decorator for turning functions (or "Prompts") into prompts.

This decorator transforms a function into a Prompt, i.e. a function that returns list[llm.Message]. Its behavior depends on whether it's called with a spec string.

If the first parameter is named 'ctx' or typed as llm.Context[T], it creates a ContextPrompt. Otherwise, it creates a regular Prompt.

With a template string, it returns a PromptTemplateDecorator, in which case it uses the provided template to decorate an function with an empty body, and uses arguments to the function for variable substitution in the template. The resulting PromptTemplate returns messages based on the template.

Without a template string, it returns a PromptFunctionalDecorator, which transforms a Prompt (a function returning either message content, or messages) into a PromptTemplate. The resulting prompt template either promotes the content into a list containing a single user message, or passes along the messages returned by the decorated function.

Spec substitution rules:

  • [USER], [ASSISTANT], [SYSTEM] demarcate the start of a new message with that role
  • [MESSAGES] indicates the next variable contains a list of messages to include
  • {{ variable }} injects the variable as a string, unless annotated
  • Annotations: {{ variable:annotation }} where annotation is one of: image, images, audio, audios, document, documents
  • Single content annotations (image, audio, document) expect a file path, URL, base64 string, or bytes, which becomes a content part with inferred mime-type
  • Multiple content annotations (images, audios, documents) expect a list of strings or bytes, each becoming a content part with inferred mime-type

Parameters

NameTypeDescription
__fn= NoneContextPromptable[P, DepsT] | AsyncContextPromptable[P, DepsT] | Promptable[P] | AsyncPromptable[P] | None-
template= Nonestr | NoneA string template with placeholders using `{{ variable_name }}` and optional role markers like [SYSTEM], [USER], and [ASSISTANT].

Returns

TypeDescription
ContextPrompt[P, DepsT] | AsyncContextPrompt[P, DepsT] | Prompt[P] | AsyncPrompt[P] | PromptDecorator | PromptTemplateDecoratorA PromptTemplateDecorator or PromptFunctionalDecorator that converts the decorated function into a prompt.