|
30 | 30 | import org.apache.hc.core5.http.message.BasicClassicHttpRequest; |
31 | 31 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; |
32 | 32 |
|
| 33 | +/** |
| 34 | + * Client to execute requests to the orchestration service. Can be configured to hold a default |
| 35 | + * {@link OrchestrationConfig} to be used for all requests. Configuration set on an {@link |
| 36 | + * OrchestrationPrompt} will take precedence upon execution. |
| 37 | + */ |
33 | 38 | @Slf4j |
34 | 39 | @RequiredArgsConstructor |
35 | 40 | public class OrchestrationClient implements OrchestrationConfig<OrchestrationClient> { |
@@ -104,20 +109,53 @@ public OrchestrationResponse chatCompletion(@Nonnull final OrchestrationPrompt p |
104 | 109 | return OrchestrationResponse.fromCompletionPostResponseDTO(result); |
105 | 110 | } |
106 | 111 |
|
| 112 | + /** |
| 113 | + * Stream a completion for the given user message. |
| 114 | + * |
| 115 | + * @param prompt The user message. |
| 116 | + * @return A stream of message chunks. |
| 117 | + * @throws OrchestrationClientException If the request fails. |
| 118 | + */ |
107 | 119 | @Nonnull |
108 | 120 | public Stream<String> streamChatCompletion(@Nonnull final String prompt) |
109 | 121 | throws OrchestrationClientException { |
110 | 122 | throw new NotImplementedError(); |
111 | 123 | } |
112 | 124 |
|
| 125 | + /** |
| 126 | + * Stream a completion for the given prompt. |
| 127 | + * |
| 128 | + * @param prompt The prompt, including messages and other configuration. |
| 129 | + * @return A stream of message chunks. |
| 130 | + * @throws OrchestrationClientException If the request fails. |
| 131 | + */ |
113 | 132 | @Nonnull |
114 | 133 | public Stream<String> streamChatCompletionDelta(@Nonnull final OrchestrationPrompt prompt) |
115 | 134 | throws OrchestrationClientException { |
116 | 135 | throw new NotImplementedError(); |
117 | 136 | } |
118 | 137 |
|
| 138 | + /** |
| 139 | + * Serializes the given request, executes it and deserializes the response. |
| 140 | + * |
| 141 | + * <p>Override this method to customize the request execution. For example, to modify the request |
| 142 | + * object before it is sent, use: |
| 143 | + * |
| 144 | + * <pre>{@code |
| 145 | + * @Override |
| 146 | + * protected CompletionPostResponse executeRequest(@Nonnull CompletionPostRequest request) { |
| 147 | + * request.setCustomField("myField", "myValue"); |
| 148 | + * return super.executeRequest(request); |
| 149 | + * } |
| 150 | + * }</pre> |
| 151 | + * |
| 152 | + * @param request The request DTO to send to orchestration. |
| 153 | + * @return The response DTO from orchestration. |
| 154 | + * @throws OrchestrationClientException If the request fails. |
| 155 | + */ |
119 | 156 | @Nonnull |
120 | | - protected CompletionPostResponse executeRequest(@Nonnull final CompletionPostRequest request) { |
| 157 | + protected CompletionPostResponse executeRequest(@Nonnull final CompletionPostRequest request) |
| 158 | + throws OrchestrationClientException { |
121 | 159 | final BasicClassicHttpRequest postRequest = new HttpPost("/completion"); |
122 | 160 | try { |
123 | 161 | val json = JACKSON.writeValueAsString(request); |
|
0 commit comments