Find answers from the community

Updated 2 years ago

Refine template

Plain Text
# Refine Prompt
CHAT_REFINE_PROMPT_TMPL_MSGS = [
    HumanMessagePromptTemplate.from_template("{query_str}"),
    AIMessagePromptTemplate.from_template("{existing_answer}"),
    HumanMessagePromptTemplate.from_template(
        "We have the opportunity to refine the above answer "
        "(only if needed) with some more context below.\n"
        "------------\n"
        "{context_msg}\n"
        "------------\n"
        "Given the new context, refine the original answer to better "
        "answer the question. "
        "If the context isn't useful, output the original answer again.",
    ),
]

this is my refine template
Plain Text
# define query configs for graph 
    query_configs = [
        {
            "index_struct_type": "simple_dict",
            "query_mode": "default",
            "query_kwargs": {
                "similarity_top_k": 1,
                "include_summary": True,
                "refine_template": CHAT_REFINE_PROMPT_TMPL_MSGS
            },
            "query_transform": decompose_transform
        },
        {
            "index_struct_type": "list",
            "query_mode": "default",
            "query_kwargs": {
                "response_mode": "tree_summarize",
                "verbose": True,
                "refine_template": CHAT_REFINE_PROMPT_TMPL_MSGS
            }
        },
    ]

this is my query_configs

However, when I run response = graph.query(q, query_configs=query_configs), I got error
Plain Text
line 117, in refine_response_single
    refine_template = self.refine_template.partial_format(
AttributeError: 'list' object has no attribute 'partial_format'
L
J
2 comments
Aha, I think you missed a few steps with the refine template.

There's two more things you need to do, check out lines 28 and 29 here

https://github.com/jerryjliu/llama_index/blob/main/gpt_index/prompts/chat_prompts.py#L28
Thanks. I'll have a try.
Add a reply
Sign up and join the conversation on Discord