Skip to content

Commit 11066f0

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Support multiple function chunks
Bug: 360751542 Change-Id: I0ab88b303c2f56c007a635e610bd0a375d94b64a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6074691 Commit-Queue: Alex Rudenko <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]> Reviewed-by: Alex Rudenko <[email protected]>
1 parent 5729804 commit 11066f0

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

front_end/core/host/AidaClient.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describeWithEnvironment('AidaClient', () => {
172172
{
173173
explanation: 'hello brave new world!',
174174
metadata: {rpcGlobalId: 123},
175-
functionCall: undefined,
175+
functionCalls: undefined,
176176
completed: true,
177177
},
178178
]);
@@ -200,7 +200,7 @@ describeWithEnvironment('AidaClient', () => {
200200
{
201201
explanation: 'hello world',
202202
metadata: {rpcGlobalId: 123},
203-
functionCall: undefined,
203+
functionCalls: undefined,
204204
completed: true,
205205
},
206206
]);
@@ -281,7 +281,7 @@ describeWithEnvironment('AidaClient', () => {
281281
'If it were so, it was a grievous fault,\n' +
282282
'And grievously hath Caesar answer’d it.\n',
283283
metadata: {rpcGlobalId: 123},
284-
functionCall: undefined,
284+
functionCalls: undefined,
285285
completed: true,
286286
},
287287
]);
@@ -342,7 +342,7 @@ describeWithEnvironment('AidaClient', () => {
342342
},
343343
],
344344
},
345-
functionCall: undefined,
345+
functionCalls: undefined,
346346
completed: true,
347347
},
348348
]);

front_end/core/host/AidaClient.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export interface AidaResponseMetadata {
213213
export interface AidaResponse {
214214
explanation: string;
215215
metadata: AidaResponseMetadata;
216-
functionCall?: AidaFunctionCallResponse;
216+
functionCalls?: [AidaFunctionCallResponse, ...AidaFunctionCallResponse[]];
217217
completed: boolean;
218218
}
219219

@@ -322,7 +322,7 @@ export class AidaClient {
322322
let chunk;
323323
const text = [];
324324
let inCodeChunk = false;
325-
let functionCall: AidaFunctionCallResponse|undefined = undefined;
325+
const functionCalls: AidaFunctionCallResponse[] = [];
326326
const metadata: AidaResponseMetadata = {rpcGlobalId: 0};
327327
while ((chunk = await stream.read())) {
328328
let textUpdated = false;
@@ -378,10 +378,10 @@ export class AidaClient {
378378
text.push(result.codeChunk.code);
379379
textUpdated = true;
380380
} else if ('functionCallChunk' in result) {
381-
functionCall = {
381+
functionCalls.push({
382382
name: result.functionCallChunk.functionCall.name,
383383
args: result.functionCallChunk.functionCall.args,
384-
};
384+
});
385385
} else if ('error' in result) {
386386
throw new Error(`Server responded: ${JSON.stringify(result)}`);
387387
} else {
@@ -399,7 +399,8 @@ export class AidaClient {
399399
yield {
400400
explanation: text.join('') + (inCodeChunk ? CODE_CHUNK_SEPARATOR : ''),
401401
metadata,
402-
functionCall,
402+
functionCalls: functionCalls.length ? functionCalls as [AidaFunctionCallResponse, ...AidaFunctionCallResponse[]] :
403+
undefined,
403404
completed: true,
404405
};
405406
}

front_end/panels/freestyler/AiAgent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export abstract class AiAgent<T> {
272272
response = aidaResponse.explanation;
273273
rpcId = aidaResponse.metadata.rpcGlobalId ?? rpcId;
274274

275-
if (aidaResponse.functionCall) {
275+
if (aidaResponse.functionCalls) {
276276
throw new Error('Function calling not supported yet');
277277
}
278278

@@ -342,7 +342,7 @@ export abstract class AiAgent<T> {
342342
}
343343

344344
parseResponse(response: Host.AidaClient.AidaResponse): ParsedResponse {
345-
if (response.functionCall && response.completed) {
345+
if (response.functionCalls && response.completed) {
346346
throw new Error('Function calling not supported yet');
347347
}
348348
return {

front_end/panels/freestyler/FreestylerAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class FreestylerAgent extends AiAgent<SDK.DOMModel.DOMNode> {
265265
}
266266

267267
override parseResponse(response: Host.AidaClient.AidaResponse): ParsedResponse {
268-
if (response.functionCall) {
268+
if (response.functionCalls) {
269269
throw new Error('Function calling not supported yet');
270270
}
271271

0 commit comments

Comments
 (0)