Fix AI service model selection#322
Conversation
Co-Authored-By: Codex with GPT-5 <codex@openai.com>
There was a problem hiding this comment.
Pull request overview
Updates AiServiceFactory to avoid configuring both ChatModel and StreamingChatModel for AI services that only need one model type, aligning Micronaut’s wiring with LangChain4j’s expectations and preventing builder errors.
Changes:
- Add model-selection logic that inspects an
@AiServicebean’s executable methods to decide whether to configureChatModel,StreamingChatModel, or both. - Use LangChain4j
TokenStreamAdapterSPI to classify streaming return types beyondTokenStream. - Add regression tests for chat-only and streaming-only AI service interfaces.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| micronaut-langchain4j-core/src/main/java/io/micronaut/langchain4j/aiservices/AiServiceFactory.java | Introduces method-based model selection and conditional wiring of chat vs streaming chat models. |
| micronaut-langchain4j-core/src/test/java/io/micronaut/langchain4j/aiservices/AiServiceFactoryModelSelectionTest.java | Adds tests ensuring only the needed model is configured for chat-only vs streaming-only services. |
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/micronaut-projects/micronaut-langchain4j/sessions/21479b80-4884-4bde-94c0-ecfc07ea9d70 Co-authored-by: graemerocher <66626+graemerocher@users.noreply.github.com>
Applied all three review changes in f4567ca:
All 3 tests pass. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|



Summary
Verification
./gradlew :micronaut-langchain4j-core:test --tests io.micronaut.langchain4j.aiservices.AiServiceFactoryModelSelectionTestResolves #233