-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
24 additions
and
16 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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
"""A cookbook demonstrating how to use Basic RAG with stuff chain.""" | ||
|
||
from grag.components.prompt import Prompt | ||
from grag.rag.basic_rag import BasicRAG | ||
|
||
custom_prompt = Prompt( | ||
input_keys={"context", "question"}, | ||
template='''Answer the following question based on the given context. | ||
template="""Answer the following question based on the given context. | ||
question: {question} | ||
context: {context} | ||
answer: | ||
''' | ||
""", | ||
) | ||
rag = BasicRAG(doc_chain="stuff", | ||
custom_prompt=custom_prompt) | ||
rag = BasicRAG(doc_chain="stuff", custom_prompt=custom_prompt) |
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 |
---|---|---|
@@ -1,29 +1,30 @@ | ||
"""A cookbook demonstrating how to use custom few-shot prompts with Basic RAG.""" | ||
|
||
from grag.components.prompt import FewShotPrompt | ||
from grag.rag.basic_rag import BasicRAG | ||
|
||
custom_few_shot_prompt = FewShotPrompt( | ||
input_keys={"context", "question"}, | ||
output_keys={"answer"}, | ||
example_template=''' | ||
example_template=""" | ||
question: {question} | ||
answer: {answer} | ||
''', | ||
prefix='''Answer the following question based on the given context like examples given below:''', | ||
suffix='''Answer the following question based on the given context | ||
""", | ||
prefix="""Answer the following question based on the given context like examples given below:""", | ||
suffix="""Answer the following question based on the given context | ||
question: {question} | ||
context: {context} | ||
answer: | ||
''', | ||
""", | ||
examples=[ | ||
{ | ||
"question": "What is the name of largest planet?", | ||
"answer": "Jupiter is the largest planet." | ||
"answer": "Jupiter is the largest planet.", | ||
}, | ||
{ | ||
"question": "Who came up with Convolutional Neural Networks?", | ||
"answer": "Yann LeCun introduced convolutional neural networks." | ||
} | ||
] | ||
"answer": "Yann LeCun introduced convolutional neural networks.", | ||
}, | ||
], | ||
) | ||
rag = BasicRAG(doc_chain="stuff", | ||
custom_prompt=custom_few_shot_prompt) | ||
rag = BasicRAG(doc_chain="stuff", custom_prompt=custom_few_shot_prompt) |
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
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
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