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

ChatPromptBuilder raises the misleading ValueError when receiving incorect argument #7962

Open
sebag90 opened this issue Jul 2, 2024 · 0 comments

Comments

@sebag90
Copy link

sebag90 commented Jul 2, 2024

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
@sebag90 sebag90 changed the title ChatPromptBuilder raises the wrong ValueError when receiving incorect argument ChatPromptBuilder raises the misleading ValueError when receiving incorect argument Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant