Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embed-model for OpenAI can not have its own base-url / api key #1220

Open
pilhuhn opened this issue Jan 17, 2025 · 1 comment
Open

embed-model for OpenAI can not have its own base-url / api key #1220

pilhuhn opened this issue Jan 17, 2025 · 1 comment

Comments

@pilhuhn
Copy link

pilhuhn commented Jan 17, 2025

I am trying to access 2 different remote OpenAI-API-compatible services for the chat and embed-models.
This fails, as the embedding model does not have its own base-url and api-key

Same applies to imageModel and moderationModel.

I think having those overrides is important as the OpenAI-API is kind of becoming a default API for many LLM-servers (InstructLab , Ollama in OpenAI mode, ..)

The following patch illustrates a potential fix, that works on my laptop :)

---
Index: model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/config/EmbeddingModelConfig.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/config/EmbeddingModelConfig.java b/model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/config/EmbeddingModelConfig.java
--- a/model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/config/EmbeddingModelConfig.java	(revision a8864444916d915b178eda65ee7665934e0ac7e8)
+++ b/model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/config/EmbeddingModelConfig.java	(date 1737111305494)
@@ -31,4 +31,14 @@
      * A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
      */
     Optional<String> user();
+
+    /**
+     * Base URL override for the embedding model
+     */
+    Optional<String> baseUrl();
+
+    /**
+     * Api key override for the embedding model
+     */
+    Optional<String> apiKey();
 }
Index: model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/OpenAiRecorder.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/OpenAiRecorder.java b/model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/OpenAiRecorder.java
--- a/model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/OpenAiRecorder.java	(revision a8864444916d915b178eda65ee7665934e0ac7e8)
+++ b/model-providers/openai/openai-vanilla/runtime/src/main/java/io/quarkiverse/langchain4j/openai/runtime/OpenAiRecorder.java	(date 1737110791953)
@@ -189,8 +189,8 @@
             builder
                     .tlsConfigurationName(openAiConfig.tlsConfigurationName().orElse(null))
                     .configName(configName)
-                    .baseUrl(openAiConfig.baseUrl())
-                    .apiKey(apiKey)
+                    .baseUrl(embeddingModelConfig.baseUrl().orElse(openAiConfig.baseUrl()))
+                    .apiKey(embeddingModelConfig.apiKey().orElse(apiKey))
                     .timeout(openAiConfig.timeout().orElse(Duration.ofSeconds(10)))
                     .maxRetries(openAiConfig.maxRetries())
                     .logRequests(firstOrDefault(false, embeddingModelConfig.logRequests(), openAiConfig.logRequests()))

@geoand
Copy link
Collaborator

geoand commented Jan 17, 2025

Thanks for looking into this!

To be honest, I am not terribly excited about the each component of LangChain4jOpenAiConfig having it's own base URL and api key configuration.
Can you please attach a sample project that you are using and that currently fails? I want to fully understand your use case and how you are trying to implement it.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants