Repository navigation
Replies: 1 comment
|
You should not restart the For current Spring AI 2.x, resolve the access token immediately before the request and override the OpenAI options for that call: private final AtomicReference<String> accessToken = new AtomicReference<>();
@Scheduled(fixedDelayString = "PT2M")
void refreshToken() {
accessToken.set(microsoftAuthService.fetchAccessToken());
}
ChatResponse getJoke() {
var token = Objects.requireNonNull(accessToken.get(), "access token not initialized");
return chatClient.prompt()
.system("test1")
.user("joke")
.options(OpenAiChatOptions.builder()
.apiKey(token)
.build())
.call()
.chatResponse();
}This keeps The current reference documents request-time option overrides and API-key management: |
Uh oh!
There was an error while loading. Please reload this page.
How would i restart the chatclient bean if i am using something like this. I need to restart it as i have dynamic api key and i need to replace the spring.ai.openai.api-key every X minutes or on demand.
All reactions