Ollama meets LangChain
Key Takeaways
This video demonstrates how to use Ollama models with LangChain to perform various tasks, including loading models, creating prompt templates, and scraping data from websites.
Full Transcript
okay so in this video I want to go through how having olama models running on your computer locally allows you to run Lang chain locally and use those models to do different tasks so I'm just going to look at some simple tasks like how we set it up and stuff like that and then finally I'll finish up with a task where we're going to get it to go and do some scraping for us and extract some information all using the Lama 2 model okay so in here uh we can see if I come down I'm just using vs code here and I've just got a couple of python files open I've made a condor environment just to install Lang chain there's nothing special about that there you can certainly set that up or just use your local python if you really wanted to so if I come into the terminal I can just come and have a look at what we've got going here I can see the models that I've got going in there I've got my Hogwarts model from before I've got the Llama 2 models and I've got some other models which I'll show you in the next video setting those up so first off let's look at just the most simplest thing how do we actually load the model so in this case we're going to use the pre-made llm in Lang chain for Al and we can just set that up with a streaming coreback for this and then we just instantiate our llm pass in the model that we want in this case I'm using llama 2 and then pass in a streaming call back now I can just call the model locally from my python code here okay so now I run the code and you'll see sure enough it's basically triggering the Alama model so it's doing this via an API so actually one of the things I didn't cover in the first video is that alur is running an API that we can actually trigger both with uh L chain but we could also do it with just a standard user interface Etc so that's something that perhaps I'll look at in the future is building a nextjs app with Lang chain and Al llama there all right so the next step up is I'm just going to make a basic change here so I've got the same things from before don't forget this is an LM so I can add in temperature I can add in Max tokens I can add in things like that if I wanted to here what I am going to do is just make a simple prompt template so just give me five interesting facts about and then I'm going to insert that in here so I could say rather than Roman Empire go for the moon so okay you can see that we're going to set up our chain we're just going to pass in the Run CH and print it out as we go in so in here we can also pass in you know ver both equals true or not if we want to see the streaming out of this okay so in this case I'm going to turn off the Callback manager so we're not going to run that and I'm going to turn verose to be false and now if I run it you'll see that it takes a bit of time because it's actually running and getting the data but sure enough once it's finished it will actually just print the data out so this is probably more useful if we wanted to write something to a file file Etc we can see there that it's gone and done it and we've got the five interesting facts about the moon and it's gone around and gotten those quite nicely all right let's look at the last example so this is definitely a bit of a jump from the previous two examples so now we're going to be doing some rag and we're going to do it using a web based loader so we're going to load a web page in we're going to run that and split that up we're going to put that in a chroma DB so you'll need to have chroma in installed for this and we're going to also use an ARG pass to actually pass in a URL that we wanted to get back some data so let's have a look at the Imports here we can see that okay we're bringing in recursive text splitter we're bringing in the web page loader with webbased loader we're bringing in chroma and then we've got some embeddings here so I haven't looked into it too much but apparently Alama seems to according to Lang chain has its own embeddings GPD for all has also made some quantized embeddings that you could use in here for this we can see we're bringing in oama like normal so we're going to just have our main function which is going to just pass through looking for the argument URL we're then going to load that URL we're then going to split that URL we're then going to put it into chroma we're then going to split that data up and we're going to then put it into a chroma DB here then after that we're going to set up our Lang chain prompt so here is the The Prompt that we're using we're pulling it in from Lang chain Hub here and you can simply print this out and have a look at it and play with it yourself and and change it and then we're setting up the retrieval QA chain where we're just going to pass in the llm we're going to pass in our Vector store which is chroma going to pass in our prompt here and then I'm just going to ask her to set up a question question what are the latest headlines on and then I'm going to pass it this in and get the results out here watch them Stream So to set this up when I actually run the file this time I need to pass in an argument called URL I'm going to pass in Tech crunch in here and that's going to kickart everything off so that we can see that okay it's filtered out the tech crunch it's loaded some documents it's loaded the Llama 2 model and now we're going to see that it's just going to basically go through and give us the headlines from there so if we look at Tech crunch we can see that these are the headlines that it's gotten out so I haven't have to write any passing code to do this the language model has done this itself and you could imagine that we could have lots of little tasks like this where we could just send it off with a Cron job or something during the day to bring back information and save it for us on our local drive and you can see here that it's managed to get those top stories and list them out now interestingly sometimes it will list out five sometimes it will list out 10 I didn't put anything in there about that but you could certainly play with that yourself so this gives you an example of just using Lang chain to do simple tasks with a local llm that you could do a variety of different tasks for this if people are interested we could look at setting up a full local rag system for documents and stuff like that using this model certainly the Llama models are pretty decent at being able to get through this and you can run chroma locally etc for this anyway as always if you found the video useful please click like and if you've got any questions please put them in the comments below I will talk to you in the next video bye for now
Original Description
Site: https://www.ollama.ai/
For more tutorials on using LLMs and building Agents, check out my Patreon:
Patreon: https://www.patreon.com/SamWitteveen
Twitter: https://twitter.com/Sam_Witteveen
My Links:
Linkedin: https://www.linkedin.com/in/samwitteveen/
Github:
https://github.com/samwit/langchain-tutorials (updated)
https://github.com/samwit/llm-tutorials
00:00 Intro
01:02 How to load Ollama model locally?
01:57 Basic Chain
03:10 Rag example
#ollama #langchain
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Sam Witteveen · Sam Witteveen · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
LangChain Basics Tutorial #1 - LLMs & PromptTemplates with Colab
Sam Witteveen
LangChain Basics Tutorial #2 Tools and Chains
Sam Witteveen
ChatGPT API Announcement & Code Walkthrough with LangChain
Sam Witteveen
Trying Out Flan 20B with UL2 - Working in Colab with 8Bit Inference
Sam Witteveen
LangChain - Conversations with Memory (explanation & code walkthrough)
Sam Witteveen
LangChain Chat with Flan20B
Sam Witteveen
LangChain - Using Hugging Face Models locally (code walkthrough)
Sam Witteveen
PAL : Program-aided Language Models with LangChain code
Sam Witteveen
Building a Summarization System with LangChain and GPT-3 - Part 1
Sam Witteveen
Building a Summarization System with LangChain and GPT-3 - Part 2
Sam Witteveen
Microsoft's Visual ChatGPT using LangChain
Sam Witteveen
Building a Summarization System with LangChain - Part 3 Using ChatGPT Turbo
Sam Witteveen
LangChain Agents - Joining Tools and Chains with Decisions
Sam Witteveen
Investigating Alpaca 7B - Finetuned LLaMa LLM
Sam Witteveen
Comparing LLMs with LangChain
Sam Witteveen
Running Alpaca7B in Colab
Sam Witteveen
How to finetune your own Alpaca 7B
Sam Witteveen
How to make a custom dataset like Alpaca7B
Sam Witteveen
Understanding Constitutional AI - the paper and key concepts
Sam Witteveen
Using Constitutional AI in LangChain
Sam Witteveen
Talking to Alpaca with LangChain - Creating an Alpaca Chatbot
Sam Witteveen
Text-to-video-synthesis with Diffusers and Colab
Sam Witteveen
Meet Dolly the new Alpaca model
Sam Witteveen
Checking out the Cerebras-GPT family of models
Sam Witteveen
A Step-by-Step Guide to Fine-Tuning Your Dolly Model (tutorial)
Sam Witteveen
Is GPT4All your new personal ChatGPT?
Sam Witteveen
Raven - RWKV-7B RNN's LLM Strikes Back
Sam Witteveen
Talk to your CSV & Excel with LangChain
Sam Witteveen
Vicuna - 90% of ChatGPT quality by using a new dataset?
Sam Witteveen
Koala Revealed: The ChatGPT Alternative You Need to Know! 🔍
Sam Witteveen
Running Koala for free in Colab. Your own personal ChatGPT? (tutorial)
Sam Witteveen
BabyAGI: Discover the Power of Task-Driven Autonomous Agents!
Sam Witteveen
Auto-GPT - How to Automate a Task Based AI with GPT-4
Sam Witteveen
Improve your BabyAGI with LangChain
Sam Witteveen
Generative Agents - Deep Dive and GPT-4 Recreation
Sam Witteveen
GPT4ALLv2: The Improvements and Drawbacks You Need to Know!
Sam Witteveen
Dolly 2.0 by Databricks: Open for Business but is it Ready to Impress!
Sam Witteveen
Red Pajama - Operation: Freeing LLaMA
Sam Witteveen
Investigating Open Assistant - Models, Datasets and Addons
Sam Witteveen
Investigating MiniGPT-4 - The Secret behind GPT-V?
Sam Witteveen
Stable LM 3B - The new tiny kid on the block.
Sam Witteveen
Bard can now code and put that code in Colab for you.
Sam Witteveen
Checking out Bark: a Text to Speech system by Suno AI
Sam Witteveen
Fine-tuning LLMs with PEFT and LoRA
Sam Witteveen
Master PDF Chat with LangChain - Your essential guide to queries on documents
Sam Witteveen
Using LangChain with DuckDuckGO Wikipedia & PythonREPL Tools
Sam Witteveen
Building Custom Tools and Agents with LangChain (gpt-3.5-turbo)
Sam Witteveen
StableVicuna: The New King of Open ChatGPTs?
Sam Witteveen
WizardLM: Evolving Instruction Datasets to Create a Better Model
Sam Witteveen
LaMini-LM - Mini Models Maxi Data!
Sam Witteveen
Finding the Best Free ChatGPT
Sam Witteveen
MPT-7B - The First Commercially Usable Fully Trained LLaMA Style Model
Sam Witteveen
LangChain Retrieval QA Over Multiple Files with ChromaDB
Sam Witteveen
LangChain Retrieval QA with Instructor Embeddings & ChromaDB for PDFs
Sam Witteveen
LangChain + Retrieval Local LLMs for Retrieval QA - No OpenAI!!!
Sam Witteveen
Transformers Agent - Is this Hugging Face's LangChain Competitor?
Sam Witteveen
StarCoder - The LLM to make you a coding star?
Sam Witteveen
Testing Starcoder for Reasoning with PAL
Sam Witteveen
The New Wizards - Unfiltered & Unaligned
Sam Witteveen
Camel + LangChain for Synthetic Data & Market Research
Sam Witteveen
More on: LLM Foundations
View skill →Related Reads
Chapters (4)
Intro
1:02
How to load Ollama model locally?
1:57
Basic Chain
3:10
Rag example
🎓
Tutor Explanation
DeepCamp AI