Skip to content
Open
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
14 changes: 7 additions & 7 deletions core/src/utils/model_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const MODEL_NAME_PATTERN =
'^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/(.+)$';

/**
* Matches the Early Access Program (EAP) Gemini naming convention. Lower-case
* only, and without the `g` flag so `.test()` stays stateless.
* Matches the Early Access Program (EAP) Gemini naming convention:
* `gemini-<variant>-early-exp` with an optional numeric suffix, e.g.
* `gemini-flash-early-exp` or `gemini-flash-early-exp3`. `<variant>` is one or
* more lower-case alphanumeric/underscore segments joined by `-`.
*/
const EAP_MODEL_NAME_PATTERN =
/^gemini-[a-z0-9_]+(?:-[a-z0-9_]+)*-early-exp\d*$/;
Expand Down Expand Up @@ -81,11 +83,9 @@ export function isGemini1Model(modelString: string): boolean {
/**
* Check if the model is a Gemini EAP or a Gemini 2.0+ model.
*
* EAP Gemini models do not encode a numeric version, so they are matched
* first by their naming convention — `gemini-<variant>-early-exp` with an
* optional numeric suffix, e.g. `gemini-flash-early-exp` or
* `gemini-flash-early-exp3`. Otherwise the model name is parsed as a version
* and matches when the major version is >= 2.
* EAP names carry no numeric version, so `EAP_MODEL_NAME_PATTERN` is tried
* first; otherwise the name is parsed as a version and matches when the major
* version is >= 2.
*
* @param modelString Either a simple model name or path - based model name
* @return true if it's a Gemini EAP model or a Gemini 2.0+ model, false
Expand Down
28 changes: 2 additions & 26 deletions core/test/tools/url_context_tool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {
Context,
createSession,
InvocationContext,
LlmAgent,
LlmRequest,
PluginManager,
URL_CONTEXT,
UrlContextTool,
} from '@google/adk';
import {LlmRequest, URL_CONTEXT, UrlContextTool} from '@google/adk';
import {describe, expect, it} from 'vitest';

function makeRequest(model?: string, tools = []): LlmRequest {
Expand All @@ -26,21 +17,6 @@ function makeRequest(model?: string, tools = []): LlmRequest {
} as unknown as LlmRequest;
}

function makeToolContext(): Context {
return new Context({
invocationContext: new InvocationContext({
invocationId: 'url-context-test',
agent: new LlmAgent({name: 'url_context_test_agent'}),
session: createSession({
id: 'test-session',
appName: 'test-app',
userId: 'test-user',
}),
pluginManager: new PluginManager([]),
}),
});
}

describe('UrlContextTool', () => {
describe('processLlmRequest', () => {
it('returns early when model is not set', async () => {
Expand Down Expand Up @@ -81,7 +57,7 @@ describe('UrlContextTool', () => {
const req = makeRequest('gemini-flash-early-exp');
await tool.processLlmRequest({
llmRequest: req,
toolContext: makeToolContext(),
toolContext: {} as never,
});

expect(req.config!.tools).toEqual([{urlContext: {}}]);
Expand Down
17 changes: 17 additions & 0 deletions core/test/utils/model_name_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ describe('isGemini2OrAbove', () => {
'qwen3-next-80b-a3b-instruct-maas',
'gemini-1.5-pro',
'gemini-1.0-pro',
'gemini-one',
'gemini-0.9-test',
'gemini-2.',
'gemini-',
];

for (const model of invalidModels) {
it(`should return false for model: ${model}`, () => {
expect(isGemini2OrAbove(model)).toBe(false);
});
}

it('should return false for an empty model string', () => {
expect(isGemini2OrAbove('')).toBe(false);
});
});

describe('EAP models', () => {
Expand Down Expand Up @@ -79,6 +87,9 @@ describe('isGemini2OrAbove', () => {
'gemini-Flash-early-exp',
'my-gemini-flash-early-exp',
'claude-3.7-sonnet',
'gemini-flash-early-experiment',
'gemini-flash-early-expX',
'gemini-early-exp3',
];

for (const model of nonEapModels) {
Expand All @@ -92,6 +103,12 @@ describe('isGemini2OrAbove', () => {
// suffix cannot match and stays below the 2.0 bar.
expect(isGemini2OrAbove('gemini-1.5-flash-early-exp')).toBe(false);
});

it('should admit a versioned name carrying the EAP suffix', () => {
// Same character class exclusion as above, resolved through the version
// path instead: '2.5' >= 2.
expect(isGemini2OrAbove('gemini-2.5-flash-early-exp')).toBe(true);
});
});
});

Expand Down