Find answers from the community

Updated 2 years ago

I haven t really had time yet do you

I haven't really had time yet, do you know the command for changing the prompt with gpt index?
L
T
3 comments
It's a little different for each index and types of queries, but here's a little example using a vector index (just from a quick failed experiment I did haha these prompts aren't useful)

Plain Text
query_prompt_template = (
    "The following is text from an invoice, captured by OCR, where each word is followed by its XY position on the page.\n"
    "---------------------\n"
    "{context_str}"
    "\n---------------------\n"
    "Given this information and not prior knowledge, "
    "answer the following question: {query_str}\n"
)
query_prompt_template = QuestionAnswerPrompt(query_prompt_template)

query_refine_propmt_template = (
    "The original question is as follows: {query_str}\n"
    "We have provided an existing answer: {existing_answer}\n"
    "We have the opportunity to refine the existing answer"
    "(only if needed) with more text captured by OCR. Each word is followed by it's XY position on the page.\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, return the original answer."
)
query_refine_propmt_template = RefinePrompt(query_refine_propmt_template)

response = index.query(query_text, similarity_top_k=5, text_qa_template=query_prompt_template, refine_template=query_refine_propmt_template)
Alright thx, so is this for the new Chat API?
This process should work for the new Chat API yea. I'm just overriding the default prompts that are defined in https://github.com/jerryjliu/gpt_index/blob/main/gpt_index/prompts/default_prompts.py
Add a reply
Sign up and join the conversation on Discord