Skip to content

Commit 0cc8632

Browse files
author
River@devbox
committed
Add Ollama documentation for local LLM integration
- Document Ollama framework for running Deepseek/Qwen/Gemma models locally - Guide for installing models via Shell Terminal (recommend deepseek-r1:1.5b) - Instructions for ollama serve and OpenAI-compatible API usage
1 parent b160acf commit 0cc8632

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

‎mkdocs.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ nav:
4949
- QPYPI: qpypi-guide.md
5050
- Graphical Interface: GraphicalInterface.md
5151
- AIPyApp: AIPyApp.md
52+
- Ollama: Ollama.md
5253
- OpenAPI: external-api.md
5354
- QSL4A:
5455
- Overview: qsl4a/index.md

‎source/en/Ollama.md‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Ollama - Local Large Language Model Integration
2+
3+
Ollama is a local large language model runtime framework that supports a variety of models including Deepseek, Qwen, and Gemma. QPython has built-in Ollama integration, enabling developers to explore GenAI development directly on their mobile devices.
4+
5+
![Ollama](static/ollama_demo.jpg)
6+
7+
## Overview
8+
9+
Ollama allows you to run powerful large language models locally on your Android device. With QPython's integration, you can:
10+
11+
- Run open-source LLMs directly on your phone
12+
- Use AI capabilities without internet connectivity
13+
- Experiment with different models for various use cases
14+
- Build AI-powered applications using familiar Python libraries
15+
16+
## Supported Models
17+
18+
Ollama supports many popular open-source models:
19+
20+
- **Deepseek** – Efficient reasoning models (recommended: deepseek-r1:1.5b for mobile)
21+
- **Qwen** – Alibaba's large language models
22+
- **Gemma** – Google's lightweight open models
23+
- And many more available on [Ollama Library](https://ollama.com/library)
24+
25+
## Getting Started
26+
27+
### Step 1: Access QPython Shell Terminal
28+
29+
1. Open QPython and go to the **Dashboard**
30+
2. **Long press** the Terminal icon
31+
3. Select **QPython Shell Terminal**
32+
33+
### Step 2: Download a Model
34+
35+
In the Shell Terminal, use Ollama commands to download models. For mobile devices, we recommend smaller models for faster response times.
36+
37+
```bash
38+
# Pull a model (example: deepseek-r1 with 1.5 billion parameters)
39+
ollama pull deepseek-r1:1.5b
40+
41+
# Pull other models
42+
ollama pull qwen:2.5
43+
ollama pull gemma:2b
44+
```
45+
46+
### Step 3: Run the Model
47+
48+
Start the Ollama service to make the model available via API:
49+
50+
```bash
51+
ollama serve
52+
```
53+
54+
When running, Ollama will output the local port address (default: 11434).
55+
56+
## Using Ollama with Python
57+
58+
### Install OpenAI Library
59+
60+
Install the `openai` library from QPYPI:
61+
62+
```bash
63+
# Using PIP Client (long press Terminal icon -> PIP Client)
64+
pip install openai
65+
```
66+
67+
### Python Code Example
68+
69+
After starting `ollama serve`, you can use the OpenAI-compatible API to interact with your local model:
70+
71+
```python
72+
from openai import OpenAI
73+
74+
# Configure the client
75+
client = OpenAI(
76+
api_key="deepseek", # Can be any string
77+
base_url="https://localhost:11434/v1" # Ollama's local address
78+
)
79+
80+
# Chat with the model
81+
response = client.chat.completions.create(
82+
model="deepseek-r1:1.5b", # Match the model you downloaded
83+
messages=[
84+
{"role": "user", "content": "What is Python?"}
85+
]
86+
)
87+
88+
print(response.choices[0].message.content)
89+
```
90+
91+
## Recommended Models for Mobile
92+
93+
| Model | Parameters | Best For |
94+
|-------|------------|----------|
95+
| deepseek-r1 | 1.5b | Fast responses, general tasks |
96+
| qwen:2.5 | 2.5b | Balanced performance |
97+
| gemma:2b | 2b | Lightweight tasks |
98+
99+
Larger models will work but may respond slower on mobile devices.
100+
101+
## Useful Ollama Commands
102+
103+
```bash
104+
# List installed models
105+
ollama list
106+
107+
# Remove a model
108+
ollama rm deepseek-r1:1.5b
109+
110+
# Show model information
111+
ollama show deepseek-r1:1.5b
112+
113+
# Create a custom model (Modelfile)
114+
ollama create mymodel -f Modelfile
115+
```
116+
117+
## Learn More
118+
119+
- [Ollama Documentation](https://docs.ollama.com) – Official Ollama guides and command reference
120+
- [Ollama Library](https://ollama.com/library) – Browse available models
121+
- [AIPyApp](AIPyApp.md) – AI-powered program generator in QPython
122+
- [QPYPI Guide](qpypi-guide.md) – Managing Python packages

0 commit comments

Comments
 (0)