-
[OPIK-3958] [BE] [FE] Add Ollama provider support (#4941)
发布于
2026-01-29 13:55:24 +00:00 - [OPIK-3958] [BE] Add Ollama provider with connection testing and model discovery
- Added OLLAMA as a new LlmProvider enum value
- Enabled provider naming support for multiple Ollama instances (local/cloud)
- Created OllamaModule and OllamaServiceProvider (OpenAI-compatible)
- Added OllamaResource REST endpoints:
- POST /v1/private/ollama/test-connection: Test Ollama instance connectivity
- POST /v1/private/ollama/models: List available models from Ollama instance
- Implemented OllamaService for Ollama API interaction (version check, model listing)
- Added DTOs: OllamaConnectionTestRequest, OllamaConnectionTestResponse, OllamaModel
- Updated StructuredOutputStrategy to handle OLLAMA provider
- Registered OllamaModule in OpikApplication
- Added comprehensive tests: 8 unit tests + 14 integration tests (all passing)
This implements the backend foundation for OPIK-3958, enabling native Ollama
support with connection validation and automatic model discovery.- Revision 2: [OPIK-3958] [FE] Add Ollama provider with connection testing and model discovery
Frontend implementation for Ollama provider integration:
Provider Type System:
- Added OLLAMA to PROVIDER_TYPE enum
- Created OllamaProviderObject type alongside StandardProviderObject and CustomProviderObject
- Added Ollama to PROVIDERS constant with metadata (icon placeholder, API key name, description)
- Integrated Ollama into feature toggle map (reusing CUSTOMLLM_PROVIDER_ENABLED)
API Integration:
- Created useOllamaTestConnectionMutation hook for connection testing
- Created useOllamaListModelsMutation hook for model discovery
- Both hooks integrate with backend /v1/private/ollama/* endpoints
UI Components:
- Created OllamaProviderDetails component with:
- Smart platform detection for default URLs (host.docker.internal for Mac/Windows, 172.17.0.1 for Linux)
- Connection testing with real-time status feedback
- Auto-discovery of models from Ollama instance
- Optional API key and custom headers support
- Updated ProviderConfigurationStep to render OllamaProviderDetails
- Updated SetupProviderDialog and ManageAIProviderDialog to handle Ollama provider
Form Validation:
- Extended CloudAIProviderDetailsFormSchema to exclude Ollama
- Added Ollama to createCustomProviderDetailsFormSchema (uses same validation as Custom/Bedrock)
- Updated provider name uniqueness check to include Ollama
Utility Functions:
- Updated getProviderDisplayName to show provider_name for Ollama
- Updated buildComposedProviderKey to handle Ollama with provider_name
- Updated parseComposedProviderType to parse "ollama:instance-name" format
Form Submission:
- Updated SetupProviderDialog handleSubmit to process Ollama as isOllama
- Updated ManageAIProviderDialog cloudConfigHandler to treat Ollama as isCustomLike
- Both dialogs now send base_url, provider_name, models config, and headers for Ollama
All files pass linting (ESLint + Prettier).
- Revision 3: Fix TypeScript compilation errors for Ollama provider
Fixed missing type definitions and imports:
- Added OLLAMA to OPTIMIZATION_STUDIO_SUPPORTED_MODELS (empty array, to be populated)
- Added OLLAMA to PROVIDER_MODELS in useLLMProviderModelsData (dynamic population)
- Added OLLAMA to ProviderEnabledMap interface in useProviderOptions
- Updated useProviderEnabledMap to include OLLAMA (using CUSTOMLLM_PROVIDER_ENABLED toggle)
- Added configured Ollama instances handling in useProviderOptions
- Added "Add new" Ollama option support in provider selection
- Fixed import path for useToast (was @/hooks/use-toast, should be @/components/ui/use-toast)
- Refactored getProviderDisplayName to handle Ollama with Bedrock pattern
All Ollama-related TypeScript errors resolved. Remaining errors are pre-existing missing dependencies unrelated to this change.
- Revision 3: Fix Ollama JSON deserialization
- Remove ObjectMapper dependency from OllamaService and use JsonUtils instead
- JsonUtils already has JavaTimeModule configured for Instant support
- Add @JsonIgnoreProperties(ignoreUnknown = true) to OllamaModelResponse to handle extra 'model' field
- Update OllamaServiceTest to match new constructor signature
- Revision 4: Add Ollama to OpenAI-compatible providers filter
- Include PROVIDER_TYPE.OLLAMA in useOpenAICompatibleModels hook
- This enables Ollama models to appear in the Playground model selector
- Fixes issue where Ollama provider was configured but models weren't visible
- Revision 5: Add /v1 suffix to Ollama default URL and improve hint text
- Set default URL to http://localhost:11434/v1 (most common real-world usage)
- Remove platform-specific Docker networking URLs (host.docker.internal, 172.17.0.1)
- Add prominent hint about /v1 requirement for OpenAI API compatibility
- Provide clear examples for local and remote Ollama instances
- This fixes 404 errors when calling Ollama through LangChain4j
- Revision 5: Simplify Ollama URL defaults and add /v1 requirement
- Default URL: http://localhost:11434/v1 (most common use case)
- Add clear hint about /v1 suffix requirement for OpenAI API compatibility
- Show practical example: http://ollama-test:11434/v1
- This fixes 404 errors when using Ollama through LangChain4j OpenAI client
- Revision 6: Fix disabled integration test for Ollama model listing
- Remove @Disabled annotation from listModels__success test
- Add 'model' field to mock response (matches actual Ollama API)
- Use proper RFC3339 timestamp format with nanoseconds
- Add comprehensive assertions for model properties
- All 7 OllamaResourceTest tests now pass
- All 8 OllamaServiceTest tests pass
- Revision 7: Fix frontend linting issues (prettier formatting)
- Apply prettier formatting to OllamaProviderDetails.tsx
- Fix whitespace in provider.ts
- All linters now pass without errors
- Revision 8: Add Ollama API v1 version validation
- Add version compatibility check (requires >= 0.1.0)
- Validate version in testConnection and listModels methods
- Return clear error messages for incompatible versions
- Update documentation to specify API v1 compatibility requirement
- Add comprehensive tests for version validation (unit + integration)
- All 12 unit tests pass, all 9 integration tests pass
- [OPIK-3958] [BE] Refactor Ollama URL validation to controller layer
- Move URL validation from service to controller using Jakarta Bean Validation
- Create custom @HttpUrl annotation and HttpUrlValidator
- Remove duplicate validation logic from OllamaService
- Return 422 status code for validation errors (instead of 500)
- Extract helper methods to reduce code duplication
- Use shared ValidationUtils.validateHttpUrl() for consistency
- Update WebhookSubscriber to use shared validation utility
- Fix frontend formatting in OllamaProviderDetails
- Revision: Update tests and rename DTO for Ollama validation refactor
- Update OllamaResourceTest to use POST with request body
- Update OllamaServiceTest to remove validation error handling tests
- Rename OllamaConnectionTestRequest to OllamaInstanceBaseUrlRequest
- Update OllamaConnectionTestResponse documentation
- Update OllamaServiceProvider documentation
- [OPIK-3958] [BE] Fix PR comments: security, logging, and test improvements
- Add URL credential redaction utility for safe logging
- Include redacted URLs in error messages for better correlation
- Refactor duplicate tests to use @ParameterizedTest
- Replace hardcoded test values with random strings
- Fix deprecated RandomStringUtils and RandomUtils method calls
-
[OPIK-3958] [BE] Redact URLs in OllamaService debug logs (PR comment 2733707311)
-
[OPIK-3958] [BE] [FE] Address PR review comments and add API key support
- Use StringUtils.isBlank() in ValidationUtils for null-safe validation
- Fix WebhookSubscriber import for ValidationUtils
- Add optional apiKey field to OllamaInstanceBaseUrlRequest with masked toString()
- Update OllamaService to send Authorization Bearer header when apiKey provided
- Add OLLAMA_REST_ENDPOINT constant in frontend api.ts
- Update frontend mutations with api_key support
- Add tests for API key authentication in OllamaServiceTest
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
- [OPIK-3958] [BE] Add @NonNull validations to OllamaServiceProvider
Add @NonNull annotations to constructor and method parameters
to address PR review comment about missing validations.Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
- [OPIK-3958] [FE] Make OllamaModel fields optional to match API contract
Make size, digest, and modified_at fields optional in the OllamaModel type
since Ollama's /api/tags endpoint can return null for these fields.Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
- [OPIK-3958] [BE] Convert OllamaService to return Mono for non-blocking operations
- Update testConnection and listModels to return Mono
- Add performAsyncGet helper using InvocationCallback
- Update OllamaResource to call .block() on service methods
- Update tests to handle reactive responses
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com
-
[OPIK-3958] [BE] Add validation to OllamaModel name field
-
[OPIK-3958] [BE] Rename OllamaTagsResponse to OllamaModelsResponse
Rename internal DTO to better reflect the data it carries (models list,
not tags). Also rename related variables for consistency.- [OPIK-3958] [BE] Return 502 Bad Gateway when Ollama connection fails
Return proper HTTP status code (502 Bad Gateway) when testConnection
fails instead of always returning 200 OK. This allows clients to
properly detect connection failures via status codes.-
[OPIK-3958] [FE] Fix Prettier formatting in useOllamaListModelsMutation
-
Add toggle
-
[OPIK-3958] [FE] Address PR review comments for Ollama provider
- Extract CustomHeadersField into shared component to reduce duplication
- Remove redundant default URL fallback in OllamaProviderDetails
- Add dedicated Ollama icon (ollama.svg)
- Add TOGGLE_OLLAMA_PROVIDER_ENABLED to docker-compose.yaml
-
[OPIK-3958] [FE] Use official Ollama logo for provider icon
-
[OPIK-3958] [FE] Fix stale connection state and include credentials in Ollama API calls
- Reset connection state when API key or headers change (not just URL)
- Pass api_key to test connection mutation for authenticated instances
- Pass api_key to list models mutation for authenticated instances
- Remove toggle from docker
Co-authored-by: Claude Opus 4.5 noreply@anthropic.com
下载附件