|
| 1 | +# Ollama Integration Documentation |
| 2 | + |
| 3 | +**Last Updated:** 2026-02-07 |
| 4 | +**Research Session:** Comprehensive Ollama + Java ecosystem analysis |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +This directory contains complete documentation for integrating Ollama with Java applications, specifically tailored for the meteor-mcp-addon project. |
| 9 | + |
| 10 | +**Ollama** is a platform for running large language models locally. It provides: |
| 11 | +- Local LLM execution (no cloud API required) |
| 12 | +- OpenAI-compatible API |
| 13 | +- Function/tool calling support |
| 14 | +- 100+ models available |
| 15 | +- Zero cost (runs locally) |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Documents in this Directory |
| 20 | + |
| 21 | +### 1. [ollama-java-integration.md](./ollama-java-integration.md) |
| 22 | +**Comprehensive integration guide covering:** |
| 23 | +- Google GenAI SDK compatibility (not recommended) |
| 24 | +- OpenAI API compatibility (fully supported) |
| 25 | +- Java library options (Ollama4j recommended) |
| 26 | +- Function calling / tool use support |
| 27 | +- REST API reference |
| 28 | +- Complete code examples |
| 29 | + |
| 30 | +**When to read:** First time learning about Ollama Java integration |
| 31 | + |
| 32 | +### 2. [ollama4j-api-reference.md](./ollama4j-api-reference.md) |
| 33 | +**Complete API reference for Ollama4j library:** |
| 34 | +- Installation (Maven/Gradle) |
| 35 | +- Chat API |
| 36 | +- Tool calling (annotation-based & manual) |
| 37 | +- Streaming responses |
| 38 | +- Model management |
| 39 | +- Configuration options |
| 40 | +- Best practices |
| 41 | + |
| 42 | +**When to read:** Implementing Ollama4j in code |
| 43 | + |
| 44 | +### 3. [integration-recommendations.md](./integration-recommendations.md) |
| 45 | +**Project-specific implementation guide:** |
| 46 | +- Architecture recommendations |
| 47 | +- Phase-by-phase implementation plan |
| 48 | +- Code examples for meteor-mcp-addon |
| 49 | +- Gemini vs Ollama comparison |
| 50 | +- StarScript integration |
| 51 | +- GUI implementation |
| 52 | +- Testing strategy |
| 53 | + |
| 54 | +**When to read:** Planning Ollama integration for this project |
| 55 | + |
| 56 | +### 4. [quick-reference.md](./quick-reference.md) |
| 57 | +**Quick reference cheat sheet:** |
| 58 | +- Installation & setup commands |
| 59 | +- Common code snippets |
| 60 | +- Model recommendations |
| 61 | +- REST API examples |
| 62 | +- Troubleshooting |
| 63 | +- Best practices |
| 64 | + |
| 65 | +**When to read:** Quick lookup during development |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## Quick Start |
| 70 | + |
| 71 | +### 1. Install Ollama |
| 72 | +```bash |
| 73 | +# Download from https://ollama.com/download |
| 74 | +# Start server |
| 75 | +ollama serve |
| 76 | +``` |
| 77 | + |
| 78 | +### 2. Pull a Model |
| 79 | +```bash |
| 80 | +ollama pull llama3.1:8b |
| 81 | +``` |
| 82 | + |
| 83 | +### 3. Add Dependency (Gradle Kotlin DSL) |
| 84 | +```kotlin |
| 85 | +dependencies { |
| 86 | + implementation("io.github.ollama4j:ollama4j:1.1.4") |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +### 4. Basic Java Code |
| 91 | +```java |
| 92 | +import io.github.ollama4j.Ollama; |
| 93 | +import io.github.ollama4j.models.chat.OllamaChatMessageRole; |
| 94 | +import io.github.ollama4j.models.chat.OllamaChatRequest; |
| 95 | + |
| 96 | +Ollama api = new Ollama("http://localhost:11434"); |
| 97 | + |
| 98 | +OllamaChatRequest request = OllamaChatRequest.builder() |
| 99 | + .withModel("llama3.1") |
| 100 | + .withMessage(OllamaChatMessageRole.USER, "Hello!") |
| 101 | + .build(); |
| 102 | + |
| 103 | +String response = api.chat(request, token -> {}).getResponseModel().getMessage().getResponse(); |
| 104 | +System.out.println(response); |
| 105 | +``` |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## Key Findings Summary |
| 110 | + |
| 111 | +### Question 1: Does Google GenAI SDK work with Ollama? |
| 112 | +**Answer:** Technically yes (via custom endpoint), but **NOT recommended**. |
| 113 | +- Different API formats (especially function calling) |
| 114 | +- Use Ollama4j instead for native support |
| 115 | + |
| 116 | +### Question 2: Does Ollama have OpenAI-compatible API? |
| 117 | +**Answer:** **YES**, fully supported at `http://localhost:11434/v1` |
| 118 | +- Chat completions: ✅ |
| 119 | +- Tool calling: ✅ |
| 120 | +- Streaming: ✅ |
| 121 | +- Embeddings: ✅ |
| 122 | + |
| 123 | +### Question 3: Best Java library for Ollama? |
| 124 | +**Answer:** **Ollama4j** (`io.github.ollama4j:ollama4j:1.1.4`) |
| 125 | +- Purpose-built for Ollama |
| 126 | +- Active development (474 stars) |
| 127 | +- Complete feature set |
| 128 | +- Annotation-based tool calling |
| 129 | +- MCP support |
| 130 | + |
| 131 | +### Question 4: Does Ollama support function calling? |
| 132 | +**Answer:** **YES**, native support |
| 133 | +- Models: Llama 3.1+, Mistral, Qwen, FunctionGemma |
| 134 | +- Format: Same as OpenAI tool calling |
| 135 | +- Works with Ollama4j annotation system |
| 136 | + |
| 137 | +### Question 5: REST API format? |
| 138 | +**Answer:** See [ollama-java-integration.md](./ollama-java-integration.md#rest-api-format-for-tool-calling) |
| 139 | +- Native endpoint: `POST /api/chat` |
| 140 | +- OpenAI endpoint: `POST /v1/chat/completions` |
| 141 | +- Streaming enabled by default |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## Recommended Implementation Path |
| 146 | + |
| 147 | +For **meteor-mcp-addon**, follow this approach: |
| 148 | + |
| 149 | +### Phase 1: Add Dependency |
| 150 | +```kotlin |
| 151 | +// build.gradle.kts |
| 152 | +implementation("io.github.ollama4j:ollama4j:1.1.4") |
| 153 | +``` |
| 154 | + |
| 155 | +### Phase 2: Create Config System |
| 156 | +```java |
| 157 | +public class OllamaConfig { |
| 158 | + private boolean enabled = false; |
| 159 | + private String host = "http://localhost:11434"; |
| 160 | + private String defaultModel = "llama3.1"; |
| 161 | + // ... NBT serialization |
| 162 | +} |
| 163 | +``` |
| 164 | + |
| 165 | +### Phase 3: Create Executor |
| 166 | +```java |
| 167 | +public class OllamaExecutor { |
| 168 | + private final Ollama api; |
| 169 | + |
| 170 | + public String execute(String model, String prompt) { ... } |
| 171 | + public String executeWithMCP(String model, String prompt, List<MCPServerConnection> servers) { ... } |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +### Phase 4: Add StarScript Functions |
| 176 | +```java |
| 177 | +// {ollama("prompt")} |
| 178 | +// {ollama_mcp("prompt with tools")} |
| 179 | +``` |
| 180 | + |
| 181 | +### Phase 5: Add Chat Commands |
| 182 | +```java |
| 183 | +// .ollama chat "prompt" |
| 184 | +// .ollama-mcp "prompt" |
| 185 | +``` |
| 186 | + |
| 187 | +### Phase 6: Add GUI Settings |
| 188 | +```java |
| 189 | +// Meteor GUI > MCP > Ollama Settings |
| 190 | +``` |
| 191 | + |
| 192 | +**Full implementation details:** See [integration-recommendations.md](./integration-recommendations.md) |
| 193 | + |
| 194 | +--- |
| 195 | + |
| 196 | +## Gemini vs Ollama Comparison |
| 197 | + |
| 198 | +| Feature | Gemini | Ollama | |
| 199 | +|---------|--------|---------| |
| 200 | +| Location | Cloud (Google) | Local machine | |
| 201 | +| Cost | Paid (free tier) | Free | |
| 202 | +| Privacy | Data → Google | Fully local | |
| 203 | +| Speed | Network latency | Very fast (local) | |
| 204 | +| Quality | Very high | Good (model-dependent) | |
| 205 | +| Internet | Required | Not required | |
| 206 | +| Models | Google only | 100+ models | |
| 207 | + |
| 208 | +**Recommendation:** Implement **both** for maximum flexibility. |
| 209 | +- Gemini: Complex reasoning, large context |
| 210 | +- Ollama: Fast, private, offline, free |
| 211 | + |
| 212 | +--- |
| 213 | + |
| 214 | +## Recommended Models for Minecraft Mod |
| 215 | + |
| 216 | +| Use Case | Model | Size | Reason | |
| 217 | +|----------|-------|------|--------| |
| 218 | +| Chat commands | `llama3.1:8b` | 4.7GB | Best balance | |
| 219 | +| HUD elements | `qwen2.5:0.5b` | 400MB | Fastest | |
| 220 | +| MCP tool use | `llama3.1:8b` | 4.7GB | Excellent tools | |
| 221 | +| Code generation | `qwen2.5-coder:7b` | 4.7GB | Code-specialized | |
| 222 | + |
| 223 | +--- |
| 224 | + |
| 225 | +## External Resources |
| 226 | + |
| 227 | +### Official Links |
| 228 | +- **Ollama:** https://ollama.com/ |
| 229 | +- **Ollama GitHub:** https://github.com/ollama/ollama |
| 230 | +- **Ollama Docs:** https://docs.ollama.com/ |
| 231 | +- **Ollama4j GitHub:** https://github.com/ollama4j/ollama4j |
| 232 | +- **Ollama4j Docs:** https://ollama4j.github.io/ollama4j/ |
| 233 | +- **Model Library:** https://ollama.com/library |
| 234 | + |
| 235 | +### Key Documentation |
| 236 | +- [OpenAI Compatibility](https://docs.ollama.com/api/openai-compatibility) |
| 237 | +- [Tool Calling Guide](https://docs.ollama.com/capabilities/tool-calling) |
| 238 | +- [Streaming Guide](https://docs.ollama.com/capabilities/streaming) |
| 239 | +- [API Reference](https://github.com/ollama/ollama/blob/main/docs/api.md) |
| 240 | + |
| 241 | +--- |
| 242 | + |
| 243 | +## Document Structure |
| 244 | + |
| 245 | +``` |
| 246 | +AI_DOCS/ollama/ |
| 247 | +├── README.md (this file) |
| 248 | +├── ollama-java-integration.md (comprehensive guide) |
| 249 | +├── ollama4j-api-reference.md (API documentation) |
| 250 | +├── integration-recommendations.md (project-specific) |
| 251 | +└── quick-reference.md (cheat sheet) |
| 252 | +``` |
| 253 | + |
| 254 | +--- |
| 255 | + |
| 256 | +## Sources |
| 257 | + |
| 258 | +All documentation is based on: |
| 259 | +- Official Ollama documentation (docs.ollama.com) |
| 260 | +- Ollama4j library documentation (ollama4j.github.io) |
| 261 | +- Community resources (Medium, IBM, DeepWiki) |
| 262 | +- Maven Central repository information |
| 263 | +- GitHub repositories (ollama/ollama, ollama4j/ollama4j) |
| 264 | + |
| 265 | +**Research Date:** 2026-02-07 |
| 266 | +**Researcher:** Claude Code AI Documentation Specialist |
| 267 | + |
| 268 | +--- |
| 269 | + |
| 270 | +## Next Steps |
| 271 | + |
| 272 | +1. **Read:** [integration-recommendations.md](./integration-recommendations.md) for full implementation plan |
| 273 | +2. **Install:** Ollama server and pull `llama3.1` model |
| 274 | +3. **Add:** Ollama4j dependency to `build.gradle.kts` |
| 275 | +4. **Implement:** Phase-by-phase following the recommendations doc |
| 276 | +5. **Test:** StarScript functions and chat commands |
| 277 | + |
| 278 | +--- |
| 279 | + |
| 280 | +**Documentation Set Version:** 1.0 |
| 281 | +**Total Documents:** 5 (including this README) |
| 282 | +**Total Pages:** ~50 pages of documentation |
| 283 | +**Coverage:** Complete (installation → production deployment) |
0 commit comments