alessandrobenedetti commented on code in PR #2809: URL: https://github.com/apache/solr/pull/2809#discussion_r1863737227
########## solr/modules/llm/src/test/org/apache/solr/llm/TestLlmBase.java: ########## @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.llm; + +import java.lang.invoke.MethodHandles; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.commons.io.file.PathUtils; +import org.apache.solr.common.SolrInputDocument; +import org.apache.solr.llm.store.rest.ManagedEmbeddingModelStore; +import org.apache.solr.util.RestTestBase; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestLlmBase extends RestTestBase { + + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + protected static Path tmpSolrHome; + protected static Path tmpConfDir; + + public static final String MODEL_FILE_NAME = "_schema_embedding-model-store.json"; + protected static final String COLLECTION = "collection1"; + protected static final String CONF_DIR = COLLECTION + "/conf"; + + protected static Path embeddingModelStoreFile = null; + + protected static String IDField = "id"; + protected static String stringField = "string_field"; + protected static String vectorField = "vector"; + protected static String vectorField2 = "vector2"; + protected static String vectorFieldByteEncoding = "vector_byte_encoding"; + + protected static void setupTest( + String solrconfig, String schema, boolean buildIndex, boolean persistModelStore) + throws Exception { + initFolders(persistModelStore); + createJettyAndHarness( + tmpSolrHome.toAbsolutePath().toString(), solrconfig, schema, "/solr", true, null); + if (buildIndex) prepareIndex(); + } + + protected static void initFolders(boolean isPersistent) throws Exception { + tmpSolrHome = createTempDir(); + tmpConfDir = tmpSolrHome.resolve(CONF_DIR); + tmpConfDir.toFile().deleteOnExit(); + PathUtils.copyDirectory(TEST_PATH(), tmpSolrHome.toAbsolutePath()); + + final Path modelStore = tmpConfDir.resolve(MODEL_FILE_NAME); + + if (isPersistent) { + embeddingModelStoreFile = modelStore; + } + + if (Files.exists(modelStore)) { + if (log.isInfoEnabled()) { + log.info("remove model store config file in {}", modelStore.toAbsolutePath()); + } + Files.delete(modelStore); + } + + System.setProperty("managed.schema.mutable", "true"); + } + + protected static void afterTest() throws Exception { + if (null != restTestHarness) { + restTestHarness.close(); + restTestHarness = null; + } + solrClientTestRule.reset(); + if (null != tmpSolrHome) { + PathUtils.deleteDirectory(tmpSolrHome); + tmpSolrHome = null; + } + System.clearProperty("managed.schema.mutable"); + } + + /** produces a model encoded in json * */ + public static String getModelInJson(String name, String className, String params) { + final StringBuilder sb = new StringBuilder(); + sb.append("{\n"); + sb.append("\"name\":").append('"').append(name).append('"').append(",\n"); + sb.append("\"class\":").append('"').append(className).append('"').append(",\n"); + if (params != null) { + sb.append(",\n"); + sb.append("\"params\":").append(params); + } + sb.append("\n}\n"); + return sb.toString(); + } + + protected static void loadModel(String name, String className, String params) throws Exception { + final String model = getModelInJson(name, className, params); + log.info("loading model \n{} ", model); Review Comment: done a cleanup and removed these bits entirely -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org