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
2 changes: 1 addition & 1 deletion core/src/models/google_llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export class Gemini extends BaseLlm {
if (llmRequest.config) {
// Using API key from Google AI Studio to call model doesn't support
// labels.
(llmRequest.config as {labels?: unknown}).labels = undefined;
llmRequest.config.labels = undefined;
}
if (llmRequest.contents) {
for (const content of llmRequest.contents) {
Expand Down
46 changes: 46 additions & 0 deletions core/test/models/google_llm_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,52 @@ describe('GoogleLlm', () => {

await expect(generator.next()).rejects.toThrow('Aborted');
});

it('should clear labels on the request config for the Gemini API backend', async () => {
const llm = new TestGemini({apiKey: 'test-key'});
const generateContentMock =
vi.fn<typeof llm.apiClient.models.generateContent>();
generateContentMock.mockResolvedValue(new GenerateContentResponse());
llm.apiClient.models.generateContent = generateContentMock;

const llmRequest: LlmRequest = {
contents: [{role: 'user', parts: [{text: 'hello'}]}],
config: {labels: {'adk-agent-name': 'agent'}},
liveConnectConfig: {},
toolsDict: {},
};

await llm.generateContentAsync(llmRequest).next();

const [callArg] = generateContentMock.mock.calls[0];
expect(callArg.config?.labels).toBeUndefined();
expect(llmRequest.config?.labels).toBeUndefined();
});

it('should preserve labels on the request config for the Vertex AI backend', async () => {
const llm = new TestGemini({
vertexai: true,
project: 'test-project',
location: 'us-central1',
});
const generateContentMock =
vi.fn<typeof llm.apiClient.models.generateContent>();
generateContentMock.mockResolvedValue(new GenerateContentResponse());
llm.apiClient.models.generateContent = generateContentMock;

const llmRequest: LlmRequest = {
contents: [{role: 'user', parts: [{text: 'hello'}]}],
config: {labels: {'adk-agent-name': 'agent'}},
liveConnectConfig: {},
toolsDict: {},
};

await llm.generateContentAsync(llmRequest).next();

const [callArg] = generateContentMock.mock.calls[0];
expect(callArg.config?.labels).toEqual({'adk-agent-name': 'agent'});
expect(llmRequest.config?.labels).toEqual({'adk-agent-name': 'agent'});
});
});

describe('generateContentAsync streaming', () => {
Expand Down
Loading