-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Refactor negative scenario tests. Add exception mapping to OpenAiOfficialChatModel #3310
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
base: main
Are you sure you want to change the base?
Conversation
…istency in AbstractChatModelErrorsTest
…penAiOfficialExceptionMapper` and adjusting maxRetries logic
…3313) This PR contains the following updates: | Package | Change | Age | Confidence | |---|---|---|---| | [com.google.protobuf:protobuf-java-util](https://developers.google.com/protocol-buffers/) ([source](https://redirect.github.com/protocolbuffers/protobuf)) | `3.25.5` -> `3.25.8` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>protocolbuffers/protobuf (com.google.protobuf:protobuf-java-util)</summary> ### [`v3.25.8`](https://redirect.github.com/protocolbuffers/protobuf/compare/v3.25.7...v3.25.8) [Compare Source](https://redirect.github.com/protocolbuffers/protobuf/compare/v3.25.7...v3.25.8) ### [`v3.25.7`](https://redirect.github.com/protocolbuffers/protobuf/compare/v3.25.6...v3.25.7) [Compare Source](https://redirect.github.com/protocolbuffers/protobuf/compare/v3.25.6...v3.25.7) ### [`v3.25.6`](https://redirect.github.com/protocolbuffers/protobuf/compare/v3.25.5...v3.25.6) [Compare Source](https://redirect.github.com/protocolbuffers/protobuf/compare/v3.25.5...v3.25.6) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/langchain4j/langchain4j). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNy4yIiwidXBkYXRlZEluVmVyIjoiNDEuMTcuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
b5fdc1c
to
0b9ac95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpavlov thanks a lot, good idea to abstract away error tests!
*/ | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@Execution(ExecutionMode.CONCURRENT) | ||
public abstract class AbstractChatModelErrorsTest< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep the code written in Java (for all tests)
} | ||
|
||
@Test | ||
public fun should_handle_timeout() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original tests run for a few timeouts (1, 10, 100 ms) to make sure both connect and read timeouts are tested, could you please keep that logic?
...hain4j-core/src/test/kotlin/dev/langchain4j/model/chat/common/AbstractChatModelErrorsTest.kt
Show resolved
Hide resolved
@@ -38,6 +42,7 @@ abstract class OpenAiOfficialBaseChatModel { | |||
protected TokenCountEstimator tokenCountEstimator; | |||
protected List<ChatModelListener> listeners; | |||
protected Set<Capability> supportedCapabilities; | |||
protected int maxRetries = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this required? maxRetries
is set on the OpenAIClientAsync
public RuntimeException mapException(Throwable t) { | ||
if (t instanceof com.openai.errors.OpenAIServiceException httpResponseException) { | ||
final var statusCode = httpResponseException.statusCode(); | ||
return mapHttpStatusCode(new HttpException(statusCode, httpResponseException), statusCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return mapHttpStatusCode(new HttpException(statusCode, httpResponseException), statusCode); | |
return mapHttpStatusCode(httpResponseException, statusCode); |
why adding an extra layer of exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once simplified, please remove new ctors in HttpException
which are not required any more
final var statusCode = httpResponseException.statusCode(); | ||
return mapHttpStatusCode(new HttpException(statusCode, httpResponseException), statusCode); | ||
} else if (t instanceof OpenAIIoException ioException) { | ||
if (t.getCause() instanceof InterruptedIOException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks strange, doesn't OpenAI SDK throw a proper timeout exception?
Issue
Reuse test logic by introducing abstract tests. Catch and fix missing exception mapping in
OpenAiOfficialChatModel
.Change
General checklist
Checklist for adding new maven module
pom.xml
andlangchain4j-bom/pom.xml
Checklist for adding new embedding store integration
{NameOfIntegration}EmbeddingStoreIT
that extends from eitherEmbeddingStoreIT
orEmbeddingStoreWithFilteringIT
{NameOfIntegration}EmbeddingStoreRemovalIT
that extends fromEmbeddingStoreWithRemovalIT
Checklist for changing existing embedding store integration
{NameOfIntegration}EmbeddingStore
works correctly with the data persisted using the latest released version of LangChain4j