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

[FEATURE] ZhipuAiChatModel does NOT support PROXY #1032

Open
andrew219219 opened this issue Apr 28, 2024 · 0 comments
Open

[FEATURE] ZhipuAiChatModel does NOT support PROXY #1032

andrew219219 opened this issue Apr 28, 2024 · 0 comments
Labels
enhancement New feature or request P3 Medium priority

Comments

@andrew219219
Copy link

Is your feature request related to a problem? Please describe.

ZhipuAiChatModel cannot be used in office environments where accessing the public network requires a proxy.

Describe the solution you'd like

The OkHttp lib has many properties including proxy\timeout\log\auth, but it can't be set when creating ZhipuAiChatModel. I think more properties will be added to ZhipuAiChatModel's contructor is a good idea to solve this problem.

Describe alternatives you've considered

Additional context

// constructor of ZhipuAiChatModel
@Builder
    public ZhipuAiChatModel(
            String baseUrl,
            String apiKey,
            Double temperature,
            Double topP,
            String model,
            Integer maxRetries,
            Integer maxToken,
            Boolean logRequests,
            Boolean logResponses    // PROXY(and timeout properties) CAN BE ADDED HERE!
    ) {
        this.baseUrl = getOrDefault(baseUrl, "https://open.bigmodel.cn/");
        this.temperature = getOrDefault(temperature, 0.7);
        this.topP = topP;
        this.model = getOrDefault(model, ChatCompletionModel.GLM_4.toString());
        this.maxRetries = getOrDefault(maxRetries, 3);
        this.maxToken = getOrDefault(maxToken, 512);
        this.client = ZhipuAiClient.builder()
                .baseUrl(this.baseUrl)
                .apiKey(apiKey)
                .logRequests(getOrDefault(logRequests, false))
                .logResponses(getOrDefault(logResponses, false))
                .build();
}
// constructor of ZhipuAiClient
public ZhipuAiClient(Builder builder) {
        this.baseUrl = builder.baseUrl;
        OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder()
                .callTimeout(builder.callTimeout)
                .connectTimeout(builder.connectTimeout)
                .readTimeout(builder.readTimeout)
                .writeTimeout(builder.writeTimeout)
                .addInterceptor(new AuthorizationInterceptor(builder.apiKey)); // PROXY CAN BE ADDED HERE!

        if (builder.logRequests) {
            okHttpClientBuilder.addInterceptor(new RequestLoggingInterceptor());
        }

        this.logResponses = builder.logResponses;
        if (builder.logResponses) {
            okHttpClientBuilder.addInterceptor(new ResponseLoggingInterceptor());
        }

        this.okHttpClient = okHttpClientBuilder.build();
        Retrofit retrofit = (new Retrofit.Builder())
                .baseUrl(formattedUrlForRetrofit(this.baseUrl))
                .client(this.okHttpClient)
                .addConverterFactory(GsonConverterFactory.create(GSON))
                .build();
        this.zhipuAiApi = retrofit.create(ZhipuAiApi.class);
    }
@andrew219219 andrew219219 added the enhancement New feature or request label Apr 28, 2024
@langchain4j langchain4j added the P3 Medium priority label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P3 Medium priority
Projects
None yet
Development

No branches or pull requests

2 participants