Commit 5ec9334
authored
feat: Add comprehensive Ollama integration with chat and embedding support (#385)
## Summary
This PR adds comprehensive Ollama integration to AgentScope, enabling
users to leverage local Ollama models with full feature support.
## Features Implemented
### Core Chat Features:
- **OllamaOptions**: Complete configuration class supporting 40+ Ollama
parameters including advanced model loading options (GPU offloading,
memory management) and runtime generation parameters (sampling
strategies, penalties)
- **OllamaHttpClient**: HTTP client for Ollama API with sync/async and
streaming support, proper JSON serialization/deserialization and error
handling
- **OllamaChatModel**: Full ChatModel implementation with tool usage,
streaming, timeout/retry mechanisms, and seamless integration with
AgentScope framework
### Message Formatting System:
- **OllamaChatFormatter**: Standard chat formatting with proper role
mapping
- **OllamaMultiAgentFormatter**: Multi-agent conversation formatting
with history management
- **OllamaMessageConverter**: Message conversion between AgentScope and
Ollama formats
- **OllamaConversationMerger**: Multi-agent conversation merging with
history tags
- **OllamaToolsHelper**: Tool configuration and usage support
- **OllamaMediaConverter**: Media and image handling for multimodal
models
### Text Embedding Features:
- **OllamaTextEmbedding**: Complete text embedding implementation with
support for Ollama's embedding API
- Includes proper error handling, timeout/retry mechanisms, and
dimension validation
- Supports reactive programming with Project Reactor's Mono
### API DTOs:
- Complete set of data transfer objects for Ollama API requests and
responses
- Support for messages, tools, tool calls, embeddings, and complex
conversation structures
## Design Decisions
- Used adapter pattern instead of inheritance for OllamaOptions to avoid
coupling with generic options
- Implemented flexible message formatting system supporting both
standard and multi-agent scenarios
- Added Chain of Thought (CoT) support through thinking options
- Optimized single message handling to avoid unnecessary conversation
history wrapping
- Proper reactive programming support with timeout and retry mechanisms
## Testing
- Complete test coverage for all Ollama components
- Unit tests for message formatting, conversion, and API communication
- Integration tests for end-to-end functionality
- Tests for both chat and embedding functionality
## Additional Notes
This integration provides a complete solution for using Ollama models
within the AgentScope ecosystem with full feature parity.1 parent 7616103 commit 5ec9334
42 files changed
Lines changed: 10300 additions & 10 deletions
File tree
- agentscope-core/src
- main/java/io/agentscope/core
- formatter/ollama
- dto
- model
- ollama
- transport
- test/java/io/agentscope/core
- formatter
- ollama
- dto
- model
- ollama
- transport
- agentscope-extensions/agentscope-extensions-rag-simple/src
- main/java/io/agentscope/core/embedding
- ollama
- test/java/io/agentscope/core/embedding/ollama
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 474 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 113 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
0 commit comments