001/** 002 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.gnu.org/licenses/lgpl-3.0.txt 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package dev.tinyflow.core.llm; 017 018import java.util.ArrayList; 019import java.util.List; 020 021public class LlmManager { 022 023 public List<LlmProvider> providers = new ArrayList<>(); 024 025 private static class ManagerHolder { 026 private static final LlmManager INSTANCE = new LlmManager(); 027 } 028 029 private LlmManager() { 030 } 031 032 public static LlmManager getInstance() { 033 return ManagerHolder.INSTANCE; 034 } 035 036 public void registerProvider(LlmProvider provider) { 037 providers.add(provider); 038 } 039 040 public void removeProvider(LlmProvider provider) { 041 providers.remove(provider); 042 } 043 044 public Llm getChatModel(Object modelId) { 045 for (LlmProvider provider : providers) { 046 Llm llm = provider.getChatModel(modelId); 047 if (llm != null) { 048 return llm; 049 } 050 } 051 return null; 052 } 053}