Files

1 line
11 KiB
JSON

{"repo": "anarlavrenov/ukraine", "files": {"cookbook/rag_cookbook.ipynb": {"74f6134ba9b95e46fc17b5015ea5bd2bcc25acf3": {"t": 1785745462.676807, "n": 4840, "h": "153fa0163a75719c", "c": "{\n \"nbformat\": 4,\n \"nbformat_minor\": 0,\n \"metadata\": {\n \"colab\": {\n \"provenance\": []\n },\n \"kernelspec\": {\n \"name\": \"python3\",\n \"display_name\": \"Python 3\"\n },\n \"language_info\": {\n \"name\": \"python\"\n }\n },\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"source\": [\n \"This notebook showcases `ukraine` library for building SOTA RAG agents. Below are examples of how to use `ukraine` library to build PDF RAG agents using OpenAI, Llama and DeepSeek language models 🐱\"\n ],\n \"metadata\": {\n \"id\": \"u4XA_TZF7VaJ\"\n }\n },\n {\n \"cell_type\": \"markdown\",\n \"source\": [\n \"Let's have a look at how to build RAG agent with `ukraine` library using Llama language model 🦙\"\n ],\n \"metadata\": {\n \"id\": \"GsRlE2SH88sn\"\n }\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"!pip install -U ukraine[langchain_llama]\\n\",\n \"\\n\",\n \"from ukraine.agents.rag import PDFLlamaRAGAgent\\n\",\n \"import os\\n\",\n \"\\n\",\n \"# Make sure to provide your OpenAI API Key for OpenAI embedding model\\n\",\n \"# and NVIDIA API Key for Llama language model\\n\",\n \"os.environ[\\\"OPENAI_API_KEY\\\"] = \\\"OPENAI_API_KEY\\\"\\n\",\n \"os.environ[\\\"NVIDIA_API_KEY\\\"] = \\\"NVIDIA_API_KEY\\\"\"\n ],\n \"metadata\": {\n \"collapsed\": true,\n \"id\": \"EM8C328JCHRl\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"# Please provide the existing path to your pdf file.\\n\",\n \"# The system prompt can be really large and contain complex instructions.\\n\",\n \"# Make sure to include '{context}' brackets at the end.\\n\",\n \"agent = PDFLlamaRAGAgent(\\n\",\n \" file_path=\\\"PATH_TO_PDF\\\",\\n\",\n \" system_prompt=\\\"\\\"\\\"Provide answers based on the document.\\\"{context}\\\"\\\"\\\"\\n\",\n \")\"\n ],\n \"metadata\": {\n \"collapsed\": true,\n \"id\": \"KIWJsR2OIfOJ\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"# Talk to your RAG agent and get results\\n\",\n \"result = agent.chat(\\\"What is this document about?\\\")\\n\",\n \"print(result[\\\"answer\\\"])\"\n ],\n \"metadata\": {\n \"id\": \"ht8PZ0SmU0qM\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"markdown\",\n \"source\": [\n \"RAG with OpenAI ֎\"\n ],\n \"metadata\": {\n \"id\": \"lbKN0gG-86Ic\"\n }\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"!pip install -U ukraine[langchain_openai]\\n\",\n \"\\n\",\n \"from ukraine.agents.rag import PDFOpenAIRAGAgent\\n\",\n \"import os\\n\",\n \"\\n\",\n \"os.environ[\\\"OPENAI_API_KEY\\\"] = \\\"OPENAI_API_KEY\\\"\"\n ],\n \"metadata\": {\n \"id\": \"dhni3Tai-snE\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"agent = PDFOpenAIRAGAgent(\\n\",\n \" file_path=\\\"PATH_TO_PDF\\\",\\n\",\n \" system_prompt=\\\"\\\"\\\"Provide answers based on the document.\\\"{context}\\\"\\\"\\\"\\n\",\n \")\"\n ],\n \"metadata\": {\n \"id\": \"JGJrXkiY_Cha\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"result = agent.chat(\\\"What is this document about?\\\")\\n\",\n \"print(result[\\\"answer\\\"])\"\n ],\n \"metadata\": {\n \"id\": \"EwX7yVm5_E5t\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"markdown\",\n \"source\": [\n \"RAG with DeepSeek 🐋\"\n ],\n \"metadata\": {\n \"id\": \"hqi2yWfE_LKc\"\n }\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"!pip install -U ukraine[langchain_deepseek]\\n\",\n \"\\n\",\n \"from ukraine.agents.rag import PDFDeepSeekRAGAgent\\n\",\n \"import os\\n\",\n \"\\n\",\n \"os.environ[\\\"DEEPSEEK_API_KEY\\\"] = \\\"DEEPSEEK_API_KEY\\\"\"\n ],\n \"metadata\": {\n \"id\": \"vM330SfO_uNX\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"agent = PDFDeepSeekRAGAgent(\\n\",\n \" file_path=\\\"PATH_TO_PDF\\\",\\n\",\n \" system_prompt=\\\"\\\"\\\"Provide answers based on the document.\\\"{context}\\\"\\\"\\\"\\n\",\n \")\"\n ],\n \"metadata\": {\n \"id\": \"9Qr2ll-BCtQJ\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"result = agent.chat(\\\"What is this document about?\\\")\\n\",\n \"print(result[\\\"answer\\\"])\"\n ],\n \"metadata\": {\n \"id\": \"NDOr-QmQCuLy\"\n },\n \"execution_count\": null,\n \"outputs\": []\n }\n ]\n}"}, "2fef31fb7377d8e8a12b3dde69c2aef326445b58": {"t": 1785753544.046189, "n": 4840, "h": "153fa0163a75719c", "c": "{\n \"nbformat\": 4,\n \"nbformat_minor\": 0,\n \"metadata\": {\n \"colab\": {\n \"provenance\": []\n },\n \"kernelspec\": {\n \"name\": \"python3\",\n \"display_name\": \"Python 3\"\n },\n \"language_info\": {\n \"name\": \"python\"\n }\n },\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"source\": [\n \"This notebook showcases `ukraine` library for building SOTA RAG agents. Below are examples of how to use `ukraine` library to build PDF RAG agents using OpenAI, Llama and DeepSeek language models 🐱\"\n ],\n \"metadata\": {\n \"id\": \"u4XA_TZF7VaJ\"\n }\n },\n {\n \"cell_type\": \"markdown\",\n \"source\": [\n \"Let's have a look at how to build RAG agent with `ukraine` library using Llama language model 🦙\"\n ],\n \"metadata\": {\n \"id\": \"GsRlE2SH88sn\"\n }\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"!pip install -U ukraine[langchain_llama]\\n\",\n \"\\n\",\n \"from ukraine.agents.rag import PDFLlamaRAGAgent\\n\",\n \"import os\\n\",\n \"\\n\",\n \"# Make sure to provide your OpenAI API Key for OpenAI embedding model\\n\",\n \"# and NVIDIA API Key for Llama language model\\n\",\n \"os.environ[\\\"OPENAI_API_KEY\\\"] = \\\"OPENAI_API_KEY\\\"\\n\",\n \"os.environ[\\\"NVIDIA_API_KEY\\\"] = \\\"NVIDIA_API_KEY\\\"\"\n ],\n \"metadata\": {\n \"collapsed\": true,\n \"id\": \"EM8C328JCHRl\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"# Please provide the existing path to your pdf file.\\n\",\n \"# The system prompt can be really large and contain complex instructions.\\n\",\n \"# Make sure to include '{context}' brackets at the end.\\n\",\n \"agent = PDFLlamaRAGAgent(\\n\",\n \" file_path=\\\"PATH_TO_PDF\\\",\\n\",\n \" system_prompt=\\\"\\\"\\\"Provide answers based on the document.\\\"{context}\\\"\\\"\\\"\\n\",\n \")\"\n ],\n \"metadata\": {\n \"collapsed\": true,\n \"id\": \"KIWJsR2OIfOJ\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"# Talk to your RAG agent and get results\\n\",\n \"result = agent.chat(\\\"What is this document about?\\\")\\n\",\n \"print(result[\\\"answer\\\"])\"\n ],\n \"metadata\": {\n \"id\": \"ht8PZ0SmU0qM\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"markdown\",\n \"source\": [\n \"RAG with OpenAI ֎\"\n ],\n \"metadata\": {\n \"id\": \"lbKN0gG-86Ic\"\n }\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"!pip install -U ukraine[langchain_openai]\\n\",\n \"\\n\",\n \"from ukraine.agents.rag import PDFOpenAIRAGAgent\\n\",\n \"import os\\n\",\n \"\\n\",\n \"os.environ[\\\"OPENAI_API_KEY\\\"] = \\\"OPENAI_API_KEY\\\"\"\n ],\n \"metadata\": {\n \"id\": \"dhni3Tai-snE\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"agent = PDFOpenAIRAGAgent(\\n\",\n \" file_path=\\\"PATH_TO_PDF\\\",\\n\",\n \" system_prompt=\\\"\\\"\\\"Provide answers based on the document.\\\"{context}\\\"\\\"\\\"\\n\",\n \")\"\n ],\n \"metadata\": {\n \"id\": \"JGJrXkiY_Cha\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"result = agent.chat(\\\"What is this document about?\\\")\\n\",\n \"print(result[\\\"answer\\\"])\"\n ],\n \"metadata\": {\n \"id\": \"EwX7yVm5_E5t\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"markdown\",\n \"source\": [\n \"RAG with DeepSeek 🐋\"\n ],\n \"metadata\": {\n \"id\": \"hqi2yWfE_LKc\"\n }\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"!pip install -U ukraine[langchain_deepseek]\\n\",\n \"\\n\",\n \"from ukraine.agents.rag import PDFDeepSeekRAGAgent\\n\",\n \"import os\\n\",\n \"\\n\",\n \"os.environ[\\\"DEEPSEEK_API_KEY\\\"] = \\\"DEEPSEEK_API_KEY\\\"\"\n ],\n \"metadata\": {\n \"id\": \"vM330SfO_uNX\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"agent = PDFDeepSeekRAGAgent(\\n\",\n \" file_path=\\\"PATH_TO_PDF\\\",\\n\",\n \" system_prompt=\\\"\\\"\\\"Provide answers based on the document.\\\"{context}\\\"\\\"\\\"\\n\",\n \")\"\n ],\n \"metadata\": {\n \"id\": \"9Qr2ll-BCtQJ\"\n },\n \"execution_count\": null,\n \"outputs\": []\n },\n {\n \"cell_type\": \"code\",\n \"source\": [\n \"result = agent.chat(\\\"What is this document about?\\\")\\n\",\n \"print(result[\\\"answer\\\"])\"\n ],\n \"metadata\": {\n \"id\": \"NDOr-QmQCuLy\"\n },\n \"execution_count\": null,\n \"outputs\": []\n }\n ]\n}"}}}}