mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-09-27 17:15:35 +00:00
feat: Add prompt_template to conversational agent init params (#4994)
This commit is contained in:
parent
524d2cba36
commit
ae9f384a97
@ -1,8 +1,8 @@
|
|||||||
from typing import Optional, Callable
|
from typing import Optional, Callable, Union
|
||||||
|
|
||||||
from haystack.agents import Agent
|
from haystack.agents import Agent
|
||||||
from haystack.agents.memory import Memory, ConversationMemory
|
from haystack.agents.memory import Memory, ConversationMemory
|
||||||
from haystack.nodes import PromptNode
|
from haystack.nodes import PromptNode, PromptTemplate
|
||||||
|
|
||||||
|
|
||||||
class ConversationalAgent(Agent):
|
class ConversationalAgent(Agent):
|
||||||
@ -36,6 +36,7 @@ class ConversationalAgent(Agent):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
prompt_node: PromptNode,
|
prompt_node: PromptNode,
|
||||||
|
prompt_template: Optional[Union[str, PromptTemplate]] = None,
|
||||||
memory: Optional[Memory] = None,
|
memory: Optional[Memory] = None,
|
||||||
prompt_parameters_resolver: Optional[Callable] = None,
|
prompt_parameters_resolver: Optional[Callable] = None,
|
||||||
):
|
):
|
||||||
@ -43,6 +44,8 @@ class ConversationalAgent(Agent):
|
|||||||
Creates a new ConversationalAgent instance
|
Creates a new ConversationalAgent instance
|
||||||
|
|
||||||
:param prompt_node: A PromptNode used to communicate with LLM.
|
:param prompt_node: A PromptNode used to communicate with LLM.
|
||||||
|
:param prompt_template: A string or PromptTemplate instance to use as the prompt template. If no prompt_template
|
||||||
|
is provided, the agent will use the "conversational-agent" template.
|
||||||
:param memory: A memory instance for storing conversation history and other relevant data, defaults to
|
:param memory: A memory instance for storing conversation history and other relevant data, defaults to
|
||||||
ConversationMemory.
|
ConversationMemory.
|
||||||
:param prompt_parameters_resolver: An optional callable for resolving prompt template parameters,
|
:param prompt_parameters_resolver: An optional callable for resolving prompt template parameters,
|
||||||
@ -50,9 +53,7 @@ class ConversationalAgent(Agent):
|
|||||||
"""
|
"""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
prompt_node=prompt_node,
|
prompt_node=prompt_node,
|
||||||
prompt_template=prompt_node.default_prompt_template
|
prompt_template=prompt_template or "conversational-agent",
|
||||||
if prompt_node.default_prompt_template is not None
|
|
||||||
else "conversational-agent",
|
|
||||||
max_steps=2,
|
max_steps=2,
|
||||||
memory=memory if memory else ConversationMemory(),
|
memory=memory if memory else ConversationMemory(),
|
||||||
prompt_parameters_resolver=prompt_parameters_resolver
|
prompt_parameters_resolver=prompt_parameters_resolver
|
||||||
|
Loading…
x
Reference in New Issue
Block a user