Skip to content

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

Open
@xiaolei

Description

@xiaolei

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();
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions