Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public OpenAIException(String message, int statusCode, String errorCode, String
* @return Appropriate exception subclass
*/
public static OpenAIException create(
int statusCode, String message, String errorCode, String responseBody) {
Integer statusCode, String message, String errorCode, String responseBody) {
if (null == statusCode) {
// When no status code is available, the default is 418
statusCode = 418;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the HTTP status code 418 ("I'm a teapot") as a default is a bit unusual and can be confusing for developers who are not familiar with this context. To improve readability and maintainability, it would be better to define this as a named constant, for example private static final int DEFAULT_STATUS_CODE_WHEN_NULL = 418;, and add a comment explaining its purpose as a placeholder for when no status code is available. Since adding a constant might be outside the scope of this change, at a minimum, a code comment explaining the choice of 418 would be beneficial.

}
return switch (statusCode) {
case 400 -> new BadRequestException(message, errorCode, responseBody);
case 401 -> new AuthenticationException(message, errorCode, responseBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ public Mono<McpClientWrapper> buildAsync() {

McpSchema.Implementation clientInfo =
new McpSchema.Implementation(
"agentscope-java", "AgentScope Java Framework", "1.0.10-SNAPSHOT");
"agentscope-java",
"AgentScope Java Framework",
"1.0.10-SNAPSHOT");

McpSchema.ClientCapabilities clientCapabilities =
McpSchema.ClientCapabilities.builder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void testVersionConstant() {
// Verify version constant is set
Assertions.assertNotNull(Version.VERSION, "VERSION constant should not be null");
Assertions.assertFalse(Version.VERSION.isEmpty(), "VERSION constant should not be empty");
Assertions.assertEquals("1.0.10-SNAPSHOT", Version.VERSION, "VERSION should match current version");
Assertions.assertEquals(
"1.0.10-SNAPSHOT", Version.VERSION, "VERSION should match current version");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,4 +882,35 @@ void testCustomEndpointPathInStreamCall() throws Exception {
recordedRequest.getPath().contains("/v4/chat/completions"),
"Stream path should contain custom endpoint path: " + recordedRequest.getPath());
}

@Test
@DisplayName("Should throw OpenAIException when handle custom endpoint path in stream call")
void testThrowOpenAIExceptionWhenCustomEndpointPathInStreamCall() {
String sseResponse = "";

mockServer.enqueue(
new MockResponse()
.setBody(sseResponse)
.setResponseCode(301)
.setHeader("Content-Type", "text/event-stream"));

OpenAIRequest request =
OpenAIRequest.builder()
.model("gpt-4")
.messages(
List.of(
OpenAIMessage.builder()
.role("user")
.content("Hello")
.build()))
.build();

// Use custom endpoint path for stream call
GenerateOptions options =
GenerateOptions.builder().endpointPath("/v4/chat/completions").build();

assertThrows(
OpenAIException.class,
() -> client.stream(TEST_API_KEY, baseUrl, request, options).collectList().block());
}
}
Loading