mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-10 15:06:18 +00:00
Allow extra variables when invoking prompt templates (#10765)
Makes chaining easier as many maps have extra properties. @baskaryan @hwchase17
This commit is contained in:
parent
8515e27d82
commit
babf46692d
@ -37,7 +37,9 @@ class BasePromptTemplate(Serializable, Runnable[Dict, PromptValue], ABC):
|
||||
|
||||
def invoke(self, input: Dict, config: RunnableConfig | None = None) -> PromptValue:
|
||||
return self._call_with_config(
|
||||
lambda inner_input: self.format_prompt(**inner_input),
|
||||
lambda inner_input: self.format_prompt(
|
||||
**{key: inner_input[key] for key in self.input_variables}
|
||||
),
|
||||
input,
|
||||
config,
|
||||
run_type="prompt",
|
||||
|
@ -369,6 +369,24 @@ async def test_prompt() -> None:
|
||||
] == [expected]
|
||||
|
||||
|
||||
def test_prompt_template_params() -> None:
|
||||
prompt = ChatPromptTemplate.from_template(
|
||||
"Respond to the following question: {question}"
|
||||
)
|
||||
result = prompt.invoke(
|
||||
{
|
||||
"question": "test",
|
||||
"topic": "test",
|
||||
}
|
||||
)
|
||||
assert result == ChatPromptValue(
|
||||
messages=[HumanMessage(content="Respond to the following question: test")]
|
||||
)
|
||||
|
||||
with pytest.raises(KeyError):
|
||||
prompt.invoke({})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@freeze_time("2023-01-01")
|
||||
async def test_prompt_with_chat_model(
|
||||
|
Loading…
Reference in New Issue
Block a user