ChatPromptBuilder

Use ChatPromptBuilder to send a prompt to a ChatGenerator.

Basic Information

For detailed overview, inputs and outputs, see Haystack documentation.

Usage Example

ChatPromptBuilder sends the instructions to a ChatGenerator in the form of a list of ChatMessage objects. You pass the instructions in the template parameter, which must follow the ChatMessage format:

- _content: 
	- content_type: content # supported content types are: text, tool_call, tool_call_result
  # content may contain variables
  _role: role # supported roles are: user, system, assistant, tool

For example:

- _content:
    - text: |
        You are a helpful assistant answering the user's questions.
        If the answer is not in the documents, rely on the web_search tool to find information.
        Do not use your own knowledge.
  _role: system
- _content:
    - text: |
        Question: {{ query }}
  _role: user

You could also pass documents in the prompt, like this:

- _content:
    - text: |
        Here are the results that your last search yielded.
        {% for doc in documents %}
        {{doc.content}}
        {% endfor %}
        
        Question: {{ query }}
  _role: user