Ollama Python Library Released! How to implement Ollama RAG?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is amazing now we have Python and JavaScript libraries for olama we are able to integrate o in our python application and JavaScript application using just few lines of code we are able to create rag application using olama mistal Lang chain and chroma DB the entered URL will get converted to embeddings then it can be fed into ol llama we'll be using chroma DB to store embeddings and mral to run ol Lama that's exactly what we're going to see today let's get [Music] started hi everyone I'm really excited to show you how to use olama using python own package Implement olama Rag and also create a user interface like this I'm going to take you through step by step on how to do this but before that I regularly create videos in regards to Artificial Intelligence on my YouTube channel so do subscribe click the Bell icon to stay tuned make sure you click the like button so this video can be helpful for many others like you first create virtual environments using cond Create hyphen ol Lama Python 3.11 and then activate the virtual environment then pip install ol Lama that installs the ol llama package now let's create a file call app.py and then let's open it first import olama next we are going to use ol. chat function and use myal model streaming equals true and we are passing a message message says why is the sky blue then we going to print out the results by using the full loop like this now I'm going to run this code in your terminal make sure you have downloaded mistl using olama run mistal if you haven't downloaded olama make sure you go to olama website and download it from here you have mac Co and Linux version once after you've downloaded mistol now I'm going to run Python app.py and then click enter now I can see the response is getting printed you are running mistra locally using ola python package just a quick overview on how to run a multimodel using AMA just import AMA then with open then provide the image as file then again use ol. chat I'm going to use lava model then I'm going to ask what is in this image and finally print out the response this is the image I'm going to use it is on my same folder now I'm going to run this code in your terminal make sure you downloaded lava 2 using oama run lava now you can run python multimodal dopy that's where my code got saved and here is the response it was able to read the image and able to describe what is in the image in this image there is a man playing Cricket on the field and it giving more information just want to quickly go through the list of features in ol python package you can use ol. chats ol. generate it is same as chat which is going to generate the response we have ol list to list the the total number of available models AMA show then you can customize your own lar language model using the model file which we can use ol. create to create your own version of L language model you are able to copy using. copy delete using. delete pull a image using ol. pull push the image using. push and create embeddings using. embeddings that's a quick overview now we're going to see how we can create olama rag using olama mistal Lang chain and chroma DB let's create a file called rag. py and then let's open it first we going to import olama then import beautiful soup then recursive character text Splitter from Lang chain web base loader chroma DB ol embeddings string output parser runable pass through now I'm going to use loader to load a web URL which is this URL this is the content of the page and it is running in Local Host as you can see here just for testing purpose so this function is going to load the content from this URL as you can see here first we are going to use a URL to load the content and that content will be converted to embeddings so the second step is converting to embeddings and the third step is passing that to ol now we going to load the data which is copied from this URL using beautiful soup next we're going to split the text into chunks next we're going to use split documents to split the documents here in text splitter we are initializing here we are actually splitting the data now the Second Step which is creating embeddings and storing in Vector store we are going to use olama embeddings model name is mral and then we are using chroma DB chroma do from documents we're going to pause the divided documents and also the embeddings now we going to create the retriever it's just initializing the retriever retriever to retrieve the data next we are using format documents this used to merge all the retrieve documents before sending it to lar language model so that this can be used as a context now the third step is to define the olama llm function this will automatically get the question and the context then it will pass it to the olama chat which we have just seen before the formatted prompt is also used as the content from the user so we are sending both question and context to the large language model mral and it'll respond accordingly now we're going to put all these things together that is called rag so we going to define the rack chain create a function called rack chain function you provide the question this is where the retriever do inor function will convert the question into embeddings and it will search the chroma DB if any information related to the question provider then we are formatting the documents that is combining all the documents then we are sending the that to the olama llm function now we're going to run the rack chain ask a question what is Task decomposition and print the result information about task decomposition is present in the URL which I've just shown which you can see here as a quick summary we loaded the document from the URL and split those document secondly we converted those document into embeddings and stored in the vector store third we are pausing the question and the context to the language model using ol. chat this is completely running locally on your computer and it's completely private this can even run without internet even the URL which we are using is Local Host now I'm going to run this code in your terminal make sure you install L chain beautiful soup chroma DB and gradio using pip install after that python R.P and then click enter now this is going to the URL fetching the data converting that to embeddings storing that in embeddings then finally you're querying based on the question and here is the final response it's about task decomposition as simple as that now you are able to create your own rack using ol running locally on your computer just as a final step I've added gradio into the mix converted everything to the function such as load and retrieve documents rack chain then finally passing the rack chain function into the gr. interface and we are launching that this is a slightly formatted version to create a user interface now I'm going to run this code in your terminal python UI dopy and then click enter and now there's a URL here I'm going to open it this is the user interface I'm going to enter a URL from my website and going to ask open interpreter use cases and then click submit now it's processing this is the URL it's going to browse and give us the information based on this data and here is the information in the context provider here are some additional use cases of open interpreter and it's giving us more information similarly you are able to to enter any URL and ask questions based on that you might need to fine-tune the code for much better results this is a quick beginner guide I'm going to create more videos similar to this so stay tuned I hope you like this video do like share and subscribe and thanks for watching
Info
Channel: Mervin Praison
Views: 22,957
Rating: undefined out of 5
Keywords:
Id: 4HfSfFvLn9Q
Channel Id: undefined
Length: 8min 15sec (495 seconds)
Published: Fri Jan 26 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.