You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Spring Boot AI for LLM base application. My company hosted its LLM models at https://dummy-server.xyz.com/. To test how it works, I have taken an example from Spring AI official site and tried from locally. But getting the below error. I have tried to bypass the SSL certificate validation, but that is also not working. Any idea how to resolve it? Please find the error message and my code.
@RestController
public class ChatController {
private final OpenAiChatModel chatModel;
@Autowired
public ChatController(@Qualifier("openAiChatModel") OpenAiChatModel chatModel) {
this.chatModel = chatModel;
}
@GetMapping("/ai/generate")
public Map<String,String> generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
return Map.of("generation", this.chatModel.call(message));
}
@GetMapping("/ai/generateStream")
public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
Prompt prompt = new Prompt(new UserMessage(message));
return this.chatModel.stream(prompt);
}
}
@Configuration
public class ChatClientConfig {
@Bean
public OpenAiChatModel openAiChatModel(@Qualifier("unsafeWebClientBuilder") WebClient unsafeWebClientBuilder) {
OpenAiApi openAiApi = new OpenAiApi("https://dummy-server.xyz.com/","OTBjZWUxMjAtYWZkNi00Mm5sdsGH", RestClient.builder(),unsafeWebClientBuilder.mutate());
return new OpenAiChatModel(openAiApi);
}
}
@Configuration
public class UnsafeWebClientConfig {
@Bean
public WebClient unsafeWebClientBuilder() throws NoSuchAlgorithmException, KeyManagementException {
HttpClient httpClient = HttpClient.create()
.secure(sslContextSpec -> {
try {
sslContextSpec.sslContext(SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build());
} catch (SSLException e) {
throw new RuntimeException("Failed to create SSL context", e);
}
});
return WebClient.builder()
.clientConnector(new ReactorClientHttpConnector(httpClient))
.build();
}
}
To bypass certificate I tried other methods also available on the web, like "X509Certificate"
Error:
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://dummy-server.xyz.com/v1/v1/chat/completions": PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'chatController' defined in file [C:\Users\Administrator\Documents\spring-ai-multi-llm-chat-svc-main\spring-ai-multi-llm-chat-svc-main\target\classes\com\raj\nola\llm\chat\controller\ChatController.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'openAiChatModel' defined in class path resource [com/raj/nola/llm/chat/controller/OpenAiClientConfig.class]: Unsatisfied dependency expressed through method 'openAiChatModel' parameter 0: Error creating bean with name 'openAiApi' defined in class path resource [com/raj/nola/llm/chat/controller/OpenAiClientConfig.class]: Failed to instantiate [org.springframework.ai.openai.api.OpenAiApi]: Factory method 'openAiApi' threw exception with message: class org.springframework.web.reactive.function.client.DefaultWebClient cannot be cast to class org.springframework.web.reactive.function.client.WebClient$Builder (org.springframework.web.reactive.function.client.DefaultWebClient and org.springframework.web.reactive.function.client.WebClient$Builder are in unnamed module of loader 'app')
The interesting thing is same endpoint I can use from Python. I tried this simple code and it works like a charm.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am using Spring Boot AI for LLM base application. My company hosted its LLM models at https://dummy-server.xyz.com/. To test how it works, I have taken an example from Spring AI official site and tried from locally. But getting the below error. I have tried to bypass the SSL certificate validation, but that is also not working. Any idea how to resolve it? Please find the error message and my code.
To bypass certificate I tried other methods also available on the web, like "X509Certificate"
Error:
The interesting thing is same endpoint I can use from Python. I tried this simple code and it works like a charm.
I am not sure how to resolve this issue. So if anyone can help.
Beta Was this translation helpful? Give feedback.
All reactions