Skip to content

Commit 4092abb

Browse files
committed
Use JdkClientHttpRequestFactory with HttpClient.Redirect.NORMAL as the fallback when aiModelHttpRequestFactory is absent, so CDN redirects are followed in ONNX-only projects. Netty is still used when present.
1 parent 8f44d67 commit 4092abb

File tree

2 files changed

+15
-8
lines changed
  • embabel-agent-autoconfigure/models/embabel-agent-onnx-autoconfigure/src/main/kotlin/com/embabel/agent/config/models/onnx/embeddings
  • embabel-agent-starters/embabel-agent-starter-onnx

2 files changed

+15
-8
lines changed

embabel-agent-autoconfigure/models/embabel-agent-onnx-autoconfigure/src/main/kotlin/com/embabel/agent/config/models/onnx/embeddings/OnnxEmbeddingAutoConfiguration.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.embabel.agent.onnx.embeddings.OnnxEmbeddingService
2020
import com.embabel.common.ai.autoconfig.ProviderInitialization
2121
import com.embabel.common.ai.autoconfig.RegisteredModel
2222
import jakarta.annotation.PreDestroy
23+
import java.net.http.HttpClient
2324
import java.nio.file.Path
2425
import org.slf4j.LoggerFactory
2526
import org.springframework.beans.factory.ObjectProvider
@@ -31,6 +32,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
3132
import org.springframework.context.annotation.Bean
3233
import org.springframework.context.annotation.Configuration
3334
import org.springframework.http.client.ClientHttpRequestFactory
35+
import org.springframework.http.client.JdkClientHttpRequestFactory
3436
import org.springframework.web.client.RestClient
3537

3638
/**
@@ -41,9 +43,10 @@ import org.springframework.web.client.RestClient
4143
* via [ConfigurableBeanFactory.registerSingleton] so the bean name
4244
* matches the model name used in [ProviderInitialization].
4345
*
44-
* Uses the shared `aiModelHttpRequestFactory` (if available) for model
45-
* downloads, consistent with other providers. Falls back to default
46-
* JDK-based `RestClient` when the factory bean is absent.
46+
* Uses the shared `aiModelHttpRequestFactory` (Netty-backed, if available) for model
47+
* downloads, consistent with other providers. Falls back to a [JdkClientHttpRequestFactory]
48+
* configured with [HttpClient.Redirect.NORMAL] so that HuggingFace CDN redirects are
49+
* followed even when no other starter brings Netty onto the classpath.
4750
*/
4851
@Configuration(proxyBeanMethods = false)
4952
@ConditionalOnClass(OnnxEmbeddingService::class)
@@ -68,7 +71,15 @@ class OnnxEmbeddingAutoConfiguration(
6871
fun onnxEmbeddingInitializer(properties: OnnxEmbeddingProperties): ProviderInitialization {
6972
val cacheDir = Path.of(properties.cacheDir, properties.modelName)
7073
val restClient = RestClient.builder()
71-
.also { b -> requestFactory.ifAvailable { b.requestFactory(it) } }
74+
.requestFactory(
75+
requestFactory.getIfAvailable {
76+
JdkClientHttpRequestFactory(
77+
HttpClient.newBuilder()
78+
.followRedirects(HttpClient.Redirect.NORMAL)
79+
.build()
80+
)
81+
}
82+
)
7283
.build()
7384
val modelPath = OnnxModelLoader.resolve(properties.modelUri, cacheDir, "model.onnx", restClient)
7485
val tokenizerPath = OnnxModelLoader.resolve(properties.tokenizerUri, cacheDir, "tokenizer.json", restClient)

embabel-agent-starters/embabel-agent-starter-onnx/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
<groupId>com.embabel.agent</groupId>
2929
<artifactId>embabel-agent-onnx-autoconfigure</artifactId>
3030
</dependency>
31-
<dependency>
32-
<groupId>com.embabel.agent</groupId>
33-
<artifactId>embabel-agent-netty-client-autoconfigure</artifactId>
34-
</dependency>
3531
</dependencies>
3632

3733
</project>

0 commit comments

Comments
 (0)