-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1050 from sberyozkin/generic_model_auth_provider_…
…with_named_models Allow using generic ModelAuthProvider with named models
- Loading branch information
Showing
7 changed files
with
200 additions
and
13 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...loyment/src/test/java/io/quarkiverse/langchain4j/test/auth/AllModelAuthProvidersTest.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,34 @@ | ||
package io.quarkiverse.langchain4j.test.auth; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
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 io.quarkiverse.langchain4j.auth.ModelAuthProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class AllModelAuthProvidersTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(GeminiModelAuthProvider.class, OpenaiModelAuthProvider.class, GlobalModelAuthProvider.class)); | ||
|
||
@Test | ||
void testThatGlobalModelAuthProviderIsSelectedWithNullModel() { | ||
assertTrue(ModelAuthProvider.resolve(null).get() instanceof GlobalModelAuthProvider); | ||
} | ||
|
||
@Test | ||
void testThatOpenAIModelAuthProviderIsSelectedForOpenaiModel() { | ||
assertTrue(ModelAuthProvider.resolve("openai").get() instanceof OpenaiModelAuthProvider); | ||
} | ||
|
||
@Test | ||
void testThatGeminiModelAuthProviderIsSelectedForGeminiModel() { | ||
assertTrue(ModelAuthProvider.resolve("gemini").get() instanceof GeminiModelAuthProvider); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...eployment/src/test/java/io/quarkiverse/langchain4j/test/auth/GeminiModelAuthProvider.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,17 @@ | ||
package io.quarkiverse.langchain4j.test.auth; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkiverse.langchain4j.ModelName; | ||
import io.quarkiverse.langchain4j.auth.ModelAuthProvider; | ||
|
||
@ModelName("gemini") | ||
@ApplicationScoped | ||
public class GeminiModelAuthProvider implements ModelAuthProvider { | ||
|
||
@Override | ||
public String getAuthorization(Input input) { | ||
return null; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...eployment/src/test/java/io/quarkiverse/langchain4j/test/auth/GlobalModelAuthProvider.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,15 @@ | ||
package io.quarkiverse.langchain4j.test.auth; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkiverse.langchain4j.auth.ModelAuthProvider; | ||
|
||
@ApplicationScoped | ||
public class GlobalModelAuthProvider implements ModelAuthProvider { | ||
|
||
@Override | ||
public String getAuthorization(Input input) { | ||
return null; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...yment/src/test/java/io/quarkiverse/langchain4j/test/auth/GlobalModelAuthProviderTest.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,34 @@ | ||
package io.quarkiverse.langchain4j.test.auth; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
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 io.quarkiverse.langchain4j.auth.ModelAuthProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class GlobalModelAuthProviderTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClass(GlobalModelAuthProvider.class)); | ||
|
||
@Test | ||
void testThatGlobalModelAuthProviderIsSelectedWithNullModel() { | ||
assertTrue(ModelAuthProvider.resolve(null).get() instanceof GlobalModelAuthProvider); | ||
} | ||
|
||
@Test | ||
void testThatGlobalOpenAIModelAuthProviderIsSelectedForOpenaiModel() { | ||
assertTrue(ModelAuthProvider.resolve("openai").get() instanceof GlobalModelAuthProvider); | ||
} | ||
|
||
@Test | ||
void testThatGlobalModelAuthProviderIsSelectedForGeminiModel() { | ||
assertTrue(ModelAuthProvider.resolve("gemini").get() instanceof GlobalModelAuthProvider); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...yment/src/test/java/io/quarkiverse/langchain4j/test/auth/NamedModelAuthProvidersTest.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,34 @@ | ||
package io.quarkiverse.langchain4j.test.auth; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
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 io.quarkiverse.langchain4j.auth.ModelAuthProvider; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class NamedModelAuthProvidersTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(OpenaiModelAuthProvider.class, GeminiModelAuthProvider.class)); | ||
|
||
@Test | ||
void testThatNoModelAuthProviderIsSelectedWithNullModel() { | ||
assertTrue(ModelAuthProvider.resolve(null).isEmpty()); | ||
} | ||
|
||
@Test | ||
void testThatGlobalOpenAIModelAuthProviderIsSelectedForOpenaiModel() { | ||
assertTrue(ModelAuthProvider.resolve("openai").get() instanceof OpenaiModelAuthProvider); | ||
} | ||
|
||
@Test | ||
void testThatGlobalModelAuthProviderIsSelectedForGeminiModel() { | ||
assertTrue(ModelAuthProvider.resolve("gemini").get() instanceof GeminiModelAuthProvider); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...eployment/src/test/java/io/quarkiverse/langchain4j/test/auth/OpenaiModelAuthProvider.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,17 @@ | ||
package io.quarkiverse.langchain4j.test.auth; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkiverse.langchain4j.ModelName; | ||
import io.quarkiverse.langchain4j.auth.ModelAuthProvider; | ||
|
||
@ModelName("openai") | ||
@ApplicationScoped | ||
public class OpenaiModelAuthProvider implements ModelAuthProvider { | ||
|
||
@Override | ||
public String getAuthorization(Input input) { | ||
return null; | ||
} | ||
|
||
} |
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