Ollama meets LangChain

Sam Witteveen · Beginner ·🧠 Large Language Models ·2y ago

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 LangChain Basics Tutorial #1 - LLMs & PromptTemplates with Colab
LangChain Basics Tutorial #1 - LLMs & PromptTemplates with Colab
Sam Witteveen
2 LangChain Basics Tutorial #2 Tools and Chains
LangChain Basics Tutorial #2 Tools and Chains
Sam Witteveen
3 ChatGPT API Announcement & Code Walkthrough with LangChain
ChatGPT API Announcement & Code Walkthrough with LangChain
Sam Witteveen
4 Trying Out Flan 20B with UL2 - Working in Colab with 8Bit Inference
Trying Out Flan 20B with UL2 - Working in Colab with 8Bit Inference
Sam Witteveen
5 LangChain - Conversations with Memory (explanation & code walkthrough)
LangChain - Conversations with Memory (explanation & code walkthrough)
Sam Witteveen
6 LangChain Chat with Flan20B
LangChain Chat with Flan20B
Sam Witteveen
7 LangChain - Using Hugging Face Models locally (code walkthrough)
LangChain - Using Hugging Face Models locally (code walkthrough)
Sam Witteveen
8 PAL : Program-aided Language Models with LangChain code
PAL : Program-aided Language Models with LangChain code
Sam Witteveen
9 Building a Summarization System with LangChain and GPT-3 - Part 1
Building a Summarization System with LangChain and GPT-3 - Part 1
Sam Witteveen
10 Building a Summarization System with LangChain and GPT-3 - Part 2
Building a Summarization System with LangChain and GPT-3 - Part 2
Sam Witteveen
11 Microsoft's Visual ChatGPT using LangChain
Microsoft's Visual ChatGPT using LangChain
Sam Witteveen
12 Building a Summarization System with LangChain - Part 3 Using ChatGPT Turbo
Building a Summarization System with LangChain - Part 3 Using ChatGPT Turbo
Sam Witteveen
13 LangChain Agents - Joining Tools and Chains with Decisions
LangChain Agents - Joining Tools and Chains with Decisions
Sam Witteveen
14 Investigating Alpaca 7B - Finetuned LLaMa LLM
Investigating Alpaca 7B - Finetuned LLaMa LLM
Sam Witteveen
15 Comparing LLMs with LangChain
Comparing LLMs with LangChain
Sam Witteveen
16 Running Alpaca7B in Colab
Running Alpaca7B in Colab
Sam Witteveen
17 How to finetune your own Alpaca 7B
How to finetune your own Alpaca 7B
Sam Witteveen
18 How to make a custom dataset like Alpaca7B
How to make a custom dataset like Alpaca7B
Sam Witteveen
19 Understanding Constitutional AI - the paper and key concepts
Understanding Constitutional AI - the paper and key concepts
Sam Witteveen
20 Using Constitutional AI in LangChain
Using Constitutional AI in LangChain
Sam Witteveen
21 Talking to Alpaca with LangChain - Creating an Alpaca Chatbot
Talking to Alpaca with LangChain - Creating an Alpaca Chatbot
Sam Witteveen
22 Text-to-video-synthesis with Diffusers and Colab
Text-to-video-synthesis with Diffusers and Colab
Sam Witteveen
23 Meet Dolly the new Alpaca model
Meet Dolly the new Alpaca model
Sam Witteveen
24 Checking out the Cerebras-GPT family of models
Checking out the Cerebras-GPT family of models
Sam Witteveen
25 A Step-by-Step Guide to Fine-Tuning Your Dolly Model (tutorial)
A Step-by-Step Guide to Fine-Tuning Your Dolly Model (tutorial)
Sam Witteveen
26 Is GPT4All your new personal ChatGPT?
Is GPT4All your new personal ChatGPT?
Sam Witteveen
27 Raven - RWKV-7B RNN's LLM Strikes Back
Raven - RWKV-7B RNN's LLM Strikes Back
Sam Witteveen
28 Talk to your CSV & Excel with LangChain
Talk to your CSV & Excel with LangChain
Sam Witteveen
29 Vicuna - 90% of ChatGPT quality by using a new dataset?
Vicuna - 90% of ChatGPT quality by using a new dataset?
Sam Witteveen
30 Koala Revealed: The ChatGPT Alternative You Need to Know! 🔍
Koala Revealed: The ChatGPT Alternative You Need to Know! 🔍
Sam Witteveen
31 Running Koala for free in Colab. Your own personal ChatGPT? (tutorial)
Running Koala for free in Colab. Your own personal ChatGPT? (tutorial)
Sam Witteveen
32 BabyAGI: Discover the Power of Task-Driven Autonomous Agents!
BabyAGI: Discover the Power of Task-Driven Autonomous Agents!
Sam Witteveen
33 Auto-GPT - How to Automate a Task Based AI with GPT-4
Auto-GPT - How to Automate a Task Based AI with GPT-4
Sam Witteveen
34 Improve your BabyAGI with LangChain
Improve your BabyAGI with LangChain
Sam Witteveen
35 Generative Agents - Deep Dive and GPT-4 Recreation
Generative Agents - Deep Dive and GPT-4 Recreation
Sam Witteveen
36 GPT4ALLv2: The Improvements and Drawbacks You Need to Know!
GPT4ALLv2: The Improvements and Drawbacks You Need to Know!
Sam Witteveen
37 Dolly 2.0 by Databricks: Open for Business but is it  Ready to Impress!
Dolly 2.0 by Databricks: Open for Business but is it Ready to Impress!
Sam Witteveen
38 Red Pajama - Operation: Freeing LLaMA
Red Pajama - Operation: Freeing LLaMA
Sam Witteveen
39 Investigating Open Assistant - Models, Datasets and Addons
Investigating Open Assistant - Models, Datasets and Addons
Sam Witteveen
40 Investigating MiniGPT-4 - The Secret behind GPT-V?
Investigating MiniGPT-4 - The Secret behind GPT-V?
Sam Witteveen
41 Stable LM 3B - The new tiny kid on the block.
Stable LM 3B - The new tiny kid on the block.
Sam Witteveen
42 Bard can now code and put that code in Colab for you.
Bard can now code and put that code in Colab for you.
Sam Witteveen
43 Checking out Bark: a Text to Speech system by Suno AI
Checking out Bark: a Text to Speech system by Suno AI
Sam Witteveen
44 Fine-tuning LLMs with PEFT and LoRA
Fine-tuning LLMs with PEFT and LoRA
Sam Witteveen
45 Master PDF Chat with LangChain - Your essential guide to queries on documents
Master PDF Chat with LangChain - Your essential guide to queries on documents
Sam Witteveen
46 Using LangChain with DuckDuckGO Wikipedia & PythonREPL Tools
Using LangChain with DuckDuckGO Wikipedia & PythonREPL Tools
Sam Witteveen
47 Building Custom Tools and Agents with LangChain (gpt-3.5-turbo)
Building Custom Tools and Agents with LangChain (gpt-3.5-turbo)
Sam Witteveen
48 StableVicuna: The New King of Open ChatGPTs?
StableVicuna: The New King of Open ChatGPTs?
Sam Witteveen
49 WizardLM: Evolving Instruction Datasets to Create a Better Model
WizardLM: Evolving Instruction Datasets to Create a Better Model
Sam Witteveen
50 LaMini-LM - Mini Models Maxi Data!
LaMini-LM - Mini Models Maxi Data!
Sam Witteveen
51 Finding the Best Free ChatGPT
Finding the Best Free ChatGPT
Sam Witteveen
52 MPT-7B - The First Commercially Usable Fully Trained LLaMA Style Model
MPT-7B - The First Commercially Usable Fully Trained LLaMA Style Model
Sam Witteveen
53 LangChain Retrieval QA Over Multiple Files with ChromaDB
LangChain Retrieval QA Over Multiple Files with ChromaDB
Sam Witteveen
54 LangChain Retrieval QA with Instructor Embeddings & ChromaDB for PDFs
LangChain Retrieval QA with Instructor Embeddings & ChromaDB for PDFs
Sam Witteveen
55 LangChain + Retrieval Local LLMs for Retrieval QA - No OpenAI!!!
LangChain + Retrieval Local LLMs for Retrieval QA - No OpenAI!!!
Sam Witteveen
56 Transformers Agent - Is this Hugging Face's LangChain Competitor?
Transformers Agent - Is this Hugging Face's LangChain Competitor?
Sam Witteveen
57 StarCoder - The LLM to make you a coding star?
StarCoder - The LLM to make you a coding star?
Sam Witteveen
58 Testing Starcoder for Reasoning with PAL
Testing Starcoder for Reasoning with PAL
Sam Witteveen
59 The New Wizards - Unfiltered & Unaligned
The New Wizards - Unfiltered & Unaligned
Sam Witteveen
60 Camel + LangChain for Synthetic Data & Market Research
Camel + LangChain for Synthetic Data & Market Research
Sam Witteveen

