-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[OPIK-5689] [BE] fix: stop retrying rate-limited LLM calls and reduce log verbosity #6132
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ public ChatCompletionResponse create(@NonNull ChatCompletionRequest rawRequest, | |
| providerError | ||
| .ifPresent(llmProviderError -> failHandlingLLMProviderError(runtimeException, llmProviderError)); | ||
|
|
||
| log.error(UNEXPECTED_ERROR_CALLING_LLM_PROVIDER, runtimeException); | ||
| log.warn(UNEXPECTED_ERROR_CALLING_LLM_PROVIDER, runtimeException); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry as I didn't notice on the first review. I'd maybe keep these two changes on this file at error level , as they're real errors and re-thrown. Even better, probably these logs can and should be removed as the exception below should be printed somewhere if not caught or if logged by some Dropwizard error handle. I'd say the best scenario would be removing these two if you confirm logs are duplicated. |
||
| throw new InternalServerErrorException(buildDetailedErrorMessage(runtimeException), runtimeException); | ||
| } | ||
|
|
||
ldaugusto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -117,7 +117,7 @@ public ChatResponse scoreTrace(@NonNull ChatRequest chatRequest, | |
| providerError | ||
| .ifPresent(llmProviderError -> failHandlingLLMProviderError(runtimeException, llmProviderError)); | ||
|
|
||
| log.error(UNEXPECTED_ERROR_CALLING_LLM_PROVIDER, runtimeException); | ||
| log.warn(UNEXPECTED_ERROR_CALLING_LLM_PROVIDER, runtimeException); | ||
| throw new InternalServerErrorException(buildDetailedErrorMessage(runtimeException), runtimeException); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.comet.opik.infrastructure.llm.openai; | ||
|
|
||
| import io.dropwizard.jersey.errors.ErrorMessage; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class OpenAiErrorMessageTest { | ||
|
|
||
| static Stream<Arguments> errorCodeMappings() { | ||
| return Stream.of( | ||
| Arguments.of("invalid_api_key", 401, "some error message"), | ||
| Arguments.of("internal_error", 500, "some error message"), | ||
| Arguments.of("invalid_request_error", 400, "some error message"), | ||
| Arguments.of("rate_limit_exceeded", 429, "some error message"), | ||
| Arguments.of("insufficient_quota", 402, "some error message"), | ||
| Arguments.of("model_not_found", 404, "some error message")); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("errorCodeMappings") | ||
| void toErrorMessageWhenErrorCodeReturnsExpectedHttpStatus(String errorCode, int expectedHttpStatus, | ||
| String message) { | ||
| var error = new OpenAiErrorMessage( | ||
| new OpenAiErrorMessage.OpenAiError(message, errorCode, "some_type")); | ||
|
|
||
ldaugusto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var expected = new ErrorMessage(expectedHttpStatus, message); | ||
| var actual = error.toErrorMessage(); | ||
|
|
||
| assertThat(actual) | ||
| .usingRecursiveComparison() | ||
| .isEqualTo(expected); | ||
| } | ||
|
|
||
| static Stream<Arguments> unknownErrorCodeCases() { | ||
| return Stream.of( | ||
| Arguments.of("unknown_code", "unknown error"), | ||
| Arguments.of("some_other_error", "another error")); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("unknownErrorCodeCases") | ||
| void toErrorMessageWhenErrorCodeUnknownReturns500WithDetails(String errorCode, String message) { | ||
| var error = new OpenAiErrorMessage( | ||
| new OpenAiErrorMessage.OpenAiError(message, errorCode, "some_type")); | ||
|
|
||
| var expected = new ErrorMessage(500, message, errorCode); | ||
| var actual = error.toErrorMessage(); | ||
|
|
||
| assertThat(actual) | ||
| .usingRecursiveComparison() | ||
| .isEqualTo(expected); | ||
| } | ||
|
|
||
| static Stream<Arguments> nullMessageCases() { | ||
| return Stream.of( | ||
| Arguments.of("rate_limit_exceeded"), | ||
| Arguments.of("unknown_code")); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("nullMessageCases") | ||
| void toErrorMessageWhenMessageNullReturnsNull(String errorCode) { | ||
| var error = new OpenAiErrorMessage( | ||
| new OpenAiErrorMessage.OpenAiError(null, errorCode, "some_type")); | ||
|
|
||
| assertThat(error.toErrorMessage()).isNull(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.