Skip to content
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

Enhance QianFanAuthenticator & AuthApi to support custom RestClient.Builder and WebClient.Builder #2523

Open
xiaolei opened this issue Mar 20, 2025 · 0 comments

Comments

@xiaolei
Copy link

xiaolei commented Mar 20, 2025

Constructor of class org.springframework.ai.qianfan.api.auth.QianFanAuthenticator & org.springframework.ai.qianfan.api.auth.AuthApi should allow customization of HTTP clients by accepting RestClient.Builder and WebClient.Builder parameters. This enhancement will provide greater flexibility in configuring HTTP clients according to specific requirements. For example, with the enhancement, developers would be able to configure a proxy in RestClient.Builder.

Expected Behavior

Constructor of class org.springframework.ai.qianfan.api.auth.QianFanAuthenticator & org.springframework.ai.qianfan.api.auth.AuthApi should allow customization of HTTP clients by accepting RestClient.Builder and WebClient.Builder parameters.

Current Behavior

Currently, when creating an instance of org.springframework.ai.qianfan.api.QianFanApi, it is possible to provide custom instances of RestClient.Builder and WebClient.Builder. However, when constructing org.springframework.ai.qianfan.api.auth.QianFanAuthenticator, these custom instances are not utilized. Instead, the superclass constructor does not accept or propagate the provided RestClient.Builder and WebClient.Builder .

Below is the relevant section of the related class, please refer to the comments:

package org.springframework.ai.qianfan.api;

public class QianFanApi extends AuthApi {
// ...
	public QianFanApi(String baseUrl, String apiKey, String secretKey, RestClient.Builder restClientBuilder,
					WebClient.Builder webClientBuilder, ResponseErrorHandler responseErrorHandler) {
                // super constructor should accept `RestClient.Builder` and `WebClient.Builder` as parameters
		**super(apiKey, secretKey);**

		this.restClient = restClientBuilder
				.baseUrl(baseUrl)
				.defaultHeaders(QianFanUtils.defaultHeaders())
				.defaultStatusHandler(responseErrorHandler)
				.build();

		this.webClient = webClientBuilder
				.baseUrl(baseUrl)
				.defaultHeaders(QianFanUtils.defaultHeaders())
				.build();
	}
//...
}
...

package org.springframework.ai.qianfan.api.auth;

public abstract class AuthApi {
        // ...
	protected AuthApi(String apiKey, String secretKey) {
                //  Should accept `RestClient.Builder` and `WebClient.Builder` as parameters
		this.authenticator = QianFanAuthenticator.builder().apiKey(apiKey).secretKey(secretKey).build();
	}
        // ...
}


package org.springframework.ai.qianfan.api.auth;

public class QianFanAuthenticator {
        // Should accept RestClient.builder
	public QianFanAuthenticator(String authUrl, String apiKey, String secretKey) {
		this.apiKey = apiKey;
		this.secretKey = secretKey;
		this.restClient = RestClient.builder().baseUrl(authUrl).build();
	}
}
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

No branches or pull requests

1 participant