Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

### ✨ New Functionality

- Support for OpenAI Responses API with the new `AiCoreOpenAiClient`.
- [OpenAI] Support for OpenAI Responses API with the new `AiCoreOpenAiClient`.
The following endpoints are currently supported:
- create()
- createStreaming()
- retrieve()
- delete()
- cancel()
- [Orchestration] You can now add multiple custom headers to an `OrchestrationClient` at once via `.withHeaders()`.

### 📈 Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,24 @@ public OrchestrationClient withHeader(@Nonnull final String key, @Nonnull final
return newClient;
}

/**
* Create a new orchestration client with multiple custom headers added to every call made with
* this client
*
* @param headers a map of key value pairs for the custom headers to add
* @return a new client.
* @since 1.22.0
*/
@Nonnull
public OrchestrationClient withHeaders(@Nonnull final Map<String, String> headers) {
final var newClient = new OrchestrationClient(this.executor);
newClient.customHeaders.addAll(this.customHeaders);
headers.entrySet().stream()
.map(e -> new Header(e.getKey(), e.getValue()))
.forEach(newClient.customHeaders::add);
return newClient;
}

/**
* Create a new orchestration client for the given resource group and scenario.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,62 @@ void testCustomHeaders() {
.withHeader("foot", equalTo("baz")));
}

@Test
void testWithHeadersAddsAllHeaders() {
stubFor(
post(urlPathEqualTo("/v2/completion"))
.willReturn(
aResponse()
.withBodyFile("templatingResponse.json")
.withHeader("Content-Type", "application/json")));

final var result =
client
.withHeaders(Map.of("x-custom-one", "value1", "x-custom-two", "value2"))
.chatCompletion(prompt, config);
assertThat(result).isNotNull();

verify(
postRequestedFor(urlPathEqualTo("/v2/completion"))
.withHeader("x-custom-one", equalTo("value1"))
.withHeader("x-custom-two", equalTo("value2")));
}

@Test
void testWithHeadersCarriesOverPreviousHeaders() {
stubFor(
post(urlPathEqualTo("/v2/completion"))
.willReturn(
aResponse()
.withBodyFile("templatingResponse.json")
.withHeader("Content-Type", "application/json")));

client
.withHeader("x-existing", "existing-value")
.withHeaders(Map.of("x-new", "new-value"))
.chatCompletion(prompt, config);

verify(
postRequestedFor(urlPathEqualTo("/v2/completion"))
.withHeader("x-existing", equalTo("existing-value"))
.withHeader("x-new", equalTo("new-value")));
}

@Test
void testWithHeadersDoesNotMutateOriginalClient() {
stubFor(
post(urlPathEqualTo("/v2/completion"))
.willReturn(
aResponse()
.withBodyFile("templatingResponse.json")
.withHeader("Content-Type", "application/json")));

client.withHeaders(Map.of("x-should-not-appear", "value"));
client.chatCompletion(prompt, config);

verify(postRequestedFor(urlPathEqualTo("/v2/completion")).withoutHeader("x-should-not-appear"));
}

@Test
void testGrounding() throws IOException {
stubFor(
Expand Down