forked from langchain4j/langchain4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw error if more than one retriever/contentRetriever/retrievalAugm… (
langchain4j#710) …entor are set As we discussed in quarkiverse/quarkus-langchain4j#353 (comment) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced AI services with new validation rules to ensure exclusive setting of components, improving system stability and predictability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
langchain4j/src/test/java/dev/langchain4j/service/AiServicesBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package dev.langchain4j.service; | ||
|
||
import dev.langchain4j.exception.IllegalConfigurationException; | ||
import dev.langchain4j.rag.RetrievalAugmentor; | ||
import dev.langchain4j.rag.content.retriever.ContentRetriever; | ||
import dev.langchain4j.retriever.Retriever; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.mock; | ||
|
||
/** | ||
* Verify that the AIServices builder doesn't allow setting more than out of | ||
* (retriever, contentRetriever, retrievalAugmentor). | ||
*/ | ||
public class AiServicesBuilderTest { | ||
|
||
@Test | ||
public void testRetrieverAndContentRetriever() { | ||
Retriever retriever = mock(Retriever.class); | ||
ContentRetriever contentRetriever = mock(ContentRetriever.class); | ||
|
||
assertThrows(IllegalConfigurationException.class, () -> { | ||
AiServices.builder(AiServices.class) | ||
.retriever(retriever) | ||
.contentRetriever(contentRetriever) | ||
.build(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testRetrieverAndRetrievalAugmentor() { | ||
Retriever retriever = mock(Retriever.class); | ||
RetrievalAugmentor retrievalAugmentor = mock(RetrievalAugmentor.class); | ||
|
||
assertThrows(IllegalConfigurationException.class, () -> { | ||
AiServices.builder(AiServices.class) | ||
.retriever(retriever) | ||
.retrievalAugmentor(retrievalAugmentor) | ||
.build(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testContentRetrieverAndRetrievalAugmentor() { | ||
ContentRetriever contentRetriever = mock(ContentRetriever.class); | ||
RetrievalAugmentor retrievalAugmentor = mock(RetrievalAugmentor.class); | ||
|
||
assertThrows(IllegalConfigurationException.class, () -> { | ||
AiServices.builder(AiServices.class) | ||
.contentRetriever(contentRetriever) | ||
.retrievalAugmentor(retrievalAugmentor) | ||
.build(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testContentRetrieverAndRetriever() { | ||
Retriever retriever = mock(Retriever.class); | ||
ContentRetriever contentRetriever = mock(ContentRetriever.class); | ||
|
||
assertThrows(IllegalConfigurationException.class, () -> { | ||
AiServices.builder(AiServices.class) | ||
.contentRetriever(contentRetriever) | ||
.retriever(retriever) | ||
.build(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testRetrievalAugmentorAndRetriever() { | ||
Retriever retriever = mock(Retriever.class); | ||
RetrievalAugmentor retrievalAugmentor = mock(RetrievalAugmentor.class); | ||
|
||
assertThrows(IllegalConfigurationException.class, () -> { | ||
AiServices.builder(AiServices.class) | ||
.retrievalAugmentor(retrievalAugmentor) | ||
.retriever(retriever) | ||
.build(); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testRetrievalAugmentorAndContentRetriever() { | ||
ContentRetriever contentRetriever = mock(ContentRetriever.class); | ||
RetrievalAugmentor retrievalAugmentor = mock(RetrievalAugmentor.class); | ||
|
||
assertThrows(IllegalConfigurationException.class, () -> { | ||
AiServices.builder(AiServices.class) | ||
.retrievalAugmentor(retrievalAugmentor) | ||
.contentRetriever(contentRetriever) | ||
.build(); | ||
}); | ||
} | ||
|
||
} |