-
Notifications
You must be signed in to change notification settings - Fork 52
Adding default use cases #583
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
Merged
owaiskazi19
merged 5 commits into
opensearch-project:main
from
amitgalitz:default-params
Mar 17, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
74f58bc
initial default use case addition
amitgalitz 9078d04
adding IT and UT
amitgalitz 88610c6
addresing comments and adding more tests
amitgalitz cdb6459
addressing more comments and adding more UT
amitgalitz 80ca636
addressed more comments and more UT
amitgalitz 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 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
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
115 changes: 115 additions & 0 deletions
115
src/main/java/org/opensearch/flowframework/common/DefaultUseCases.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.common; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.flowframework.exception.FlowFrameworkException; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Enum encapsulating the different default use cases and templates we have stored | ||
*/ | ||
public enum DefaultUseCases { | ||
|
||
/** defaults file and substitution ready template for OpenAI embedding model */ | ||
OPEN_AI_EMBEDDING_MODEL_DEPLOY( | ||
"open_ai_embedding_model_deploy", | ||
"defaults/open-ai-embedding-defaults.json", | ||
"substitutionTemplates/deploy-remote-model-template.json" | ||
), | ||
/** defaults file and substitution ready template for cohere embedding model */ | ||
COHERE_EMBEDDING_MODEL_DEPLOY( | ||
"cohere-embedding_model_deploy", | ||
"defaults/cohere-embedding-defaults.json", | ||
"substitutionTemplates/deploy-remote-model-template-extra-params.json" | ||
), | ||
/** defaults file and substitution ready template for local neural sparse model and ingest pipeline*/ | ||
LOCAL_NEURAL_SPARSE_SEARCH( | ||
"local_neural_sparse_search", | ||
"defaults/local-sparse-search-defaults.json", | ||
"substitutionTemplates/neural-sparse-local-template.json" | ||
); | ||
owaiskazi19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final String useCaseName; | ||
private final String defaultsFile; | ||
private final String substitutionReadyFile; | ||
private static final Logger logger = LogManager.getLogger(DefaultUseCases.class); | ||
private static final Set<String> allResources = Stream.of(values()).map(DefaultUseCases::getDefaultsFile).collect(Collectors.toSet()); | ||
owaiskazi19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
DefaultUseCases(String useCaseName, String defaultsFile, String substitutionReadyFile) { | ||
this.useCaseName = useCaseName; | ||
this.defaultsFile = defaultsFile; | ||
this.substitutionReadyFile = substitutionReadyFile; | ||
} | ||
|
||
/** | ||
* Returns the useCaseName for the given enum Constant | ||
* @return the useCaseName of this use case. | ||
*/ | ||
public String getUseCaseName() { | ||
return useCaseName; | ||
} | ||
|
||
/** | ||
* Returns the defaultsFile for the given enum Constant | ||
* @return the defaultsFile of this for the given useCase. | ||
*/ | ||
public String getDefaultsFile() { | ||
return defaultsFile; | ||
} | ||
|
||
/** | ||
* Returns the substitutionReadyFile for the given enum Constant | ||
* @return the substitutionReadyFile of the given useCase | ||
*/ | ||
public String getSubstitutionReadyFile() { | ||
return substitutionReadyFile; | ||
} | ||
|
||
/** | ||
* Gets the defaultsFile based on the given use case. | ||
* @param useCaseName name of the given use case | ||
* @return the defaultsFile for that usecase | ||
* @throws FlowFrameworkException if the use case doesn't exist in enum | ||
*/ | ||
public static String getDefaultsFileByUseCaseName(String useCaseName) throws FlowFrameworkException { | ||
if (useCaseName != null && !useCaseName.isEmpty()) { | ||
for (DefaultUseCases mapping : values()) { | ||
amitgalitz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (useCaseName.equals(mapping.getUseCaseName())) { | ||
return mapping.getDefaultsFile(); | ||
} | ||
} | ||
} | ||
logger.error("Unable to find defaults file for use case: {}", useCaseName); | ||
throw new FlowFrameworkException("Unable to find defaults file for use case: " + useCaseName, RestStatus.BAD_REQUEST); | ||
} | ||
|
||
/** | ||
* Gets the substitutionReadyFile based on the given use case | ||
* @param useCaseName name of the given use case | ||
* @return the substitutionReadyFile which has the template | ||
* @throws FlowFrameworkException if the use case doesn't exist in enum | ||
*/ | ||
public static String getSubstitutionReadyFileByUseCaseName(String useCaseName) throws FlowFrameworkException { | ||
if (useCaseName != null && !useCaseName.isEmpty()) { | ||
for (DefaultUseCases mapping : values()) { | ||
owaiskazi19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (mapping.getUseCaseName().equals(useCaseName)) { | ||
return mapping.getSubstitutionReadyFile(); | ||
} | ||
} | ||
} | ||
logger.error("Unable to find substitution ready file for use case: {}", useCaseName); | ||
throw new FlowFrameworkException("Unable to find substitution ready file for use case: " + useCaseName, RestStatus.BAD_REQUEST); | ||
} | ||
} |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.