-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation for prompts in llm-app (#8122)
Co-authored-by: berkecanrizai <[email protected]> GitOrigin-RevId: ab7fbe4630186340c8900a6b248028fbd0c5eedc
- Loading branch information
1 parent
0321f11
commit aff4ee1
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: 'Customizing prompt' | ||
description: 'Guide to customizing prompt in the RAG templates' | ||
navigation: true | ||
heading: false | ||
--- | ||
|
||
# Customizing prompts in RAG templates | ||
|
||
In the RAG templates, you can customize the LLM Q&A prompt directly in the YAML configuration file. You just need to set the `prompt_template` argument for the `BaseRAGQuestionAnswerer`. | ||
|
||
Using [`demo-question-answering`](https://github.com/pathwaycom/llm-app/tree/main/examples/pipelines/demo-question-answering) as an example, let's see how to customize the prompt. | ||
By default, the `BaseRAGQuestionAnswerer` in the [`app.yaml`](https://github.com/pathwaycom/llm-app/blob/main/examples/pipelines/demo-question-answering/app.yaml) is initialized with: | ||
|
||
```yaml | ||
question_answerer: !pw.xpacks.llm.question_answering.BaseRAGQuestionAnswerer | ||
llm: $llm | ||
indexer: $document_store | ||
``` | ||
Set the `prompt_template` to be the prompt you want to use. Your prompt needs to contain two placeholders: `"{query}"` and `"{context}"` – `"{query}"` will be replaced with the question being asked, whereas `"{context}"` will be replaced with the list of context documents. | ||
|
||
```yaml | ||
question_answerer: !pw.xpacks.llm.question_answering.BaseRAGQuestionAnswerer | ||
llm: $llm | ||
indexer: $document_store | ||
prompt_template: "Given these documents: {context}, please answer the question: {query}" | ||
``` | ||
|
||
If you plan to use a longer prompt, it may be more convenient to use a multiline string and store it in a variable (the syntax for variables is described in https://pathway.com/developers/ai-pipelines/configure-yaml). | ||
|
||
```yaml | ||
$prompt_template: | | ||
Answer the question based on the given documents. | ||
If you can't find the answer in the documents, say that you don't know. | ||
Context documents: {context} | ||
Question: {query} | ||
Your answer: | ||
question_answerer: !pw.xpacks.llm.question_answering.BaseRAGQuestionAnswerer | ||
llm: $llm | ||
indexer: $document_store | ||
prompt_template: $prompt_template | ||
``` |