alessandrobenedetti commented on code in PR #2809: URL: https://github.com/apache/solr/pull/2809#discussion_r1830840186
########## solr/modules/llm/src/test/org/apache/solr/llm/store/rest/TestModelManager.java: ########## @@ -0,0 +1,205 @@ +/* + * 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.store.rest; + +import dev.langchain4j.model.cohere.CohereEmbeddingModel; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.core.SolrResourceLoader; +import org.apache.solr.llm.TestLlmBase; +import org.apache.solr.llm.search.TextEmbedderQParserPlugin; +import org.apache.solr.rest.ManagedResource; +import org.apache.solr.rest.ManagedResourceStorage; +import org.apache.solr.rest.RestManager; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestModelManager extends TestLlmBase { + + @BeforeClass + public static void init() throws Exception { + setuptest(false); + } + + @Test + public void test() throws Exception { + final SolrResourceLoader loader = new SolrResourceLoader(tmpSolrHome); + + final RestManager.Registry registry = loader.getManagedResourceRegistry(); + assertNotNull( + "Expected a non-null RestManager.Registry from the SolrResourceLoader!", registry); + + final String resourceId = "/schema/mstore1"; + registry.registerManagedResource( + resourceId, ManagedEmbeddingModelStore.class, new TextEmbedderQParserPlugin()); + + final NamedList<String> initArgs = new NamedList<>(); + + final RestManager restManager = new RestManager(); + restManager.init(loader, initArgs, new ManagedResourceStorage.InMemoryStorageIO()); + + final ManagedResource res = restManager.getManagedResource(resourceId); + assertTrue(res instanceof ManagedEmbeddingModelStore); + assertEquals(res.getResourceId(), resourceId); + } + + @Test + public void testRestManagerEndpoints() throws Exception { + assertJQ("/schema/managed", "/responseHeader/status==0"); + + final String cohereModelClassName = CohereEmbeddingModel.class.getName(); + + // Add models + String model = "{ \"name\":\"testModel1\", \"class\":\"" + cohereModelClassName + "\"}"; + // fails since it does not have params + assertJPut(ManagedEmbeddingModelStore.REST_END_POINT, model, "/responseHeader/status==400"); + // success + model = + "{ name:\"testModel2\", class:\"" + + cohereModelClassName + + "\"," + + "params:{" + + "baseUrl:\"https://api.cohere.ai/v1/\"," + + "apiKey:\"cohereApiKey2\"," + + "modelName:\"embed-english-light-v3.0\"," + + "inputType:\"search_document\"," + + "logRequests:true," + + "logResponses:false" + + "}}"; + assertJPut(ManagedEmbeddingModelStore.REST_END_POINT, model, "/responseHeader/status==0"); + // success + final String multipleModels = + "[{ name:\"testModel3\", class:\"" Review Comment: mmm I am missing the point here, can you tell me how you think this can be improved with an example? happy to do it then! -- 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