|
8 | 8 | import okhttp3.OkHttpClient; |
9 | 9 | import org.apache.commons.lang3.ObjectUtils; |
10 | 10 | import org.apache.commons.lang3.StringUtils; |
11 | | -import org.devlive.sdk.openai.exception.ParamException; |
12 | 11 | import org.devlive.sdk.openai.interceptor.DefaultInterceptor; |
13 | 12 | import retrofit2.Retrofit; |
14 | 13 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; |
@@ -102,30 +101,21 @@ public OpenAiClientBuilder unit(TimeUnit unit) |
102 | 101 |
|
103 | 102 | public OpenAiClientBuilder client(OkHttpClient client) |
104 | 103 | { |
105 | | - DefaultInterceptor interceptor = new DefaultInterceptor(); |
106 | | - interceptor.setApiKey(this.apiKey); |
107 | 104 | if (ObjectUtils.isEmpty(client)) { |
108 | 105 | log.warn("No client, creating default client"); |
109 | 106 | client = new OkHttpClient.Builder() |
110 | | - .addInterceptor(interceptor) |
111 | 107 | .connectTimeout(this.timeout, this.unit) |
112 | 108 | .writeTimeout(this.timeout, this.unit) |
113 | 109 | .readTimeout(this.timeout, this.unit) |
114 | 110 | .callTimeout(this.timeout, this.unit) |
115 | 111 | .build(); |
116 | 112 | } |
117 | | - |
118 | | - if (client.interceptors().size() <= 0) { |
119 | | - throw new ParamException("No interceptors available"); |
120 | | - } |
121 | | - |
122 | | - long count = client.interceptors() |
123 | | - .stream() |
124 | | - .filter(inter -> inter instanceof DefaultInterceptor) |
125 | | - .count(); |
126 | | - if (count <= 0) { |
127 | | - throw new ParamException("Must inject DefaultInterceptor"); |
128 | | - } |
| 113 | + // Add default interceptor |
| 114 | + DefaultInterceptor interceptor = new DefaultInterceptor(); |
| 115 | + interceptor.setApiKey(this.apiKey); |
| 116 | + client = client.newBuilder() |
| 117 | + .addInterceptor(interceptor) |
| 118 | + .build(); |
129 | 119 | this.client = client; |
130 | 120 | return this; |
131 | 121 | } |
|
0 commit comments