This commit is contained in:
Mohammad Zwaib
2026-07-16 00:34:42 +02:00
parent 7cef62cc48
commit 5d6edef396
4 changed files with 84 additions and 9 deletions
@@ -96,10 +96,56 @@ public class AzureMistralService {
+ " Retry-After = "+ e.getHeaders().getFirst("Retry-After")
+ " Body = "+ e.getResponseBodyAsString());
}catch (Exception e) {
throw new RuntimeException("Azure Mistral request failed: "+ e.getMessage());
}
}
public String askMistral(List<Map<String, Object>> messages, int maxTokens) {
try {
String url = endPoint + "/openai/v1/chat/completions";
System.out.println(">>> MODELL = " + deployment + " | URL = " + url);
Map<String, Object> requstBody = Map.of(
"model", "gpt-5-mini-datazone",
"messages", messages,
"reasoning_effort", "minimal",
"max_completion_tokens", maxTokens
);
long c0 = System.currentTimeMillis();
String response = webClient.post()
.uri(url)
.header("api-key", apiKey)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(requstBody)
.retrieve()
.bodyToMono(String.class)
.retryWhen(
Retry.backoff(2, Duration.ofSeconds(5))
.filter(ex -> ex instanceof WebClientResponseException.TooManyRequests)
.onRetryExhaustedThrow((spec, sig) -> sig.failure())
)
.block();
System.out.println(" askMistral daurte = " + (System.currentTimeMillis() - c0) + "ms");
if (response == null || response.isBlank()) {
throw new RuntimeException("Leere Antwort von Azure Mistral");
}
JsonNode root = objectMapper.readTree(response);
return root.path("choices").get(0).get("message").path("content").asText();
} catch (WebClientResponseException e) {
throw new RuntimeException("Azure Mistral request failed: " + e.getStatusCode()
+ " Retry-After = " + e.getHeaders().getFirst("Retry-After")
+ " Body = " + e.getResponseBodyAsString());
} catch (Exception e) {
throw new RuntimeException("Azure Mistral request failed: " + e.getMessage());
}
}
}