forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update model to return correct model for CHAT_COMPLETION task type (e…
…lastic#120326) * Update model to return correct model for CHAT_COMPLETION task type * Update docs/changelog/120326.yaml * Delete docs/changelog/120326.yaml * Fixing chat completion functionality * Fixing tests * naming * Fixing tests * Adding more tests --------- Co-authored-by: Jonathan Buttner <[email protected]> Co-authored-by: Jonathan Buttner <[email protected]>
- Loading branch information
1 parent
165f930
commit 408f473
Showing
24 changed files
with
312 additions
and
62 deletions.
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.