Skip to content

Conversation

@JGoP-L
Copy link
Contributor

@JGoP-L JGoP-L commented Dec 30, 2025

Fixes #95

Description

This PR replaces the OpenAI Java SDK dependency with a native HTTP client implementation, enabling support for multiple OpenAI-compatible API providers.

Background

The previous implementation relied on the openai-java SDK, which:

  • Added unnecessary dependency overhead
  • Limited flexibility for different API providers
  • Made it difficult to support OpenAI-compatible services

Changes Made

  • Removed openai-java dependency from agentscope-core/pom.xml
  • Added native HTTP client implementation using OkHttp
    • OpenAIClient.java - HTTP client wrapper
    • OpenAIConfig.java - configuration class
  • Added OpenAI DTOs for request/response
    • dto/OpenAIRequest.java, dto/OpenAIResponse.java
    • dto/OpenAIMessage.java, dto/OpenAIToolCall.java, etc.
  • Added provider capability support
    • ProviderCapability.java - defines tool_choice support per provider
  • Refactored OpenAIChatModel to be stateless and HTTP-based
  • Added support for multiple providers:
    • GLM (Zhipu AI)
    • DeepSeek
    • DashScope (Alibaba)
    • OpenRouter
    • Any OpenAI-compatible API

Testing

  • Existing E2E tests pass with native HTTP client
  • Test coverage: 80% (overall), 76% for formatter.openai package
  • All provider-specific tests included

Breaking Changes

None. The public API remains unchanged; only the internal implementation switches from SDK to HTTP.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Code is ready for review

@JGoP-L JGoP-L requested review from a team and Copilot December 30, 2025 07:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces the OpenAI Java SDK with a native HTTP client implementation to support multiple OpenAI-compatible API providers. The change eliminates SDK dependency overhead while maintaining backward compatibility with the public API.

Key Changes:

  • Removed openai-java SDK dependency
  • Implemented native HTTP client using OkHttp
  • Added comprehensive OpenAI DTOs for request/response handling
  • Introduced provider capability support for different API vendors
  • Refactored OpenAIChatModel to be stateless and HTTP-based

Reviewed changes

Copilot reviewed 95 out of 103 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
OpenAIClientExceptionTest.java Tests exception handling for HTTP status codes
OpenAIChatModelTest.java Integration tests with MockWebServer
OpenAIChatModelE2ETest.java E2E tests against real OpenRouter API
GeminiChatModelE2ETest.java E2E tests for Gemini via OpenRouter
GLMChatModelE2ETest.java E2E tests for GLM API compatibility
GLMApiDebugTest.java Debug tests for GLM API behavior
DoubaoE2ETest.java E2E tests for Doubao provider
DeepSeekChatModelE2ETest.java E2E tests for DeepSeek API
ResponseFormatTest.java Tests for structured output DTOs
OpenAIBuilderIndependenceTest.java Builder pattern independence tests
ProviderCapabilityTest.java Tests for provider capability detection
OpenAIToolsHelperTest.java Tests for tools helper functionality
OpenAIStreamingToolCallTest.java Tests for streaming tool call parsing
OpenAIResponseParserTest.java Tests for response parsing logic
OpenAIMultiAgentFormatterTest.java Tests for multi-agent message formatting
OpenAIMessageConverterTest.java Tests for message conversion
OpenAIConverterUtilsTest.java Tests for converter utilities
OpenAIConversationMergerTest.java Tests for conversation merging
OpenAIChatFormatterTest.java Tests for chat message formatting
Multiple provider files License header updates and test timeout increases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (modelName == null || modelName.isEmpty()) {
// Try common OpenRouter GLM model names
String[] openRouterGLMModels = {
"z-ai/glm-4.6", // GLM 4.6
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

Model name format appears incorrect. Based on the OpenRouter API documentation and provider patterns used elsewhere in the codebase, the correct format should use zhipu/ prefix (e.g., zhipu/glm-4) instead of z-ai/. This inconsistency may cause model lookup failures when using OpenRouter.

Copilot generated this review using guidance from repository custom instructions.
@AlbumenJ AlbumenJ requested a review from Copilot December 30, 2025 08:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 95 out of 103 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

class VisionToolIntegrationE2ETest {

private static final Duration TEST_TIMEOUT = Duration.ofSeconds(60);
private static final Duration TEST_TIMEOUT = Duration.ofSeconds(180);
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

Test timeout was increased from 60 to 180 seconds. This significant change should be documented in the PR description or code comments to explain why such a long timeout is needed. Consider if this indicates a performance issue that should be addressed separately, or if the tests genuinely require this much time for API calls.

Copilot generated this review using guidance from repository custom instructions.
class ToolSystemE2ETest {

private static final Duration TEST_TIMEOUT = Duration.ofSeconds(45);
private static final Duration TEST_TIMEOUT = Duration.ofSeconds(180);
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

Test timeout was increased from 45 to 180 seconds. This is a 4x increase which should be justified. Document why such a long timeout is required and consider if tests can be optimized or if this indicates issues with the API provider responses.

Copilot generated this review using guidance from repository custom instructions.
@AlbumenJ AlbumenJ requested a review from Copilot December 30, 2025 09:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 95 out of 103 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AlbumenJ AlbumenJ requested a review from Copilot December 30, 2025 13:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 95 out of 103 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…usage

This commit adds two enhancements to the HTTP transport layer:

1. SSL Certificate Verification Control (fixes agentscope-ai#344):
   - Add `ignoreSsl` option to HttpTransportConfig for development/testing
   - Implement trust-all SSL context in OkHttpTransport
   - Support custom OkHttpClient injection via builder

2. Default Token Usage in Streaming (fixes agentscope-ai#355):
   - Automatically include `stream_options: {"include_usage": true}`
     for all streaming API calls
   - Ensures token usage is available in final response chunk
   - Compatible with OpenAI, DashScope, Bailian, and other providers

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Use okhttp to replace OpenAI Model SDK

1 participant