This video shows how to use Ollama models with LangChain to perform tasks like loading models, creating prompt templates, and scraping data from websites. It covers setting up a local environment, using APIs, and integrating with other tools like Chroma.

Key Takeaways
  1. Set up a local environment with VS Code and Python
  2. Install LangChain and Ollama models
  3. Load LLM models locally
  4. Create prompt templates
  5. Use APIs to trigger LLMs
  6. Integrate with Chroma for web-based loading and RAG
💡 Using Ollama models with LangChain allows for flexible and powerful natural language processing tasks, including web scraping and information retrieval.

Related Reads

📰
The Research Assistant in the Room
Learn how to build a Research Assistant like Omnist in two weeks with a team of one, leveraging AI and ML concepts
Dev.to · Thomas Lee
📰
AI Mastery: Why Learning AI Is One of the Best Skills Today
Learning AI skills can boost productivity and competitiveness in today's digital world
Dev.to AI
📰
Top AI Papers on Hugging Face - 2026-07-22
Explore top AI papers on Hugging Face, including video grounding and code agents, to stay updated on the latest advancements in AI research
Dev.to · Y Hành Nhan
📰
The Sophistication Trap: Why the Smarter AI Technique Keeps Losing
Smaller AI models can outperform larger ones due to overfitting and complexity, and understanding this phenomenon can inform better AI development strategies
Medium · Deep Learning

Chapters (4)

Intro
1:02 How to load Ollama model locally?
1:57 Basic Chain
3:10 Rag example
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →