Neler yapabileceksin
- Create an isolated Python virtual environment and install LangChain, Ollama, and Chroma dependencies
- Run a local LLM through Ollama and invoke it from Python with a LangChain prompt chain
- Build an interactive question loop that sends user input through a model chain
- Embed CSV rows as documents into a persistent Chroma vector store using a local embedding model
- Implement retrieval-augmented generation by feeding retrieved documents into the prompt before the model answers
Önce bilmen iyi olur
- Basic Python syntax, including functions, loops, and dictionaries
- Comfort using a terminal and command line
- Familiarity with VS Code or another code editor
- Basic understanding of CSV files
Müfredat
7 ders
- 1
Demo of the finished local review assistant Ücretsiz
You get a first look at the finished app: a terminal program that answers questions by reading a CSV of restaurant reviews. It runs entirely on your own computer, with no paid cloud account.
2 kod2 adım3 alıştırma3 soru - 2
Proje klasörünü ve sanal ortamı kurun Beyond Pass
Proje klasörünü oluşturacak, içinde izole bir Python sanal ortamı oluşturup etkinleştirecek ve agent'ın ihtiyaç duyduğu kütüphaneleri kuracaksın. Bunu en başta yapmak, projenin paketlerini bilgisayarındaki diğer her şeyden ayrı tutar.
1 kod6 adım2 alıştırma3 soru - 3
Ollama'yı kur ve bir sohbet modeli ile bir gömme (embedding) modelini indir Beyond Pass
Ollama'yı kuracaksın; bu, yapay zeka modellerini kendi bilgisayarında çalıştıran bir program. Ardından iki model indireceksin: bir sohbet modeli (llama3.2) ve bir gömme modeli (mxbai-embed-large). Kod yazmadan önce ikisinin de kullanılabilir olduğunu doğrulayacaksın.
1 kod4 adım3 alıştırma4 soru - 4
Bir LangChain istem zinciriyle yerel bir model çağır Beyond Pass
Bu derste, Ollama aracılığıyla kendi bilgisayarınızda çalışan bir modele LangChain kullanarak bir Python betiği bağlayacaksın. Yer tutucuları olan bir istem şablonu yazacak ve bunu modele bağlayarak çağırabileceğin bir zincir oluşturacaksın.
1 kod6 adım3 alıştırma3 soru - 5
Bir soru döngüsü ekle Beyond Pass
Zinciri bir while True döngüsüne alacaksın; böylece kullanıcı q yazana kadar soru sormaya devam edebilir. input(), break ve chain.invoke() komutlarının birlikte nasıl çalıştığını ve basit bir soru-cevap programının nasıl yapıldığını öğreneceksin.
1 kod6 adım3 alıştırma3 soru - 6
Load the CSV and build a persistent Chroma vector store Beyond Pass
You will turn each row of a restaurant-reviews CSV into a Document, convert the text into vectors with a local Ollama embedding model, and store them in a persistent Chroma database that is built only once. You will also see why IDs, metadata and a "does the database already exist?" check matter.
1 kod4 adım3 alıştırma3 soru - 7
Bir retriever oluştur ve RAG'i zincire bağla Beyond Pass
Chroma vektör deposunu, bir soru için en ilgili yorumları getiren bir retriever'a dönüştürürsün. Ardından bu yorumları prompt'a aktarırsın; böylece yerel LLM kendi verilerini kullanarak yanıt verir.
1 kod5 adım3 alıştırma3 soru
Ücretsiz önizleme · 1. dersin tamamı
Demo of the finished local review assistant
You get a first look at the finished app: a terminal program that answers questions by reading a CSV of restaurant reviews. It runs entirely on your own computer, with no paid cloud account.
Dersin komutlarını yaz, boz ve nedenini gör.
Videonun yanında çiz ve yaz.
Fikir
This chapter is a preview. Before any code is written, the video shows the finished product so you know what you are building. The app is a small Python program run from the command prompt. It asks you a question, looks through a file of fake pizza restaurant reviews, and answers using what it found.
The data lives in a CSV file called realistic_restaurant_reviews.csv. A CSV is a plain text table where each line is a row and commas separate the columns. Here the columns are Title, Date, Rating and Review. A review might read 'Best pizza in town' with a date, a rating out of five, and a long text describing the pizza.
The idea behind the app is retrieval augmented generation, often shortened to RAG. The program first retrieves the reviews that are relevant to your question from the file, then gives those reviews to a language model, which writes the answer. The model does not have to know anything about this restaurant in advance; it only sees the pieces the search found.
The tools are all free and run locally. The video uses Ollama to run a language model on your machine, LangChain to connect the pieces, and ChromaDB as a vector database that finds relevant reviews. No OpenAI account or cloud service is needed.
In the demo, the user asks 'how is the quality of the pizza?'. The agent pulls matching reviews and writes a conclusion that notes the answer is hard to score from the reviews alone. Then the user asks 'are there vegan options?' and the agent points to a vegan pizza mentioned in a review, quoting the review's metadata. The answer depends on the reviews in the file, so it is only as good as the data.
Ana noktalar
- The finished app answers questions about restaurant reviews from a local CSV file. 0:00
- RAG means retrieving relevant information from a file and giving it to the model before it answers. 0:12
- Everything is free and runs on your own computer: no OpenAI or cloud account is needed. 0:24
- The tools are Ollama (local model), LangChain (connects the pieces) and ChromaDB (vector search database). 0:36
- The app is run from the command prompt with python main.py and loops asking questions until you type q. 0:59
Bilmen gereken kelimeler
- CSV file
- A plain text table. Each line is a row and commas separate the columns.
- RAG (retrieval augmented generation)
- First find the pieces of data that fit the question, then give them to a language model so it writes the answer from them.
- Language model
- A program that writes text. Here it runs on your own computer.
- Ollama
- A free tool that runs a language model on your own machine.
- LangChain
- A Python library that connects the parts of the app, such as the model and the database.
- ChromaDB
- A vector database. It stores text so it can find the pieces most relevant to a question.
Ekrandaki kod
Title,Date,Rating,Review
Best pizza in town,2024-03-15,5,"The crust was perfectly crispy on the outside and chewy inside. Their signature pepperoni pizza had the perfect ratio of sauce to cheese, and the pepperoni curled up into little cups of deliciousness. Will definitely be back!"
Disappointed with service,2024-02-20,2,"While the pizza itself was decent, we waited over an hour for delivery despite being told it would be 30 minutes. When it finally arrived, it was barely warm. The flavors were good but the experience ruined it."Open the file in any text editor to see the rows; no code needs to run for this chapter.
C:\Users\User\Desktop\Local Ai Agent>python main.py
--------------------
Ask your question here (q to quit):In a terminal inside your project folder, type python main.py and press Enter.
Alıştırma terminalinde birlikte yap
- Open a terminal and move into your project folder (the video uses a folder called Local Ai Agent on the Desktop). Göreceğin: The prompt now shows the Desktop folder.
$ cd Desktop C:\Users\User>cd Desktop C:\Users\User\Desktop>
- Run the app with python main.py. The video shows this as a preview, so you may not have the file yet; this step shows what the finished program looks like when it starts. Göreceğin: The program prints a line of dashes and waits for your question.
$ python main.py -------------------- Ask your question here (q to quit):
Bilerek boz
$ python main.py python: can't open file 'main.py': [Errno 2] No such file or directoryNeden: Python can only run a file that exists in the folder you are in. Check that you cd-ed into the project folder where main.py was saved.
$ cd Local Ai Agent The system cannot find the path specified.Neden: Folder names with spaces must be wrapped in quotes, so use cd "Local Ai Agent".
Dikkat
Alıştırma
In your own words, explain what retrieval augmented generation means, using the pizza reviews as the example.
Çözüm
- Retrieval: find the reviews in the CSV that match the question, e.g. reviews mentioning vegan.
- Augmented generation: give those reviews to the language model so it writes an answer based on them.
RAG first searches a document for the pieces relevant to a question (retrieval), then passes those pieces to a language model that writes the answer (generation). For example, when asked about vegan options, the app finds the reviews that mention vegan food and the model answers using them.
Write one new line for the reviews CSV about a pizza place. Use the columns Title, Date, Rating, Review in that order. Put the Review text in double quotes.
İpucu
Look at the example lines: four values separated by commas, and the long text is in quotes because it contains commas.
Çözüm
- The columns are Title, Date, Rating, Review, so the line needs four values separated by commas.
- Write a short title, then a date such as 2024-04-01, then a rating from 1 to 5.
- Put the review text last and wrap it in double quotes, because the text may contain commas.
Example: Great vegan pizza,2024-04-01,4,"They had a vegan pizza with lots of vegetables, and the crust was lovely."
Match each tool to its job: Ollama, LangChain, ChromaDB. Jobs: (a) connects the pieces together, (b) runs the language model on your computer, (c) finds the reviews relevant to a question.
İpucu
Think about what each tool is described as doing in the lesson.
Çözüm
- Ollama runs the language model locally.
- LangChain connects the pieces of the app.
- ChromaDB is the vector database that finds relevant reviews.
Ollama = (b), LangChain = (a), ChromaDB = (c).
Karalama defterinde
Karalama defterinizde üç kutu çizin, etiketleri 'CSV yorumları', 'İlgili yorumlar' ve 'Model yanıtı' olsun ve kutular arasına oklar çizin. Her okun altına, orada ne olduğunu anlatan bir cümle yazın.
Test
Uygulama restoran hakkındaki soruları yanıtlamak için neyi kullanır?
- Yalnızca kendi yerleşik pizza bilgisini
- CSV dosyasından alınan ilgili yorumların bir modele verilmesi
- Ücretli bir OpenAI bulut hesabını
- İnternette web araması yapmayı
Cevabı göster
B. CSV dosyasından alınan ilgili yorumların bir modele verilmesi · Uygulama CSV'den ilgili yorumları alır ve bunları yerel bir modele iletir (RAG).
0:19 o anı izleBu projede vektör arama veritabanı hangi araçtır?
- Ollama
- LangChain
- ChromaDB
- Sublime Text
Cevabı göster
C. ChromaDB · ChromaDB vektör veritabanıdır; Ollama modeli çalıştırır ve LangChain parçaları birbirine bağlar.
0:08 o anı izleUygulamadan nasıl çıkarsın?
- Ctrl+Alt+Delete tuşlarına basarak
- Soru isteminde q yazarak
- CSV dosyasına exit yazarak
- Sublime Text penceresini kapatarak
Cevabı göster
B. Soru isteminde q yazarak · İstemde 'q to quit' yazıyor, yani q yazmak programı sonlandırır.
1:18 o anı izle
2–7. dersler
Beyond Pass ile açılırlar: her kursun her dersi, eksiksiz. Tek ödeme: 90 gün için $14.99 ya da bir yıl için $29. Abonelik yok.
Beyond, Tech With Tim kanalının “How to Build a Local AI Agent With Python (Ollama, LangChain & RAG)” videosundan yaptı. Video YouTube’un kendi oynatıcısında oynar. YouTube’da izle · Bütün dersler
