Find answers from the community

Updated 3 months ago

how to set qa_template for chat engine

how to set qa_template for chat engine
k
L
t
7 comments
Please stand by @tugay as I search the knowledge base. We are experiencing especially high traffic right now and might take longer than usual. :wave:
----------------------
To set a custom QA template for a chat engine in LlamaIndex, you need to define a custom prompt and pass it as an argument when creating the chat engine. However, the extracts provided do not contain specific examples of setting a QA template for a chat engine. They do contain examples of setting a QA template for a query engine, which might be similar.

Here is an example of how to set a custom QA template for a query engine:

Plain Text
from llama_index import Prompt, VectorStoreIndex, SimpleDirectoryReader

# load documents
documents = SimpleDirectoryReader('data').load_data()

# define custom Prompt
TEMPLATE_STR = (
    "We have provided context information below. \n"
    "---------------------\n"
    "{context_str}"
    "\n---------------------\n"
    "Given this information, please answer the question: {query_str}\n"
)
QA_TEMPLATE = Prompt(TEMPLATE_STR)

# Build index 
index = VectorStoreIndex.from_documents(documents)

# Configure query engine
query_engine = index.as_query_engine(text_qa_template=QA_TEMPLATE)

# Execute query
response = query_engine.query("What did the author do growing up?")
print(response)

(Source: Custom Prompts ())

For a chat engine, the process might be similar, but the exact method to set a QA template for a chat engine is not specified in the provided extracts. For more detailed information, you may want to refer to the LlamaIndex documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
You can just pass it in as a kwarg

index.as_chat_engine(text_qa_template=text_qa_template)

Keep in mind this is only applied to the underlying query engine, not the agent itself (its default to use an agent with a tool, unless you are changing chat_mode)
@Logan M , i feel kind of embarrased to use your help in every single thing. Thank you very much
Hahaha no worries
I get paid to do it, don't worry πŸ˜„
That's great, I feel relieved
Add a reply
Sign up and join the conversation on Discord