-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update model to return correct model for CHAT_COMPLETION task type #120326
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7055790
Update model to return correct model for CHAT_COMPLETION task type
jaybcee bb21394
Merge branch 'main' into jbc-bugfix
jaybcee fb6943d
Update docs/changelog/120326.yaml
jaybcee f264c67
Delete docs/changelog/120326.yaml
jaybcee 08e0f50
Fixing chat completion functionality
jonathan-buttner c48b866
Fixing tests
jonathan-buttner 47e5755
naming
jonathan-buttner e4c1112
Fixing tests
jonathan-buttner 0609cb8
Merge branch 'main' into jbc-bugfix
jonathan-buttner 58ad9de
Adding more tests
jonathan-buttner fe92c54
Merge branch 'jbc-bugfix' of github.com:elastic/elasticsearch into jb…
jonathan-buttner 8d5daea
Merge branch 'main' into jbc-bugfix
jonathan-buttner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
59 changes: 59 additions & 0 deletions
59
.../xpack/inference/services/validation/SimpleChatCompletionServiceIntegrationValidator.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.services.validation; | ||
|
||
import org.elasticsearch.ElasticsearchStatusException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.inference.InferenceService; | ||
import org.elasticsearch.inference.InferenceServiceResults; | ||
import org.elasticsearch.inference.Model; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.xpack.core.inference.action.InferenceAction; | ||
import org.elasticsearch.xpack.inference.external.http.sender.UnifiedChatInput; | ||
|
||
import java.util.List; | ||
|
||
import static org.elasticsearch.xpack.inference.external.http.sender.OpenAiCompletionRequestManager.USER_ROLE; | ||
|
||
/** | ||
* This class uses the unified chat completion method to perform validation. | ||
*/ | ||
public class SimpleChatCompletionServiceIntegrationValidator implements ServiceIntegrationValidator { | ||
private static final List<String> TEST_INPUT = List.of("how big"); | ||
|
||
@Override | ||
public void validate(InferenceService service, Model model, ActionListener<InferenceServiceResults> listener) { | ||
var chatCompletionInput = new UnifiedChatInput(TEST_INPUT, USER_ROLE, false); | ||
service.unifiedCompletionInfer( | ||
model, | ||
chatCompletionInput.getRequest(), | ||
InferenceAction.Request.DEFAULT_TIMEOUT, | ||
ActionListener.wrap(r -> { | ||
if (r != null) { | ||
listener.onResponse(r); | ||
} else { | ||
listener.onFailure( | ||
new ElasticsearchStatusException( | ||
"Could not complete inference endpoint creation as validation call to service returned null response.", | ||
RestStatus.BAD_REQUEST | ||
) | ||
); | ||
} | ||
}, e -> { | ||
listener.onFailure( | ||
new ElasticsearchStatusException( | ||
"Could not complete inference endpoint creation as validation call to service threw an exception.", | ||
RestStatus.BAD_REQUEST, | ||
e | ||
) | ||
); | ||
}) | ||
); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we've a test class
SimpleChatCompletionServiceIntegrationValidatorTests
for this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, let me take care of that 👍