|
33 | 33 | import org.apache.hc.client5.http.classic.methods.HttpPost; |
34 | 34 | import org.apache.hc.core5.http.ContentType; |
35 | 35 | import org.apache.hc.core5.http.io.entity.StringEntity; |
36 | | -import org.apache.hc.core5.http.message.BasicClassicHttpRequest; |
37 | 36 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; |
38 | 37 |
|
39 | 38 | /** Client to execute requests to the orchestration service. */ |
@@ -135,16 +134,15 @@ public OrchestrationChatResponse chatCompletion( |
135 | 134 | @Nonnull |
136 | 135 | public CompletionPostResponse executeRequest(@Nonnull final CompletionPostRequest request) |
137 | 136 | throws OrchestrationClientException { |
138 | | - final BasicClassicHttpRequest postRequest = new HttpPost("/completion"); |
| 137 | + final String jsonRequest; |
139 | 138 | try { |
140 | | - val json = JACKSON.writeValueAsString(request); |
141 | | - log.debug("Serialized request into JSON payload: {}", json); |
142 | | - postRequest.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); |
| 139 | + jsonRequest = JACKSON.writeValueAsString(request); |
| 140 | + log.debug("Serialized request into JSON payload: {}", jsonRequest); |
143 | 141 | } catch (final JsonProcessingException e) { |
144 | 142 | throw new OrchestrationClientException("Failed to serialize request parameters", e); |
145 | 143 | } |
146 | 144 |
|
147 | | - return executeRequest(postRequest); |
| 145 | + return executeRequest(jsonRequest); |
148 | 146 | } |
149 | 147 |
|
150 | 148 | /** |
@@ -180,29 +178,31 @@ public OrchestrationChatResponse executeRequestFromJsonModuleConfig( |
180 | 178 | try { |
181 | 179 | moduleConfigJson = JACKSON.readTree(moduleConfig); |
182 | 180 | } catch (JsonProcessingException e) { |
183 | | - throw new IllegalArgumentException("The provided module configuration is not valid JSON", e); |
| 181 | + throw new IllegalArgumentException( |
| 182 | + "The provided module configuration is not valid JSON: " + moduleConfig, e); |
184 | 183 | } |
185 | 184 | requestJson.set("orchestration_config", moduleConfigJson); |
186 | 185 |
|
187 | | - val postRequest = new HttpPost("/completion"); |
188 | 186 | final String body; |
189 | 187 | try { |
190 | 188 | body = JACKSON.writeValueAsString(requestJson); |
191 | 189 | } catch (JsonProcessingException e) { |
192 | 190 | throw new OrchestrationClientException("Failed to serialize request to JSON", e); |
193 | 191 | } |
194 | | - postRequest.setEntity(new StringEntity(body, ContentType.APPLICATION_JSON)); |
195 | | - return new OrchestrationChatResponse(executeRequest(postRequest)); |
| 192 | + return new OrchestrationChatResponse(executeRequest(body)); |
196 | 193 | } |
197 | 194 |
|
198 | 195 | @Nonnull |
199 | | - CompletionPostResponse executeRequest(@Nonnull final BasicClassicHttpRequest request) { |
| 196 | + CompletionPostResponse executeRequest(@Nonnull final String request) { |
| 197 | + val postRequest = new HttpPost("/completion"); |
| 198 | + postRequest.setEntity(new StringEntity(request, ContentType.APPLICATION_JSON)); |
| 199 | + |
200 | 200 | try { |
201 | 201 | val destination = deployment.get().destination(); |
202 | 202 | log.debug("Using destination {} to connect to orchestration service", destination); |
203 | 203 | val client = ApacheHttpClient5Accessor.getHttpClient(destination); |
204 | 204 | return client.execute( |
205 | | - request, new OrchestrationResponseHandler<>(CompletionPostResponse.class)); |
| 205 | + postRequest, new OrchestrationResponseHandler<>(CompletionPostResponse.class)); |
206 | 206 | } catch (NoSuchElementException |
207 | 207 | | DestinationAccessException |
208 | 208 | | DestinationNotFoundException |
|
0 commit comments