Skip to content

Commit

Permalink
Allow to disable all models at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Nov 22, 2023
1 parent 02d4244 commit aa3f9d4
Show file tree
Hide file tree
Showing 20 changed files with 378 additions and 18 deletions.
51 changes: 51 additions & 0 deletions docs/modules/ROOT/pages/includes/quarkus-langchain4j-openai.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,57 @@ h|[[quarkus-langchain4j-openai_configuration]]link:#quarkus-langchain4j-openai_c
h|Type
h|Default

a|icon:lock[title=Fixed at build time] [[quarkus-langchain4j-openai_quarkus.langchain4j.openai.chat-model.enabled]]`link:#quarkus-langchain4j-openai_quarkus.langchain4j.openai.chat-model.enabled[quarkus.langchain4j.openai.chat-model.enabled]`


[.description]
--
Whether the model should be enabled

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_CHAT_MODEL_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a|icon:lock[title=Fixed at build time] [[quarkus-langchain4j-openai_quarkus.langchain4j.openai.embedding-model.enabled]]`link:#quarkus-langchain4j-openai_quarkus.langchain4j.openai.embedding-model.enabled[quarkus.langchain4j.openai.embedding-model.enabled]`


[.description]
--
Whether the model should be enabled

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_EMBEDDING_MODEL_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_EMBEDDING_MODEL_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a|icon:lock[title=Fixed at build time] [[quarkus-langchain4j-openai_quarkus.langchain4j.openai.moderation-model.enabled]]`link:#quarkus-langchain4j-openai_quarkus.langchain4j.openai.moderation-model.enabled[quarkus.langchain4j.openai.moderation-model.enabled]`


