Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harrison/delegate from template #14266

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading