From 89de624bf4d63b38375fc2a175e5f27a9d6b8758 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 5 Nov 2024 11:30:47 +0200 Subject: [PATCH] Fix warning about missing model-id in Ollama Fixes: #1043 --- .../ModelIdConfigFallbackInterceptor.java | 21 ++++++++++++++- .../ModelIdConfigRelocateInterceptor.java | 22 +++++++++++++++- .../config/ModelIdToModelNameFunction.java | 26 ------------------- 3 files changed, 41 insertions(+), 28 deletions(-) delete mode 100644 model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdToModelNameFunction.java diff --git a/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdConfigFallbackInterceptor.java b/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdConfigFallbackInterceptor.java index f86d14fb6..bef222edb 100644 --- a/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdConfigFallbackInterceptor.java +++ b/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdConfigFallbackInterceptor.java @@ -1,11 +1,30 @@ package io.quarkiverse.langchain4j.ollama.runtime.config; +import java.util.function.Function; + import io.smallrye.config.FallbackConfigSourceInterceptor; public class ModelIdConfigFallbackInterceptor extends FallbackConfigSourceInterceptor { + private static final Function FALLBACK = new Function<>() { + @Override + public String apply(String name) { + if (!name.startsWith("quarkus.langchain4j.ollama")) { + return name; + } + if (!name.endsWith("model-id")) { + return name; + } + int index = name.lastIndexOf(".model-id"); + if (index < 1) { + return name; + } + return name.substring(0, index) + ".model-name"; + } + }; + public ModelIdConfigFallbackInterceptor() { - super(ModelIdToModelNameFunction.INSTANCE); + super(FALLBACK); } } diff --git a/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdConfigRelocateInterceptor.java b/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdConfigRelocateInterceptor.java index ce5045aed..ec6b99d5a 100644 --- a/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdConfigRelocateInterceptor.java +++ b/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdConfigRelocateInterceptor.java @@ -1,9 +1,29 @@ package io.quarkiverse.langchain4j.ollama.runtime.config; +import java.util.function.Function; + import io.smallrye.config.RelocateConfigSourceInterceptor; public class ModelIdConfigRelocateInterceptor extends RelocateConfigSourceInterceptor { + + private static final Function RELOCATE = new Function<>() { + @Override + public String apply(String name) { + if (!name.startsWith("quarkus.langchain4j.ollama")) { + return name; + } + if (!name.endsWith("model-name")) { + return name; + } + int index = name.lastIndexOf(".model-name"); + if (index < 1) { + return name; + } + return name.substring(0, index) + ".model-id"; + } + }; + public ModelIdConfigRelocateInterceptor() { - super(ModelIdToModelNameFunction.INSTANCE); + super(RELOCATE); } } diff --git a/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdToModelNameFunction.java b/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdToModelNameFunction.java deleted file mode 100644 index 516e9ea39..000000000 --- a/model-providers/ollama/runtime/src/main/java/io/quarkiverse/langchain4j/ollama/runtime/config/ModelIdToModelNameFunction.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.quarkiverse.langchain4j.ollama.runtime.config; - -import java.util.function.Function; - -final class ModelIdToModelNameFunction implements Function { - - static final ModelIdToModelNameFunction INSTANCE = new ModelIdToModelNameFunction(); - - private ModelIdToModelNameFunction() { - } - - @Override - public String apply(String name) { - if (!name.startsWith("quarkus.langchain4j.ollama")) { - return name; - } - if (!name.endsWith("model-id")) { - return name; - } - int index = name.lastIndexOf(".model-id"); - if (index < 1) { - return name; - } - return name.substring(0, index) + ".model-name"; - } -}