[.description]
--
Whether the model should be enabled

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_MODERATION_MODEL_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_MODERATION_MODEL_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a| [[quarkus-langchain4j-openai_quarkus.langchain4j.openai.base-url]]`link:#quarkus-langchain4j-openai_quarkus.langchain4j.openai.base-url[quarkus.langchain4j.openai.base-url]`


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.huggingface.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface ChatModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.huggingface.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface EmbeddingModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ FeatureBuildItem feature() {
@BuildStep
public void providerCandidates(BuildProducer<ChatModelProviderCandidateBuildItem> chatProducer,
BuildProducer<EmbeddingModelProviderCandidateBuildItem> embeddingProducer,
BuildProducer<ModerationModelProviderCandidateBuildItem> moderationProducer) {
chatProducer.produce(new ChatModelProviderCandidateBuildItem(PROVIDER));
embeddingProducer.produce(new EmbeddingModelProviderCandidateBuildItem(PROVIDER));
moderationProducer.produce(new ModerationModelProviderCandidateBuildItem(PROVIDER));
BuildProducer<ModerationModelProviderCandidateBuildItem> moderationProducer,
Langchain4jHuggingFaceBuildConfig config) {
if (config.chatModel().enabled().isEmpty() || config.chatModel().enabled().get()) {
chatProducer.produce(new ChatModelProviderCandidateBuildItem(PROVIDER));
}
if (config.embeddingModel().enabled().isEmpty() || config.embeddingModel().enabled().get()) {
embeddingProducer.produce(new EmbeddingModelProviderCandidateBuildItem(PROVIDER));
}
if (config.moderationModel().enabled().isEmpty() || config.moderationModel().enabled().get()) {
moderationProducer.produce(new ModerationModelProviderCandidateBuildItem(PROVIDER));
}
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.quarkiverse.langchain4j.huggingface.deployment;

import static io.quarkus.runtime.annotations.ConfigPhase.BUILD_TIME;

import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(phase = BUILD_TIME)
@ConfigMapping(prefix = "quarkus.langchain4j.huggingface")
public interface Langchain4jHuggingFaceBuildConfig {

/**
* Chat model related settings
*/
ChatModelBuildConfig chatModel();

/**
* Embedding model related settings
*/
EmbeddingModelBuildConfig embeddingModel();

/**
* Moderation model related settings
*/
ModerationModelBuildConfig moderationModel();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.huggingface.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface ModerationModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.ollama.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface ChatModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.ollama.deployment;

import static io.quarkus.runtime.annotations.ConfigPhase.BUILD_TIME;

import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(phase = BUILD_TIME)
@ConfigMapping(prefix = "quarkus.langchain4j.ollama")
public interface Langchain4jOllamaOpenAiBuildConfig {

/**
* Chat model related settings
*/
ChatModelBuildConfig chatModel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import jakarta.enterprise.context.ApplicationScoped;

import io.quarkiverse.langchain4j.deployment.items.ChatModelProviderCandidateBuildItem;
import io.quarkiverse.langchain4j.deployment.items.ModerationModelProviderCandidateBuildItem;
import io.quarkiverse.langchain4j.deployment.items.SelectedChatModelProviderBuildItem;
import io.quarkiverse.langchain4j.ollama.runtime.OllamaRecorder;
import io.quarkiverse.langchain4j.ollama.runtime.config.Langchain4jOllamaConfig;
Expand All @@ -30,11 +29,10 @@ FeatureBuildItem feature() {

@BuildStep
public void providerCandidates(BuildProducer<ChatModelProviderCandidateBuildItem> chatProducer,
// BuildProducer<EmbeddingModelProviderCandidateBuildItem> embeddingProducer,
BuildProducer<ModerationModelProviderCandidateBuildItem> moderationProducer) {
chatProducer.produce(new ChatModelProviderCandidateBuildItem(PROVIDER));
// embeddingProducer.produce(new EmbeddingModelProviderCandidateBuildItem(PROVIDER));
// moderationProducer.produce(new ModerationModelProviderCandidateBuildItem(PROVIDER));
Langchain4jOllamaOpenAiBuildConfig config) {
if (config.chatModel().enabled().isEmpty() || config.chatModel().enabled().get()) {
chatProducer.produce(new ChatModelProviderCandidateBuildItem(PROVIDER));
}
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ FeatureBuildItem feature() {
@BuildStep
public void providerCandidates(BuildProducer<ChatModelProviderCandidateBuildItem> chatProducer,
BuildProducer<EmbeddingModelProviderCandidateBuildItem> embeddingProducer,
BuildProducer<ModerationModelProviderCandidateBuildItem> moderationProducer) {
chatProducer.produce(new ChatModelProviderCandidateBuildItem(PROVIDER));
embeddingProducer.produce(new EmbeddingModelProviderCandidateBuildItem(PROVIDER));
moderationProducer.produce(new ModerationModelProviderCandidateBuildItem(PROVIDER));
BuildProducer<ModerationModelProviderCandidateBuildItem> moderationProducer,
Langchain4jAzureOpenAiBuildConfig config) {
if (config.chatModel().enabled().isEmpty() || config.chatModel().enabled().get()) {
chatProducer.produce(new ChatModelProviderCandidateBuildItem(PROVIDER));
}
if (config.embeddingModel().enabled().isEmpty() || config.embeddingModel().enabled().get()) {
embeddingProducer.produce(new EmbeddingModelProviderCandidateBuildItem(PROVIDER));
}
if (config.moderationModel().enabled().isEmpty() || config.moderationModel().enabled().get()) {
moderationProducer.produce(new ModerationModelProviderCandidateBuildItem(PROVIDER));
}
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.azure.openai.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface ChatModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.azure.openai.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface EmbeddingModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.quarkiverse.langchain4j.azure.openai.deployment;

import static io.quarkus.runtime.annotations.ConfigPhase.BUILD_TIME;

import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(phase = BUILD_TIME)
@ConfigMapping(prefix = "quarkus.langchain4j.azure-openai")
public interface Langchain4jAzureOpenAiBuildConfig {

/**
* Chat model related settings
*/
ChatModelBuildConfig chatModel();

/**
* Embedding model related settings
*/
EmbeddingModelBuildConfig embeddingModel();

/**
* Moderation model related settings
*/
ModerationModelBuildConfig moderationModel();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.azure.openai.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface ModerationModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.openai.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface ChatModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.openai.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface EmbeddingModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.quarkiverse.langchain4j.openai.deployment;

import static io.quarkus.runtime.annotations.ConfigPhase.BUILD_TIME;

import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

@ConfigRoot(phase = BUILD_TIME)
@ConfigMapping(prefix = "quarkus.langchain4j.openai")
public interface Langchain4jOpenAiBuildConfig {

/**
* Chat model related settings
*/
ChatModelBuildConfig chatModel();

/**
* Embedding model related settings
*/
EmbeddingModelBuildConfig embeddingModel();

/**
* Moderation model related settings
*/
ModerationModelBuildConfig moderationModel();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkiverse.langchain4j.openai.deployment;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;

@ConfigGroup
public interface ModerationModelBuildConfig {

/**
* Whether the model should be enabled
*/
@ConfigDocDefault("true")
Optional<Boolean> enabled();
}
Loading

0 comments on commit aa3f9d4

Please sign in to comment.