langtree.core.prompt

Module Contents

Classes

Prompt

A class to represent and process prompt templates.

Functions

render_prompt(template, **kwargs)

Render a template string by substituting placeholders with provided keyword arguments.

langtree.core.prompt.render_prompt(template, **kwargs)[source]

Render a template string by substituting placeholders with provided keyword arguments.

Parameters:
  • template (str) – The template string containing placeholders.

  • **kwargs – Keyword arguments representing placeholder-value pairs.

Returns:

The rendered string after substitutions.

Return type:

str

class langtree.core.prompt.Prompt(template)[source]

A class to represent and process prompt templates.

__call__(**kwargs)[source]

Render the prompt using the provided keyword arguments.

Parameters:

**kwargs – Keyword arguments for rendering the prompt.

Returns:

The rendered prompt.

Return type:

str

__add__(other)[source]

Handle concatenation of two Prompt objects or a Prompt object with a string.

Parameters:

other (Prompt, str) – Another Prompt object or a string to concatenate with.

Returns:

A new Prompt object with concatenated templates.

Return type:

Prompt

Raises:

TypeError – If the other object is neither a Prompt nor a string.