Skip to content

Commit

Permalink
Linting and formatting cookbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
arjbingly committed Mar 25, 2024
1 parent ee884c7 commit 77b4bb8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
9 changes: 5 additions & 4 deletions projects/Basic-RAG/BasciRAG_CustomPrompt.py
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)
23 changes: 12 additions & 11 deletions projects/Basic-RAG/BasicRAG_FewShotPrompt.py
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)
4 changes: 3 additions & 1 deletion projects/Basic-RAG/BasicRAG_ingest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
2 changes: 2 additions & 0 deletions projects/Basic-RAG/BasicRAG_refine.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions projects/Basic-RAG/BasicRAG_stuff.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 77b4bb8

Please sign in to comment.