llama-index
109 строк · 3.5 Кб
1"""Prompts for ChatGPT."""
2
3from llama_index.legacy.core.llms.types import ChatMessage, MessageRole4from llama_index.legacy.prompts.base import ChatPromptTemplate5
6# text qa prompt
7TEXT_QA_SYSTEM_PROMPT = ChatMessage(8content=(9"You are an expert Q&A system that is trusted around the world.\n"10"Always answer the query using the provided context information, "11"and not prior knowledge.\n"12"Some rules to follow:\n"13"1. Never directly reference the given context in your answer.\n"14"2. Avoid statements like 'Based on the context, ...' or "15"'The context information ...' or anything along "16"those lines."17),18role=MessageRole.SYSTEM,19)
20
21TEXT_QA_PROMPT_TMPL_MSGS = [22TEXT_QA_SYSTEM_PROMPT,23ChatMessage(24content=(25"Context information is below.\n"26"---------------------\n"27"{context_str}\n"28"---------------------\n"29"Given the context information and not prior knowledge, "30"answer the query.\n"31"Query: {query_str}\n"32"Answer: "33),34role=MessageRole.USER,35),36]
37
38CHAT_TEXT_QA_PROMPT = ChatPromptTemplate(message_templates=TEXT_QA_PROMPT_TMPL_MSGS)39
40# Tree Summarize
41TREE_SUMMARIZE_PROMPT_TMPL_MSGS = [42TEXT_QA_SYSTEM_PROMPT,43ChatMessage(44content=(45"Context information from multiple sources is below.\n"46"---------------------\n"47"{context_str}\n"48"---------------------\n"49"Given the information from multiple sources and not prior knowledge, "50"answer the query.\n"51"Query: {query_str}\n"52"Answer: "53),54role=MessageRole.USER,55),56]
57
58CHAT_TREE_SUMMARIZE_PROMPT = ChatPromptTemplate(59message_templates=TREE_SUMMARIZE_PROMPT_TMPL_MSGS60)
61
62
63# Refine Prompt
64CHAT_REFINE_PROMPT_TMPL_MSGS = [65ChatMessage(66content=(67"You are an expert Q&A system that strictly operates in two modes "68"when refining existing answers:\n"69"1. **Rewrite** an original answer using the new context.\n"70"2. **Repeat** the original answer if the new context isn't useful.\n"71"Never reference the original answer or context directly in your answer.\n"72"When in doubt, just repeat the original answer."73"New Context: {context_msg}\n"74"Query: {query_str}\n"75"Original Answer: {existing_answer}\n"76"New Answer: "77),78role=MessageRole.USER,79)80]
81
82
83CHAT_REFINE_PROMPT = ChatPromptTemplate(message_templates=CHAT_REFINE_PROMPT_TMPL_MSGS)84
85
86# Table Context Refine Prompt
87CHAT_REFINE_TABLE_CONTEXT_TMPL_MSGS = [88ChatMessage(content="{query_str}", role=MessageRole.USER),89ChatMessage(content="{existing_answer}", role=MessageRole.ASSISTANT),90ChatMessage(91content=(92"We have provided a table schema below. "93"---------------------\n"94"{schema}\n"95"---------------------\n"96"We have also provided some context information below. "97"{context_msg}\n"98"---------------------\n"99"Given the context information and the table schema, "100"refine the original answer to better "101"answer the question. "102"If the context isn't useful, return the original answer."103),104role=MessageRole.USER,105),106]
107CHAT_REFINE_TABLE_CONTEXT_PROMPT = ChatPromptTemplate(108message_templates=CHAT_REFINE_TABLE_CONTEXT_TMPL_MSGS109)
110