-
Notifications
You must be signed in to change notification settings - Fork 128
feat: Add comprehensive Ollama integration with chat and embedding support #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This commit adds complete Ollama support to AgentScope, enabling users to leverage local Ollama models with full feature support. 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 Comprehensive 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 This integration provides a complete solution for using Ollama models within the AgentScope ecosystem with full feature parity."
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive Ollama integration to AgentScope, enabling local model usage with full chat and embedding capabilities. The implementation includes 40+ configuration parameters, tool usage support, streaming, and multi-agent conversation formatting.
Key changes:
- Core Ollama integration classes (OllamaChatModel, OllamaHttpClient, OllamaOptions)
- Message formatting system for standard and multi-agent scenarios
- Text embedding support with OllamaTextEmbedding
- Complete DTO layer for API communication
Reviewed changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Added JVM flag for URLClassPath to support tests |
| OllamaOptions.java | Configuration class with 40+ parameters and conversion utilities |
| ThinkOption.java | Chain of Thought configuration interface with boolean/level support |
| OllamaHttpClient.java | HTTP client for Ollama API with sync/async support |
| OllamaChatModel.java | ChatModel implementation with streaming and tool support |
| OllamaTextEmbedding.java | Text embedding model implementation |
| OllamaMessageConverter.java | Converts AgentScope messages to Ollama format |
| OllamaMultiAgentFormatter.java | Formatter for multi-agent conversations |
| OllamaChatFormatter.java | Standard chat formatter |
| OllamaToolsHelper.java | Tool configuration and conversion utilities |
| OllamaResponseParser.java | Parses Ollama responses to ChatResponse |
| OllamaConversationMerger.java | Merges multi-agent conversations |
| OllamaMediaConverter.java | Handles image/media conversion |
| DTO classes | Request/response objects for Ollama API |
| Test files | Comprehensive unit and e2e tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| void testJsonSerializationError() throws Exception { | ||
| // Arrange | ||
| OllamaRequest request = mock(OllamaRequest.class); | ||
| doThrow(new JsonProcessingException("Serialization error") {}).when(request).toString(); // This will cause issues |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default toString(): OllamaRequest inherits toString() from Object, and so is not suitable for printing.
|
|
||
| /** | ||
| * Convert list of content blocks (usually from tool result) to string. | ||
| */ |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method overrides AbstractBaseFormatter<OllamaMessage,OllamaResponse,OllamaRequest>.convertToolResultToString; it is advisable to add an Override annotation.
| */ | |
| */ | |
| @Override |
| .dimensions(TEST_DIMENSIONS) | ||
| .build(); | ||
|
|
||
| assertTrue(model instanceof EmbeddingModel); |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to test whether an instance of OllamaTextEmbedding is also an instance of EmbeddingModel - it always is.
refactor: replace wildcard imports with specific imports - Replace import static org.junit.jupiter.api.Assertions.* with specific assertion imports - Replace import static org.mockito.Mockito.* with specific Mockito imports - Fix Spotless format issue: forbidWildcardImports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
agentscope-extensions/agentscope-extensions-rag-simple/src/test/java/io/agentscope/core/embedding/ollama/OllamaTextEmbeddingEmbedTest.java:1
- Comment is in Chinese. For consistency and accessibility, comments in the codebase should be in English.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public OllamaHttpException(String message, String errorCode, String responseBody) { | ||
| super(message); | ||
| this.statusCode = null; | ||
| this.responseBody = responseBody; | ||
| } |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor parameter errorCode is defined but never used in the constructor body. This appears to be an unused parameter that should either be removed or utilized properly. Consider removing this parameter if it's not needed, or storing it as a field if it should be accessible.
- 添加空的audio.mp3文件以满足CI检查要求 - 该文件为占位符,不包含实际功能 - 此前已在.licenserc.yaml中配置忽略音频文件格式 - 解决ERROR: 'agentscope-core/audio.mp3'缺少许可证头部问题
| * @author qjc | ||
| * @since 1.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this
| * @author qjc | ||
| * @since 1.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this
| <version>${maven-surefire-plugin.version}</version> | ||
| <configuration> | ||
| <argLine>@{argLine} ${argLine}</argLine> | ||
| <argLine>@{argLine} ${argLine} -Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 41 out of 42 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public String convertToolResultToString(List<ContentBlock> blocks) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| for (ContentBlock block : blocks) { | ||
| if (block instanceof TextBlock) { |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method overrides AbstractBaseFormatter<OllamaMessage,OllamaResponse,OllamaRequest>.convertToolResultToString; it is advisable to add an Override annotation.
| public String convertToolResultToString(List<ContentBlock> blocks) { | |
| StringBuilder sb = new StringBuilder(); | |
| for (ContentBlock block : blocks) { | |
| if (block instanceof TextBlock) { | |
| @Override | |
| public String convertToolResultToString(List<ContentBlock> blocks) { | |
| StringBuilder sb = new StringBuilder(); | |
| for (ContentBlock block : blocks) { |
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:
Message Formatting System:
Text Embedding Features:
API DTOs:
Design Decisions
Testing
Additional Notes
This integration provides a complete solution for using Ollama models within the AgentScope ecosystem with full feature parity.