.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Basic-RAG/BasicRAG_FewShotPrompt.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_Basic-RAG_BasicRAG_FewShotPrompt.py: Custom Few-Shot Prompts ============================ This cookbook demonstrates how to use custom few-shot prompts with Basic RAG. `Note that this cookbook assumes that you already have the` ``Llama-2-13b-chat`` `LLM ready, ` `for more details on how to quantize and run an LLM locally, ` `refer to the LLM section under Getting Started.` `Note that this cookbook also assumes that you have already ingested documents into a DeepLake collection called 'grag'` `for more details on how to ingest documents refer to the cookbook called` ``Document Ingestion``. .. GENERATED FROM PYTHON SOURCE LINES 12-55 .. code-block:: Python from grag.components.multivec_retriever import Retriever from grag.components.prompt import FewShotPrompt from grag.components.vectordb.deeplake_client import DeepLakeClient from grag.rag.basic_rag import BasicRAG custom_few_shot_prompt = FewShotPrompt( input_keys={"context", "question"}, output_keys={"answer"}, 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 question: {question} context: {context} answer: """, examples=[ { "question": "What is the name of largest planet?", "answer": "Jupiter is the largest planet.", }, { "question": "Who came up with Convolutional Neural Networks?", "answer": "Yann LeCun introduced convolutional neural networks.", }, ], ) client = DeepLakeClient(collection_name="grag") retriever = Retriever(vectordb=client) rag = BasicRAG( model_name="Llama-2-13b-chat", custom_prompt=custom_few_shot_prompt, retriever=retriever, ) if __name__ == "__main__": while True: query = input("Query:") rag(query) .. _sphx_glr_download_auto_examples_Basic-RAG_BasicRAG_FewShotPrompt.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: BasicRAG_FewShotPrompt.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: BasicRAG_FewShotPrompt.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_