Skip to content

Commit 03ae42b

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[Ai Assistance] Use function calling for StylingAgent
Bug: 360751542 Change-Id: Ia2b8ffc86537d919a0aef585929fbd53bf3e2234 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6197651 Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Alex Rudenko <[email protected]>
1 parent 88d1633 commit 03ae42b

File tree

12 files changed

+868
-831
lines changed

12 files changed

+868
-831
lines changed

front_end/core/host/AidaClient.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@ import type {AidaClientResult, SyncInformation} from './InspectorFrontendHostAPI
1010
import {bindOutputStream} from './ResourceLoader.js';
1111

1212
export enum Role {
13-
// Unspecified role.
13+
/** Provide this role when giving a function call response */
1414
ROLE_UNSPECIFIED = 0,
15-
// The user.
15+
/** Tags the content came from the user */
1616
USER = 1,
17-
// The model.
17+
/** Tags the content came from the LLM */
1818
MODEL = 2,
1919
}
2020

2121
export const enum Rating {
22+
// Resets the vote to null in the logs
2223
SENTIMENT_UNSPECIFIED = 'SENTIMENT_UNSPECIFIED',
2324
POSITIVE = 'POSITIVE',
2425
NEGATIVE = 'NEGATIVE',
2526
}
2627

27-
// A `Content` represents a single turn message.
28+
/**
29+
* A `Content` represents a single turn message.
30+
*/
2831
export interface Content {
2932
parts: Part[];
30-
// The producer of the content.
33+
/** The producer of the content. */
3134
role: Role;
3235
}
3336

@@ -44,7 +47,7 @@ export type Part = {
4447
response: Record<string, unknown>,
4548
},
4649
}|{
47-
// Inline media bytes.
50+
/** Inline media bytes. */
4851
inlineData: MediaBlob,
4952
};
5053

@@ -71,23 +74,23 @@ interface FunctionArrayParam extends BaseFunctionParam {
7174
items: FunctionPrimitiveParams;
7275
}
7376

74-
export interface FunctionObjectParam extends BaseFunctionParam {
77+
export interface FunctionObjectParam<T extends string|number|symbol = string> extends BaseFunctionParam {
7578
type: ParametersTypes.OBJECT;
7679
// TODO: this can be also be ObjectParams
77-
properties: {[Key in string]: FunctionPrimitiveParams|FunctionArrayParam};
80+
properties: Record<T, FunctionPrimitiveParams|FunctionArrayParam>;
7881
}
7982

8083
/**
8184
* More about function declaration can be read at
8285
* https://ai.google.dev/gemini-api/docs/function-calling
8386
*/
84-
export interface FunctionDeclaration {
87+
export interface FunctionDeclaration<T extends string|number|symbol = string> {
8588
name: string;
8689
/**
8790
* A description for the LLM to understand what the specific function will do once called.
8891
*/
8992
description: string;
90-
parameters: FunctionObjectParam|FunctionPrimitiveParams|FunctionArrayParam;
93+
parameters: FunctionObjectParam<T>;
9194
}
9295

9396
// Raw media bytes.

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
} from './agents/NetworkAgent.js';
4141
import {PatchAgent, ProjectContext} from './agents/PatchAgent.js';
4242
import {CallTreeContext, PerformanceAgent} from './agents/PerformanceAgent.js';
43-
import {NodeContext, StylingAgent} from './agents/StylingAgent.js';
43+
import {NodeContext, StylingAgent, StylingAgentWithFunctionCalling} from './agents/StylingAgent.js';
4444
import aiAssistancePanelStyles from './aiAssistancePanel.css.js';
4545
import {
4646
AiHistoryStorage,
@@ -334,6 +334,13 @@ export class AiAssistancePanel extends UI.Panel.Panel {
334334
...options,
335335
changeManager: this.#changeManager,
336336
});
337+
if (isAiAssistanceStylingWithFunctionCallingEnabled()) {
338+
agent = new StylingAgentWithFunctionCalling({
339+
...options,
340+
changeManager: this.#changeManager,
341+
});
342+
}
343+
337344
break;
338345
}
339346
case AgentType.NETWORK: {
@@ -939,9 +946,13 @@ export class AiAssistancePanel extends UI.Panel.Panel {
939946
commitStep();
940947
break;
941948
}
949+
case ResponseType.SUGGESTIONS: {
950+
systemMessage.suggestions = data.suggestions;
951+
break;
952+
}
942953
case ResponseType.SIDE_EFFECT: {
943954
step.isLoading = false;
944-
step.code = data.code;
955+
step.code ??= data.code;
945956
step.sideEffect = {
946957
onAnswer: data.confirm,
947958
};
@@ -950,8 +961,8 @@ export class AiAssistancePanel extends UI.Panel.Panel {
950961
}
951962
case ResponseType.ACTION: {
952963
step.isLoading = false;
953-
step.code = data.code;
954-
step.output = data.output;
964+
step.code ??= data.code;
965+
step.output ??= data.output;
955966
step.canceled = data.canceled;
956967
if (isAiAssistanceChangeSummariesEnabled() && this.#currentAgent && !this.#currentAgent.isHistoryEntry) {
957968
this.#viewProps.changeSummary = this.#changeManager.formatChanges(this.#currentAgent.id);
@@ -960,7 +971,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
960971
break;
961972
}
962973
case ResponseType.ANSWER: {
963-
systemMessage.suggestions = data.suggestions;
974+
systemMessage.suggestions ??= data.suggestions;
964975
systemMessage.answer = data.text;
965976
systemMessage.rpcId = data.rpcId;
966977
// When there is an answer without any thinking steps, we don't want to show the thinking step.
@@ -1075,7 +1086,21 @@ function isAiAssistanceServerSideLoggingEnabled(): boolean {
10751086
return localStorage.getItem('aiAssistance_enableServerSideLogging') !== 'false';
10761087
}
10771088

1089+
function setAiAssistanceStylingWithFunctionCalling(enabled: boolean): void {
1090+
if (enabled) {
1091+
localStorage.setItem('aiAssistance_stylingFunctionCalling', 'true');
1092+
} else {
1093+
localStorage.setItem('aiAssistance_stylingFunctionCalling', 'false');
1094+
}
1095+
}
1096+
1097+
function isAiAssistanceStylingWithFunctionCallingEnabled(): boolean {
1098+
return localStorage.getItem('aiAssistance_stylingFunctionCalling') === 'true';
1099+
}
1100+
10781101
// @ts-ignore
10791102
globalThis.setAiAssistanceServerSideLoggingEnabled = setAiAssistanceServerSideLoggingEnabled;
10801103
// @ts-ignore
10811104
globalThis.setAiAssistanceChangeSummariesEnabled = setAiAssistanceChangeSummariesEnabled;
1105+
// @ts-ignore
1106+
globalThis.setAiAssistanceStylingWithFunctionCalling = setAiAssistanceStylingWithFunctionCalling;

0 commit comments

Comments
 (0)