Skip to content

Commit df39798

Browse files
maxhniebergallelasticsearchmachine
andauthored
[Inference API] Fix model field in OpenAI Upgrade IT (#119362) (#119371)
* 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 <[email protected]>
1 parent ee1a4ff commit df39798

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

x-pack/plugin/inference/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/application/OpenAiServiceUpgradeIT.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.junit.BeforeClass;
1717

1818
import java.io.IOException;
19+
import java.util.Collection;
20+
import java.util.LinkedList;
1921
import java.util.List;
2022
import java.util.Map;
2123

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

8992
assertEmbeddingInference(oldClusterId);
9093
} else if (isUpgradedCluster()) {
@@ -139,9 +142,11 @@ public void testOpenAiCompletions() throws IOException {
139142

140143
assertCompletionInference(oldClusterId);
141144
} else if (isMixedCluster()) {
142-
var configs = (List<Map<String, Object>>) get(testTaskType, oldClusterId).get("endpoints");
145+
List<Map<String, Object>> configs = new LinkedList<>();
146+
var request = get(testTaskType, oldClusterId);
147+
configs.addAll((Collection<? extends Map<String, Object>>) request.getOrDefault("endpoints", List.of()));
143148
if (oldClusterHasFeature("gte_v" + MODELS_RENAMED_TO_ENDPOINTS) == false) {
144-
configs.addAll((List<Map<String, Object>>) get(testTaskType, oldClusterId).get(old_cluster_endpoint_identifier));
149+
configs.addAll((List<Map<String, Object>>) request.getOrDefault(old_cluster_endpoint_identifier, List.of()));
145150
// in version 8.15, there was a breaking change where "models" was renamed to "endpoints"
146151
}
147152
assertEquals("openai", configs.get(0).get("service"));

0 commit comments

Comments
 (0)