haystack
haystack copied to clipboard
ChatPromptBuilder raises the misleading ValueError when receiving incorect argument
Describe the bug
The ChatPromptBuilder raises a misleading ValueError when receiving incorrect argument.
It complains that the prompt_source entry in not found, but it really needs the template argument
Error message ValueError: Input prompt_source not found in component prompt_builder.
Expected behavior ValueError: Input template not found in component prompt_builder.
Additional context
I noticed this while migrating from the DynamicChatPromptBuilder and forgot to change prompt_source to ´template`
To Reproduce
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack import Pipeline
from haystack.utils import Secret
# no parameter init, we don't use any runtime template variables
prompt_builder = ChatPromptBuilder()
llm = OpenAIChatGenerator(api_key=Secret.from_token("<your-api-key>"), model="gpt-3.5-turbo")
pipe = Pipeline()
pipe.add_component("prompt_builder", prompt_builder)
pipe.add_component("llm", llm)
pipe.connect("prompt_builder.prompt", "llm.messages")
location = "Berlin"
language = "English"
system_message = ChatMessage.from_system("You are an assistant giving information to tourists in {{language}}")
messages = [system_message, ChatMessage.from_user("Tell me about {{location}}")]
res = pipe.run(data={"prompt_builder": {"template_variables": {"location": location, "language": language},
"prompt_source": messages}})
print(res)
System:
- OS: mac
- GPU/CPU: M3 Pro
- Haystack version (commit or version number): 2.2.3