mirror of
https://github.com/hwchase17/langchain
synced 2024-11-16 06:13:16 +00:00
Harrison/delegate from template (#14266)
Co-authored-by: M.R. Sopacua <144725145+msopacua@users.noreply.github.com>
This commit is contained in:
parent
956d55de2b
commit
8eab4d95c0
@ -1,6 +1,7 @@
|
|||||||
"""Prompt schema definition."""
|
"""Prompt schema definition."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import warnings
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Literal, Optional, Union
|
from typing import Any, Dict, List, Literal, Optional, Union
|
||||||
|
|
||||||
@ -176,21 +177,30 @@ class PromptTemplate(StringPromptTemplate):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(
|
def from_file(
|
||||||
cls, template_file: Union[str, Path], input_variables: List[str], **kwargs: Any
|
cls,
|
||||||
|
template_file: Union[str, Path],
|
||||||
|
input_variables: Optional[List[str]] = None,
|
||||||
|
**kwargs: Any,
|
||||||
) -> PromptTemplate:
|
) -> PromptTemplate:
|
||||||
"""Load a prompt from a file.
|
"""Load a prompt from a file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
template_file: The path to the file containing the prompt template.
|
template_file: The path to the file containing the prompt template.
|
||||||
input_variables: A list of variable names the final prompt template
|
input_variables: [DEPRECATED] A list of variable names the final prompt
|
||||||
will expect.
|
template will expect.
|
||||||
|
|
||||||
|
input_variables is ignored as from_file now delegates to from_template().
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The prompt loaded from the file.
|
The prompt loaded from the file.
|
||||||
"""
|
"""
|
||||||
with open(str(template_file), "r") as f:
|
with open(str(template_file), "r") as f:
|
||||||
template = f.read()
|
template = f.read()
|
||||||
return cls(input_variables=input_variables, template=template, **kwargs)
|
if input_variables:
|
||||||
|
warnings.warn(
|
||||||
|
"`input_variables' is deprecated and ignored.", DeprecationWarning
|
||||||
|
)
|
||||||
|
return cls.from_template(template=template, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_template(
|
def from_template(
|
||||||
|
Loading…
Reference in New Issue
Block a user