From 77b4bb894a4579711d05a36e5e58a0c6a80dd143 Mon Sep 17 00:00:00 2001 From: Arjun Bingly Date: Mon, 25 Mar 2024 17:50:54 -0400 Subject: [PATCH] Linting and formatting cookbooks --- projects/Basic-RAG/BasciRAG_CustomPrompt.py | 9 ++++---- projects/Basic-RAG/BasicRAG_FewShotPrompt.py | 23 ++++++++++---------- projects/Basic-RAG/BasicRAG_ingest.py | 4 +++- projects/Basic-RAG/BasicRAG_refine.py | 2 ++ projects/Basic-RAG/BasicRAG_stuff.py | 2 ++ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/projects/Basic-RAG/BasciRAG_CustomPrompt.py b/projects/Basic-RAG/BasciRAG_CustomPrompt.py index 3a3eed9..751a7b1 100644 --- a/projects/Basic-RAG/BasciRAG_CustomPrompt.py +++ b/projects/Basic-RAG/BasciRAG_CustomPrompt.py @@ -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) diff --git a/projects/Basic-RAG/BasicRAG_FewShotPrompt.py b/projects/Basic-RAG/BasicRAG_FewShotPrompt.py index 5fc2d46..a2804e6 100644 --- a/projects/Basic-RAG/BasicRAG_FewShotPrompt.py +++ b/projects/Basic-RAG/BasicRAG_FewShotPrompt.py @@ -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) diff --git a/projects/Basic-RAG/BasicRAG_ingest.py b/projects/Basic-RAG/BasicRAG_ingest.py index b80e6ef..4c3b8a1 100644 --- a/projects/Basic-RAG/BasicRAG_ingest.py +++ b/projects/Basic-RAG/BasicRAG_ingest.py @@ -1,3 +1,5 @@ +"""A cookbook demonstrating how to ingest pdf files for use with Basic RAG.""" + from pathlib import Path from grag.components.multivec_retriever import Retriever @@ -8,7 +10,7 @@ client = DeepLakeClient(collection_name="test") retriever = Retriever(vectordb=client) -dir_path = Path(__file__).parent / 'some_dir' +dir_path = Path(__file__).parent / "some_dir" retriever.ingest(dir_path) # rag = BasicRAG(doc_chain="refine") diff --git a/projects/Basic-RAG/BasicRAG_refine.py b/projects/Basic-RAG/BasicRAG_refine.py index ad8d8e7..f06e821 100644 --- a/projects/Basic-RAG/BasicRAG_refine.py +++ b/projects/Basic-RAG/BasicRAG_refine.py @@ -1,3 +1,5 @@ +"""A cookbook demonstrating how to use Basic RAG with refine chain.""" + from grag.components.multivec_retriever import Retriever from grag.components.vectordb.deeplake_client import DeepLakeClient from grag.rag.basic_rag import BasicRAG diff --git a/projects/Basic-RAG/BasicRAG_stuff.py b/projects/Basic-RAG/BasicRAG_stuff.py index 63edeab..78236e2 100644 --- a/projects/Basic-RAG/BasicRAG_stuff.py +++ b/projects/Basic-RAG/BasicRAG_stuff.py @@ -1,3 +1,5 @@ +"""A cookbook demonstrating how to use custom prompts with Basic RAG.""" + from grag.components.multivec_retriever import Retriever from grag.components.vectordb.deeplake_client import DeepLakeClient from grag.rag.basic_rag import BasicRAG