Find answers from the community

Updated 2 years ago

Would someone be able to give an example

Would someone be able to give an example usage of the RefinePrompt, having trouble constructing the template
Attachment
image.png
j
m
10 comments
@marismaro could you show what the REFINE_PROMPT_TMPL looks like? you don't want to "pre-format" the variables, you want to leave those in as variable templates
Plain Text
# initial query Q&A
query = "list MEP requirements and reference appropriate page numbers" #@param {type:"string"}

response = index.query(query, verbose=True, mode="embedding")


# attempt follow up  Q&A 
existing_answer = response.response
REFINE_PROMPT_TMPL = (
    "Context information is below. \n"
    "---------------------\n"
    "{context_msg}"
    "{existing_answer}"
    "\n---------------------\n"
    "Given the context information and not prior knowledge, "
    "answer the question: {query_str}\n"
)
refine_prompt = RefinePrompt(REFINE_PROMPT_TMPL)

refined_index = GPTPineconeIndex('', pinecone_index=index, llm_predictor=llm_predictor, text_qa_template=refine_prompt)


@jerryjliu0 if that's the case, how does one pass in those template vars? is that part of the general **kwargs?
Thanks @marismaro. First, you want to pass in text_qa_template and refine_template to index.query, not when initializing the index. e.g. something like

Plain Text
text_qa_prompt = QuestionAnswerPrompt(QUESTION_ANSWER_PROMPT_TMPL)
refine_prompt = RefinePrompt(REFINE_PROMPT_TMPL)
index.query(text_qa_template=text_qa_prompt, refine_template=refine_prompt)


Note that you'll have to define a QuestionAnswer prompt as well. See https://gpt-index.readthedocs.io/en/latest/reference/prompts.html for the template vars of QuestionAnswer prompt
@jerryjliu0 Gotcha, when you actually ask the follow up question, do you pass all 3 (query str and both templates) to index.query? Sorry for the ignorance, having some trouble wrapping my head around this
btw you don't need to create two separate indices for the first query and the followup query (unless it was your intention to define indices over separate sources of data)
And every time you want to ask a follow up, do you provide all those params with the next time you call index.query?
Thanks Jerry, I’m guessing it then kind of comes down to an art of crafting good prompt templates?
there's definitely an element of that, yeah. hopefully the need for this goes down in the future as better models come out
Add a reply
Sign up and join the conversation on Discord