langchain/libs/partners/prompty/langchain_prompty/renderers.py
Leonid Ganeline 50484be330
prompty: docstring (#23152)
Added missed docstrings. Format docstrings to the consistent format
(used in the API Reference)

---------

Co-authored-by: ccurme <chester.curme@gmail.com>
2024-06-19 12:50:58 -04:00

17 lines
492 B
Python

from langchain_core.utils import mustache
from pydantic import BaseModel
from .core import Invoker, Prompty, SimpleModel
class MustacheRenderer(Invoker):
"""Render a mustache template."""
def __init__(self, prompty: Prompty) -> None:
self.prompty = prompty
def invoke(self, data: BaseModel) -> BaseModel:
assert isinstance(data, SimpleModel)
generated = mustache.render(self.prompty.content, data.item)
return SimpleModel[str](item=generated)