-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable resolution of AI services by EL name #1087
- Loading branch information
1 parent
ba5350b
commit 6fe51bc
Showing
3 changed files
with
76 additions
and
2 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
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
56 changes: 56 additions & 0 deletions
56
...src/test/java/io/quarkiverse/langchain4j/test/NamedAiServicesAreResolvableByNameTest.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,56 @@ | ||
package io.quarkiverse.langchain4j.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.enterprise.inject.spi.BeanManager; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import dev.langchain4j.data.message.AiMessage; | ||
import dev.langchain4j.data.message.ChatMessage; | ||
import dev.langchain4j.model.chat.ChatLanguageModel; | ||
import dev.langchain4j.model.output.Response; | ||
import dev.langchain4j.service.UserMessage; | ||
import io.quarkiverse.langchain4j.RegisterAiService; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class NamedAiServicesAreResolvableByNameTest { | ||
|
||
private static final String MY_NAMED_SERVICE_BEAN = "myNamedServiceBean"; | ||
|
||
@Inject | ||
BeanManager beanManager; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MyNamedService.class)); | ||
|
||
@Named(MY_NAMED_SERVICE_BEAN) | ||
@RegisterAiService(chatMemoryProviderSupplier = RegisterAiService.NoChatMemoryProviderSupplier.class) | ||
interface MyNamedService { | ||
@UserMessage("Dummy prompt for " + MY_NAMED_SERVICE_BEAN) | ||
String chat(); | ||
} | ||
|
||
@Singleton | ||
public static class MyLanguageModel implements ChatLanguageModel { | ||
@Override | ||
public Response<AiMessage> generate(List<ChatMessage> messages) { | ||
return null; | ||
} | ||
} | ||
|
||
@Test | ||
void namedAiServiceCouldBeResolvedByNameTest() { | ||
assertEquals(1, beanManager.getBeans(MY_NAMED_SERVICE_BEAN).size()); | ||
} | ||
} |