Skip to content

Commit

Permalink
[Inference API] Fix model field in OpenAI Upgrade IT (#119362) (#119371)
Browse files Browse the repository at this point in the history
* Fix NPE by getting request once and defaulting to empty list

* Fix error in OpenAIUpgrade test which used the wrong field name for certain versions

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
  • Loading branch information
maxhniebergall and elasticsearchmachine authored Dec 30, 2024
1 parent ee1a4ff commit df39798
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.junit.BeforeClass;

import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -83,8 +85,9 @@ public void testOpenAiEmbeddings() throws IOException {
assertEquals("openai", configs.get(0).get("service"));
var serviceSettings = (Map<String, Object>) configs.get(0).get("service_settings");
var taskSettings = (Map<String, Object>) configs.get(0).get("task_settings");
var modelIdFound = serviceSettings.containsKey("model_id") || taskSettings.containsKey("model_id");
assertTrue("model_id not found in config: " + configs.toString(), modelIdFound);
var modelIdFound = serviceSettings.containsKey("model_id")
|| (taskSettings.containsKey("model") && getOldClusterTestVersion().onOrBefore(OPEN_AI_EMBEDDINGS_MODEL_SETTING_MOVED));
assertTrue("model_id not found in config: " + configs, modelIdFound);

assertEmbeddingInference(oldClusterId);
} else if (isUpgradedCluster()) {
Expand Down Expand Up @@ -139,9 +142,11 @@ public void testOpenAiCompletions() throws IOException {

assertCompletionInference(oldClusterId);
} else if (isMixedCluster()) {
var configs = (List<Map<String, Object>>) get(testTaskType, oldClusterId).get("endpoints");
List<Map<String, Object>> configs = new LinkedList<>();
var request = get(testTaskType, oldClusterId);
configs.addAll((Collection<? extends Map<String, Object>>) request.getOrDefault("endpoints", List.of()));
if (oldClusterHasFeature("gte_v" + MODELS_RENAMED_TO_ENDPOINTS) == false) {
configs.addAll((List<Map<String, Object>>) get(testTaskType, oldClusterId).get(old_cluster_endpoint_identifier));
configs.addAll((List<Map<String, Object>>) request.getOrDefault(old_cluster_endpoint_identifier, List.of()));
// in version 8.15, there was a breaking change where "models" was renamed to "endpoints"
}
assertEquals("openai", configs.get(0).get("service"));
Expand Down

0 comments on commit df39798

Please sign in to comment.