-
Notifications
You must be signed in to change notification settings - Fork 1
Langchain Notes
j-sawn edited this page Mar 19, 2025
·
5 revisions
- Langchain can just be downloaded through pip
pip install langchain
- When doing this in a docker container, remember run
source ./app/venv/bin/activate
Requirements
- You would need a Docker container that can run the Python Virtual Environment
- You would also need a Docker container that has the following: (the instructions cover this but you can save time by using our modelworks containers from Week 4)
- Ollama
- Gradio
- Langchain
- You should be able to run two instances of Docker from two terminals
Part 1
Using your terminal run
ollama serve
Part 2
Then, in a new terminal, run the following:
docker exec modelworks-container bash
use cd to move to the dir you want to work in then run
python3 -m venv ./app/venv
source ./app/venv/bin/activate
pip install langchain langchain-community ollama gradio
touch ./app/app.py
open the app.py file and write the following inside (see below)
import gradio as gr
from langchain_community.llms import Ollama
# Load the DeepSeek R1 1.5B model in Ollama
llm = Ollama(model="deepseek-r1:1.5b")
# Function to interact with the model
def chat_with_model(prompt):
response = llm.invoke(prompt) # Invoke the model with user input
return response
# Create a Gradio interface
demo = gr.Interface(
fn=chat_with_model,
inputs="text",
outputs="text",
title="DeepSeek R1 1.5B Chatbot",
description="Chat with DeepSeek-R1:1.5B model running on Ollama using LangChain and Gradio."
)
# Launch Gradio app on a specific port
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)
save that then in the same directory run
python ./app/app.py
open a browser and go to http://localhost:7860.
The result should look like this:

- If you want to make the app.py file from the command line:
- Type
vi ./app/app.py - Press
ito insert code - Copy in the necessary code
- Press
Esc, type:wq, then Enter
- Type
- Otherwise, you might want to do the following if you want to test files that are already in your system but you are using a non-Linux device:
docker cp "[INSERT LOCAL PATH TO YOUR FILE YOU WANT TO RUN]" [INSERT CONTAINER NAME]:[INSERT DIRECTORY OF CONTAINER YOU WANT TO SAVE THE FILE IN]
Welcome to the ModelWorks Wiki! Use the links below to navigate our resources quickly.
Product Information
- π¦ !! JoeyLLM Guide !! π¦
- Shared Product Vision
- Personas, Scenarios, & User Stories
- Procedure to Resolve Conflicts
- Project Milestones
- Decision Making Protocol
- Story Point Estimation Algorithm
- Gradio Notes
- Javascript Notes (split into two)
- Ollama Notes
- Langchain Notes
- Chroma Notes
- GPU Monitor Notes
- Open WebUI Notes
- Web Search Notes
- Chat History Notes
- Meeting Minute 1
- Meeting Minute 2
- Meeting Minute 3
- Meeting Minute 4
- Meeting Minute 5
- Meeting Minute 6
- Meeting Minute 7
- Meeting Minute 8
- Meeting Minute 9
- Meeting Minute 10
- Meeting Minute 11