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

[Question]: how to get RetrieverQueryEngine full prompt #17608

Open
1 task done
whoo9112 opened this issue Jan 24, 2025 · 2 comments
Open
1 task done

[Question]: how to get RetrieverQueryEngine full prompt #17608

whoo9112 opened this issue Jan 24, 2025 · 2 comments
Labels
question Further information is requested

Comments

@whoo9112
Copy link

Question Validation

  • I have searched both the documentation and discord for an answer.

Question

When using RetrieverQueryEngine, can you check how the Retriever results I extracted are applied to the prompt and delivered to LLM?

For example
"""
you are helpful assistant
{context_str}

{query_str}
"""

I'd like to check the full prompt with {context_str}, {query_str} completely filled.

@whoo9112 whoo9112 added the question Further information is requested label Jan 24, 2025
Copy link

dosubot bot commented Jan 24, 2025

To view the full prompt with {context_str} and {query_str} completely filled when using RetrieverQueryEngine, you can use the get_prompts method to access the set of prompts used by the query engine, including those in sub-modules. This allows you to see how the context_str and query_str are applied in the prompt templates. Here's how you can do it:

  1. Access Prompts: Use the get_prompts method on your query engine to retrieve all the prompts, including those used in nested modules.

    prompts_dict = query_engine.get_prompts()
  2. Display Prompts: Define a function to display the prompts in a readable format.

    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>"))
  3. View Filled Prompts: Call the display function to see the prompts with {context_str} and {query_str} filled in.

    display_prompt_dict(prompts_dict)

This approach allows you to centralize and view the prompts used by the RetrieverQueryEngine, providing insight into how the retriever results are formatted and delivered to the LLM [1][2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@whoo9112
Copy link
Author

To view the full prompt with {context_str} and {query_str} completely filled when using RetrieverQueryEngine, you can use the get_prompts method to access the set of prompts used by the query engine, including those in sub-modules. This allows you to see how the context_str and query_str are applied in the prompt templates. Here's how you can do it:

  1. Access Prompts: Use the get_prompts method on your query engine to retrieve all the prompts, including those used in nested modules.
    prompts_dict = query_engine.get_prompts()
  2. Display Prompts: Define a function to display the prompts in a readable format.
    def display_prompt_dict(prompts_dict):
    for k, p in prompts_dict.items():
    text_md = f"Prompt Key: {k}
    " f"Text:
    "
    display(Markdown(text_md))
    print(p.get_template())
    display(Markdown("

    "))
  3. View Filled Prompts: Call the display function to see the prompts with {context_str} and {query_str} filled in.
    display_prompt_dict(prompts_dict)

This approach allows you to centralize and view the prompts used by the RetrieverQueryEngine, providing insight into how the retriever results are formatted and delivered to the LLM [1][2].

To continue talking to Dosu, mention @dosu.

Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Dosubot always gives me different answers than I want.. it's awful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant