Skip to content

Commit

Permalink
Check for null before overriding task settings (elastic#102918)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle authored Dec 4, 2023
1 parent fd1e26a commit af30fe4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ public ExecutableAction accept(OpenAiActionVisitor creator, Map<String, Object>
}

public OpenAiEmbeddingsModel overrideWith(Map<String, Object> taskSettings) {
var requestTaskSettings = OpenAiEmbeddingsRequestTaskSettings.fromMap(taskSettings);
if (taskSettings == null || taskSettings.isEmpty()) {
return this;
}

var requestTaskSettings = OpenAiEmbeddingsRequestTaskSettings.fromMap(taskSettings);
return new OpenAiEmbeddingsModel(this, getTaskSettings().overrideWith(requestTaskSettings));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import org.elasticsearch.xpack.inference.services.openai.OpenAiServiceSettings;
import org.elasticsearch.xpack.inference.services.settings.DefaultSecretSettings;

import java.util.Map;

import static org.elasticsearch.xpack.inference.services.openai.embeddings.OpenAiEmbeddingsRequestTaskSettingsTests.getRequestTaskSettingsMap;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;

public class OpenAiEmbeddingsModelTests extends ESTestCase {

Expand All @@ -28,6 +31,22 @@ public void testOverrideWith_OverridesUser() {
assertThat(overriddenModel, is(createModel("url", "org", "api_key", "model_name", "user_override")));
}

public void testOverrideWith_EmptyMap() {
var model = createModel("url", "org", "api_key", "model_name", null);

var requestTaskSettingsMap = Map.<String, Object>of();

var overriddenModel = model.overrideWith(requestTaskSettingsMap);
assertThat(overriddenModel, sameInstance(model));
}

public void testOverrideWith_NullMap() {
var model = createModel("url", "org", "api_key", "model_name", null);

var overriddenModel = model.overrideWith(null);
assertThat(overriddenModel, sameInstance(model));
}

public static OpenAiEmbeddingsModel createModel(
String url,
@Nullable String org,
Expand Down

0 comments on commit af30fe4

Please sign in to comment.