-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing chat completion functionality
- Loading branch information
1 parent
f264c67
commit 08e0f50
Showing
10 changed files
with
76 additions
and
12 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
54 changes: 54 additions & 0 deletions
54
.../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,54 @@ | ||
|
||
/* | ||
* 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. | ||
*/ | ||
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 a = new UnifiedChatInput(TEST_INPUT, USER_ROLE, false); | ||
service.unifiedCompletionInfer(model, a.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