Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/src/main/java/com/google/adk/models/LlmRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.adk.models;

import com.google.common.annotations.VisibleForTesting;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -38,6 +39,7 @@ public interface LlmFactory {
static {
registerLlm("gemini-.*", modelName -> Gemini.builder().modelName(modelName).build());
registerLlm("apigee/.*", modelName -> ApigeeLlm.builder().modelName(modelName).build());
registerLlm("gemma-.*", modelName -> Gemini.builder().modelName(modelName).build());
}

/**
Expand All @@ -50,6 +52,17 @@ public static void registerLlm(String modelNamePattern, LlmFactory factory) {
llmFactories.put(modelNamePattern, factory);
}

/**
* Checks if the given model name matches any of the registered LLM factory patterns.
*
* @param modelName The model name to check.
* @return {@code true} if the model name matches at least one pattern, {@code false} otherwise.
*/
@VisibleForTesting
static boolean matchesAnyPattern(String modelName) {
return llmFactories.keySet().stream().anyMatch(modelName::matches);
}

/**
* Returns an LLM instance for the given model name, using a cached or new factory-created
* instance.
Expand Down
39 changes: 39 additions & 0 deletions core/src/test/java/com/google/adk/models/GemmaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2026 Google LLC
*
* Licensed 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 com.google.adk.models;

import static com.google.common.truth.Truth.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class GemmaTest {

@Test
public void getLlm_withValidGemmaModels_succeeds() {
assertThat(LlmRegistry.matchesAnyPattern("gemma-4-26b-a4b-it")).isTrue();
assertThat(LlmRegistry.matchesAnyPattern("gemma-4-31b-it")).isTrue();
}

@Test
public void getLlm_withInvalidGemmaModels_throwsException() {
assertThat(LlmRegistry.matchesAnyPattern("not-a-gemma")).isFalse();
assertThat(LlmRegistry.matchesAnyPattern("gemma")).isFalse();
}
}
Loading