- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25.6k
 
[ML] Custom service add support for input_type, top_n, and return_documents #129441
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
Changes from 12 commits
9e97819
              6988b7a
              4bc337b
              a3a532b
              6176e37
              eec1f5c
              02ffef6
              659f9e0
              b061fe2
              a65a12b
              ddf6676
              70be427
              6523643
              5c39685
              9d5c2e5
              c1b053a
              35035ad
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| 
          
            
          
           | 
    @@ -10,8 +10,12 @@ | |||||
| package org.elasticsearch.inference; | ||||||
| 
     | 
||||||
| import org.elasticsearch.common.Strings; | ||||||
| import org.elasticsearch.common.ValidationException; | ||||||
| 
     | 
||||||
| import java.util.EnumSet; | ||||||
| import java.util.HashMap; | ||||||
| import java.util.Locale; | ||||||
| import java.util.Map; | ||||||
| 
     | 
||||||
| import static org.elasticsearch.core.Strings.format; | ||||||
| 
     | 
||||||
| 
        
          
        
         | 
    @@ -29,6 +33,13 @@ public enum InputType { | |||||
| INTERNAL_SEARCH, | ||||||
| INTERNAL_INGEST; | ||||||
| 
     | 
||||||
| private static final EnumSet<InputType> SUPPORTED_REQUEST_VALUES = EnumSet.of( | ||||||
| InputType.CLASSIFICATION, | ||||||
| InputType.CLUSTERING, | ||||||
| InputType.INGEST, | ||||||
| InputType.SEARCH | ||||||
| ); | ||||||
| 
     | 
||||||
| @Override | ||||||
| public String toString() { | ||||||
| return name().toLowerCase(Locale.ROOT); | ||||||
| 
          
            
          
           | 
    @@ -57,4 +68,57 @@ public static boolean isSpecified(InputType inputType) { | |||||
| public static String invalidInputTypeMessage(InputType inputType) { | ||||||
| return Strings.format("received invalid input type value [%s]", inputType.toString()); | ||||||
| } | ||||||
| 
     | 
||||||
| /** | ||||||
| * Ensures that a map used for translating input types is valid. The keys of the map are the external representation, | ||||||
| * and the values correspond to the values in this class. | ||||||
| * Throws a {@link ValidationException} if any value is not a valid InputType. | ||||||
| * | ||||||
| * @param inputTypeTranslation the map of input type translations to validate | ||||||
| * @param validationException a ValidationException to which errors will be added | ||||||
| */ | ||||||
| public static Map<InputType, String> validateInputTypeTranslationValues( | ||||||
| Map<String, Object> inputTypeTranslation, | ||||||
| ValidationException validationException | ||||||
| ) { | ||||||
| if (inputTypeTranslation == null || inputTypeTranslation.isEmpty()) { | ||||||
| return Map.of(); | ||||||
| } | ||||||
| 
     | 
||||||
| var translationMap = new HashMap<InputType, String>(); | ||||||
| 
     | 
||||||
| for (var entry : inputTypeTranslation.entrySet()) { | ||||||
| var key = entry.getKey(); | ||||||
| var value = entry.getValue(); | ||||||
| 
     | 
||||||
| if (value instanceof String == false || Strings.isNullOrEmpty((String) value)) { | ||||||
| validationException.addValidationError( | ||||||
| Strings.format( | ||||||
| "Input type translation value for key [%s] must be a String that is not null and not empty, received: [%s].", | ||||||
| key, | ||||||
| value.getClass().getSimpleName() | ||||||
                
       | 
||||||
| value.getClass().getSimpleName() | |
| value == null ? "null" : value.getClass().getSimpleName() | 
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.
Oops, thank you.
        
          
              
                Outdated
          
        
      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.
| EnumSet.of(InputType.CLASSIFICATION, InputType.CLUSTERING, InputType.INGEST, InputType.SEARCH) | |
| SUPPORTED_REQUEST_VALUES | 
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.
Thanks for adding this