[ML] Adding headers support for OpenAI chat completion#134504
Merged
jonathan-buttner merged 16 commits intoelastic:mainfrom Sep 16, 2025
Merged
[ML] Adding headers support for OpenAI chat completion#134504jonathan-buttner merged 16 commits intoelastic:mainfrom
jonathan-buttner merged 16 commits intoelastic:mainfrom
Conversation
Collaborator
|
Hi @jonathan-buttner, I've created a changelog YAML for you. |
|
|
||
| public void testIsEmpty() { | ||
| var randomSettings = new OpenAiChatCompletionTaskSettings(randomBoolean() ? null : "username"); | ||
| var randomSettings = new OpenAiEmbeddingsTaskSettings(randomBoolean() ? null : "username"); |
Contributor
Author
There was a problem hiding this comment.
Randomly found that this was testing the wrong class so switch it to the appropriate one.
…icsearch into ml-openai-headers
| ValidationException validationException = new ValidationException(); | ||
|
|
||
| String user = extractOptionalString(map, USER, ModelConfigurations.TASK_SETTINGS, validationException); | ||
| Map<String, Object> headers = extractOptionalMapRemoveNulls(map, HEADERS, validationException); |
Contributor
Author
There was a problem hiding this comment.
Since we need to add the headers to each task type I'll move this functionality to an abstract class in a later PR.
Collaborator
|
Pinging @elastic/ml-core (Team:ML) |
DonalEvans
reviewed
Sep 11, 2025
| } | ||
|
|
||
| /** | ||
| * Read an optional {@link Map} using the given key and value readers. The return Map is immutable. |
Contributor
There was a problem hiding this comment.
Minor typo, should be "the returned Map is immutable"
|
|
||
| public void testFromMap_ReturnsUser() { | ||
| var settings = OpenAiChatCompletionRequestTaskSettings.fromMap(new HashMap<>(Map.of(OpenAiServiceFields.USER, "user"))); | ||
| public void testFromMap_ParsesCorrectly() { |
Contributor
There was a problem hiding this comment.
It would be good to also have a test for the case where the headers map is null, since that's new functionality in this PR.
DonalEvans
approved these changes
Sep 12, 2025
…icsearch into ml-openai-headers
mridula-s109
pushed a commit
to mridula-s109/elasticsearch
that referenced
this pull request
Sep 17, 2025
* Adding headers support for openai chat completion and completion * Update docs/changelog/134504.yaml * [CI] Auto commit changes from spotless * Adjusting test name * Updating the changelog * Adding headers to the configuration * [CI] Auto commit changes from spotless * [CI] Update transport version definitions * Fixing transport versions --------- Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
gmjehovich
pushed a commit
to gmjehovich/elasticsearch
that referenced
this pull request
Sep 18, 2025
* Adding headers support for openai chat completion and completion * Update docs/changelog/134504.yaml * [CI] Auto commit changes from spotless * Adjusting test name * Updating the changelog * Adding headers to the configuration * [CI] Auto commit changes from spotless * [CI] Update transport version definitions * Fixing transport versions --------- Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for including custom headers in the chat completion and completion openai request. We'll need the support for other openai task types but I'll do that in a follow up PR to keep this one small.
The headers are stored in the
task_settings.This PR also introduce a new type for the
_inference/_servicesconfiguration results calledmapto represent the headers field.Example create inference API request
OpenAI configuration