Python and venv installation and longchain ollama installation on debian13
Install python and basic modules:
sudo apt update
sudo apt install python3 python3-venv python3-pip python3-full
to make python command alias of python3 :-
sudo apt install python-is-python3
kayyum@debian:~/Downloads$ python -m venv 9May2026
kayyum@debian:~/Downloads$ ls
9May2026 Dockerfile
kayyum@debian:~/Downloads$ cd 9May2026/
kayyum@debian:~/Downloads/9May2026$ ls
bin include lib lib64 pyvenv.cfg
kayyum@debian:~/Downloads/9May2026$
kayyum@debian:~/Downloads/9May2026$
kayyum@debian:~/Downloads/9May2026$ source bin/activate
(9May2026) kayyum@debian:~/Downloads/9May2026$
(9May2026) kayyum@debian:~/Downloads/9May2026$
(9May2026) kayyum@debian:~/Downloads/9May2026$
(9May2026) kayyum@debian:~/Downloads/9May2026$ pip install -U langchain-ollama langchain
(9May2026) kayyum@debian:~/Downloads/9May2026$ cat ollama_test.py
from langchain_ollama import ChatOllama
from langchain_core.prompts import ChatPromptTemplate
# 1. Initialize the model
llm = ChatOllama(
model="qwen2.5-coder:1.5b",
temperature=0,
)
# 2. Create a prompt template
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful coding assistant."),
("human", "{input}")
])
# 3. Create and invoke the chain
chain = prompt | llm
response = chain.invoke({"input": "list out top process currently running."})
print(response.content)
(9May2026) kayyum@debian:~/Downloads/9May2026$ python ollama_test.py
To list the top processes currently running on your system, you can use various methods depending on your operating system. Here are some common ways to do this:
### On Linux
1. **Using `top` Command:**
```sh
top
```
This command provides a real-time view of the system's processes, showing CPU usage, memory usage, and other details.
2. **Using `htop`:**
```sh
htop
```
`htop` is an interactive process viewer that allows you to sort and filter processes by various criteria.
3. **Using `ps` Command:**
```sh
ps aux --sort=-%mem
```
This command lists all running processes sorted by memory usage in descending order.
4. **Using `pgrep` and `pkill`:**
```sh
pgrep -x <process_name>
pkill <process_name>
```
These commands can be used to find the process ID (PID) of a specific process and kill it, respectively.
### On macOS
1. **Using `top` Command:**
```sh
top
```
This command provides a real-time view of the system's processes, showing CPU usage, memory usage, and other details.
2. **Using `Activity Monitor`:**
- Open Activity Monitor from the Applications > Utilities folder.
- You can sort processes by various criteria in the "CPU" or "Memory" tabs.
3. **Using `ps` Command:**
```sh
ps aux --sort=-%mem
```
This command lists all running processes sorted by memory usage in descending order.
### On Windows
1. **Using Task Manager:**
- Press `Ctrl + Shift + Esc` to open the Task Manager.
- You can sort processes by various criteria in the "CPU" or "Memory" tabs.
2. **Using Command Prompt:**
```cmd
tasklist /FI "IMAGENAME eq <process_name>"
```
This command lists all running processes that match a specific image name.
3. **Using PowerShell:**
```powershell
Get-Process | Sort-Object -Property CPU -Descending
```
This command lists all running processes sorted by CPU usage in descending order.
These methods should help you identify and manage the top processes currently running on your system effectively.
(9May2026) kayyum@debian:~/Downloads/9May2026$
(9May2026) kayyum@debian:~/Downloads/9May2026$ ollama ps
NAME ID SIZE PROCESSOR CONTEXT UNTIL
qwen2.5-coder:1.5b d7372fd82851 1.1 GB 100% CPU 4096 4 minutes from now
(9May2026) kayyum@debian:~/Downloads/9May2026$ ollama list
NAME ID SIZE MODIFIED
qwen2.5-coder:1.5b d7372fd82851 986 MB 2 days ago
(9May2026) kayyum@debian:~/Downloads/9May2026$
to execute shell scripts commands :=
(9May2026) kayyum@debian:~/Downloads/9May2026$ pip install langchain-ollama langchain-community
(9May2026) kayyum@debian:~/Downloads/9May2026$ pip install -U langchain-experimental
to view all pip packages modules installed on your system:=
pip list
(9May2026) kayyum@debian:~/Downloads/9May2026$ cat executing_script.py
from langchain_ollama import ChatOllama
from langchain_community.tools import ShellTool
# 1. Initialize the tool and the model
shell_tool = ShellTool()
llm = ChatOllama(model="qwen2.5-coder:1.5b", temperature=0)
# 2. Bind the tool to the LLM (so the model knows it can "call" it)
llm_with_tools = llm.bind_tools([shell_tool])
# 3. Direct execution (Manual)
# You can use the tool yourself to run a specific command
result = shell_tool.run({"commands": ["ls -la", "echo 'Hello from LangChain'"]})
print(result)
# 4. Agentic execution (AI chooses to run it)
# To let the AI decide when to use the terminal, you typically use an
# AgentExecutor (requires a separate 'langchain' install).
(9May2026) kayyum@debian:~/Downloads/9May2026$ python executing_script.py
/home/kayyum/Downloads/9May2026/lib/python3.13/site-packages/langchain_community/tools/shell/tool.py:33: UserWarning: The shell tool has no safeguards by default. Use at your own risk.
warnings.warn(
Executing command:
['ls -la', "echo 'Hello from LangChain'"]
total 40
drwxrwxr-x 5 kayyum kayyum 4096 May 9 13:10 .
drwxr-xr-x 3 kayyum kayyum 4096 May 9 12:38 ..
drwxrwxr-x 2 kayyum kayyum 4096 May 9 13:11 bin
-rwxrwxr-x 1 kayyum kayyum 691 May 9 13:10 executing_script.py
-rw-rw-r-- 1 kayyum kayyum 69 May 9 12:38 .gitignore
drwxrwxr-x 4 kayyum kayyum 4096 May 9 13:11 include
drwxrwxr-x 3 kayyum kayyum 4096 May 9 12:38 lib
lrwxrwxrwx 1 kayyum kayyum 3 May 9 12:38 lib64 -> lib
-rwxrwxr-x 1 kayyum kayyum 508 May 9 12:54 ollama_test.py
-rw-rw-r-- 1 kayyum kayyum 512 May 9 12:58 python ollama_test.py
-rw-rw-r-- 1 kayyum kayyum 169 May 9 12:38 pyvenv.cfg
Hello from LangChain
(9May2026) kayyum@debian:~/Downloads/9May2026$ cat executing_script.py
from langchain_ollama import ChatOllama
from langchain_community.tools import ShellTool
# Import from langchain_classic instead of langchain.agents
from langchain_classic.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
# 1. Setup the Model & Tools
llm = ChatOllama(model="qwen2.5-coder:1.5b", temperature=0)
shell_tool = ShellTool()
tools = [shell_tool]
# 2. Define the Prompt (standard for tool-calling)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful assistant that can use the terminal to solve problems."),
("placeholder", "{chat_history}"),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
# 3. Construct the Agent using the classic logic
agent = create_tool_calling_agent(llm, tools, prompt)
# 4. Create the Executor
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# 5. Run it
agent_executor.invoke({"input": "list the files in the current directory"})
(9May2026) kayyum@debian:~/Downloads/9May2026$ python executing_script.py
> Entering new AgentExecutor chain...
```json
{
"name": "terminal",
"arguments": {
"commands": [
{
"description": "List of shell commands to run. Deserialized using json.loads"
}
]
}
}
```
> Finished chain.
Comments
Post a Comment