Pydantic prompt
PydanticPrompt
PydanticPrompt(
name: Optional[str] = None,
language: str = "english",
original_hash: Optional[str] = None,
)
Bases: BasePrompt
, Generic[InputModel, OutputModel]
Source code in src/ragas/prompt/base.py
generate
async
generate(
llm: BaseRagasLLM,
data: InputModel,
temperature: Optional[float] = None,
stop: Optional[List[str]] = None,
callbacks: Optional[Callbacks] = None,
) -> OutputModel
Generate a single output using the provided language model and input data.
This method is a special case of generate_multiple
where only one output is generated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm
|
BaseRagasLLM
|
The language model to use for generation. |
required |
data
|
InputModel
|
The input data for generation. |
required |
temperature
|
float
|
The temperature parameter for controlling randomness in generation. |
None
|
stop
|
List[str]
|
A list of stop sequences to end generation. |
None
|
callbacks
|
Callbacks
|
Callback functions to be called during the generation process. |
None
|
Returns:
Type | Description |
---|---|
OutputModel
|
The generated output. |
Notes
This method internally calls generate_multiple
with n=1
and returns the first (and only) result.
Source code in src/ragas/prompt/pydantic_prompt.py
generate_multiple
async
generate_multiple(
llm: BaseRagasLLM,
data: InputModel,
n: int = 1,
temperature: Optional[float] = None,
stop: Optional[List[str]] = None,
callbacks: Optional[Callbacks] = None,
) -> List[OutputModel]
Generate multiple outputs using the provided language model and input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm
|
BaseRagasLLM
|
The language model to use for generation. |
required |
data
|
InputModel
|
The input data for generation. |
required |
n
|
int
|
The number of outputs to generate. Default is 1. |
1
|
temperature
|
float
|
The temperature parameter for controlling randomness in generation. |
None
|
stop
|
List[str]
|
A list of stop sequences to end generation. |
None
|
callbacks
|
Callbacks
|
Callback functions to be called during the generation process. |
None
|
Returns:
Type | Description |
---|---|
List[OutputModel]
|
A list of generated outputs. |
Raises:
Type | Description |
---|---|
RagasOutputParserException
|
If there's an error parsing the output. |
Source code in src/ragas/prompt/pydantic_prompt.py
adapt
async
adapt(
target_language: str, llm: BaseRagasLLM
) -> "PydanticPrompt[InputModel, OutputModel]"
Adapt the prompt to a new language.
Source code in src/ragas/prompt/pydantic_prompt.py
save
Save the prompt to a file.