Skip to content

Commit

Permalink
Harrison/delegate from template (langchain-ai#14266)
Browse files Browse the repository at this point in the history
Co-authored-by: M.R. Sopacua <144725145+msopacua@users.noreply.github.com>
  • Loading branch information
2 people authored and aymeric-roucher committed Dec 11, 2023
1 parent 334998b commit b6d626c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions libs/core/langchain_core/prompts/prompt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Prompt schema definition."""
from __future__ import annotations

import warnings
from pathlib import Path
from typing import Any, Dict, List, Literal, Optional, Union

Expand Down Expand Up @@ -176,21 +177,30 @@ def from_examples(

@classmethod
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:
"""Load a prompt from a file.
Args:
template_file: The path to the file containing the prompt template.
input_variables: A list of variable names the final prompt template
will expect.
input_variables: [DEPRECATED] A list of variable names the final prompt
template will expect.
input_variables is ignored as from_file now delegates to from_template().
Returns:
The prompt loaded from the file.
"""
with open(str(template_file), "r") as f:
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
def from_template(
Expand Down

0 comments on commit b6d626c

Please sign in to comment.