|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
"""Prompt schema definition."""
|
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
from typing import Any, Dict, List
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, Extra, root_validator
|
|
|
|
@ -10,7 +11,31 @@ _FORMATTER_MAPPING = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Prompt(BaseModel):
|
|
|
|
|
class BasePrompt(ABC):
|
|
|
|
|
"""Base prompt should expose the format method, returning a prompt."""
|
|
|
|
|
|
|
|
|
|
input_variables: List[str]
|
|
|
|
|
"""A list of the names of the variables the prompt template expects."""
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def format(self, **kwargs: Any) -> str:
|
|
|
|
|
"""Format the prompt with the inputs.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
kwargs: Any arguments to be passed to the prompt template.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
A formatted string.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
prompt.format(variable1="foo")
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Prompt(BaseModel, BasePrompt):
|
|
|
|
|
"""Schema to represent a prompt for an LLM.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|