Find answers from the community

Updated 8 months ago

How can I print out the intermediate prompts used in TreeSummarizer?

@kapa.ai How can I print out the intermediate prompts used in TreeSummarizer?
k
2 comments
Please stand by @eden as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To print out the intermediate prompts used in TreeSummarizer, you can use the get_prompts method of the query engine. This method returns a dictionary of prompts. You can then display this dictionary using a function like display_prompt_dict.

Here is an example of how you can do this:

Plain Text
# Get the prompts dictionary
prompts_dict = query_engine.get_prompts()

# Define a function to display the prompts
def display_prompt_dict(prompts_dict):
    for k, p in prompts_dict.items():
        text_md = f"**Prompt Key**: {k}<br>" f"**Text:** <br>"
        display(Markdown(text_md))
        print(p.get_template())
        display(Markdown("<br><br>"))

# Use the function to display the prompts
display_prompt_dict(prompts_dict)


Please note that you need to have an instance of the query engine. You can create one like this:

Plain Text
query_engine = index.as_query_engine(response_mode="tree_summarize")


You can find more details in the LlamaIndex documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord