Skip to content

Commit ce3a991

Browse files
Samiya CaurDevtools-frontend LUCI CQ
authored andcommitted
Update request sent to AIDA to use new fields current_message and historical_contexts
Bug: 379074152 Change-Id: I38147da812b2b3c5f6b92a9932c5f9c4ca018ca0 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6040796 Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Samiya Caur <[email protected]>
1 parent 8fd8873 commit ce3a991

File tree

10 files changed

+204
-168
lines changed

10 files changed

+204
-168
lines changed

front_end/core/host/AidaClient.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describeWithEnvironment('AidaClient', () => {
1313
const stub = getGetHostConfigStub({});
1414
const request = Host.AidaClient.AidaClient.buildConsoleInsightsRequest('foo');
1515
assert.deepStrictEqual(request, {
16-
input: 'foo',
16+
current_message: {parts: [{text: 'foo'}], role: Host.AidaClient.Role.USER},
1717
client: 'CHROME_DEVTOOLS',
1818
client_feature: 1,
1919
functionality_type: 2,
@@ -30,7 +30,7 @@ describeWithEnvironment('AidaClient', () => {
3030
});
3131
const request = Host.AidaClient.AidaClient.buildConsoleInsightsRequest('foo');
3232
assert.deepStrictEqual(request, {
33-
input: 'foo',
33+
current_message: {parts: [{text: 'foo'}], role: Host.AidaClient.Role.USER},
3434
client: 'CHROME_DEVTOOLS',
3535
options: {
3636
temperature: 0.5,
@@ -50,7 +50,7 @@ describeWithEnvironment('AidaClient', () => {
5050
});
5151
const request = Host.AidaClient.AidaClient.buildConsoleInsightsRequest('foo');
5252
assert.deepStrictEqual(request, {
53-
input: 'foo',
53+
current_message: {parts: [{text: 'foo'}], role: Host.AidaClient.Role.USER},
5454
client: 'CHROME_DEVTOOLS',
5555
options: {
5656
temperature: 0,
@@ -70,7 +70,7 @@ describeWithEnvironment('AidaClient', () => {
7070
});
7171
const request = Host.AidaClient.AidaClient.buildConsoleInsightsRequest('foo');
7272
assert.deepStrictEqual(request, {
73-
input: 'foo',
73+
current_message: {parts: [{text: 'foo'}], role: Host.AidaClient.Role.USER},
7474
client: 'CHROME_DEVTOOLS',
7575
client_feature: 1,
7676
functionality_type: 2,
@@ -88,7 +88,7 @@ describeWithEnvironment('AidaClient', () => {
8888
});
8989
const request = Host.AidaClient.AidaClient.buildConsoleInsightsRequest('foo');
9090
assert.deepStrictEqual(request, {
91-
input: 'foo',
91+
current_message: {parts: [{text: 'foo'}], role: Host.AidaClient.Role.USER},
9292
client: 'CHROME_DEVTOOLS',
9393
options: {
9494
model_id: TEST_MODEL_ID,
@@ -112,7 +112,7 @@ describeWithEnvironment('AidaClient', () => {
112112
});
113113
const request = Host.AidaClient.AidaClient.buildConsoleInsightsRequest('foo');
114114
assert.deepStrictEqual(request, {
115-
input: 'foo',
115+
current_message: {parts: [{text: 'foo'}], role: Host.AidaClient.Role.USER},
116116
client: 'CHROME_DEVTOOLS',
117117
metadata: {
118118
disable_user_content_logging: true,

front_end/core/host/AidaClient.ts

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

12-
export enum Entity {
13-
UNKNOWN = 0,
12+
export enum Role {
13+
// Unspecified role.
14+
ROLE_UNSPECIFIED = 0,
15+
// The user.
1416
USER = 1,
15-
SYSTEM = 2,
17+
// The model.
18+
MODEL = 2,
1619
}
1720

1821
export const enum Rating {
@@ -21,9 +24,27 @@ export const enum Rating {
2124
NEGATIVE = 'NEGATIVE',
2225
}
2326

24-
export interface HistoryChunk {
25-
text: string;
26-
entity: Entity;
27+
// A `Content` represents a single turn message.
28+
export interface Content {
29+
parts: Part[];
30+
// The producer of the content.
31+
role: Role;
32+
}
33+
34+
export interface Part {
35+
text?: string;
36+
// Inline media bytes.
37+
inlineData?: MediaBlob;
38+
}
39+
40+
// Raw media bytes.
41+
export interface MediaBlob {
42+
// The IANA standard MIME type of the source data.
43+
// Currently supported types are: image/png, image/jpeg.
44+
// Format: base64-encoded
45+
// For reference: google3/google/x/pitchfork/aida/v1/content.proto
46+
mimeType: string;
47+
data: string;
2748
}
2849

2950
export enum FunctionalityType {
@@ -62,10 +83,11 @@ export enum UserTier {
6283
}
6384

6485
export interface AidaRequest {
65-
input: string;
86+
// eslint-disable-next-line @typescript-eslint/naming-convention
87+
current_message?: Content;
6688
preamble?: string;
6789
// eslint-disable-next-line @typescript-eslint/naming-convention
68-
chat_history?: HistoryChunk[];
90+
historical_contexts?: Content[];
6991
client: string;
7092
options?: {
7193
temperature?: number,
@@ -152,7 +174,7 @@ export class AidaAbortError extends Error {}
152174
export class AidaClient {
153175
static buildConsoleInsightsRequest(input: string): AidaRequest {
154176
const request: AidaRequest = {
155-
input,
177+
current_message: {parts: [{text: input}], role: Role.USER},
156178
client: CLIENT_NAME,
157179
functionality_type: FunctionalityType.EXPLAIN_ERROR,
158180
client_feature: ClientFeature.CHROME_CONSOLE_INSIGHTS,

front_end/panels/freestyler/AiAgent.test.ts

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describeWithEnvironment('AiAgent', () => {
7474
aidaClient: {} as Host.AidaClient.AidaClient,
7575
});
7676
assert.strictEqual(
77-
agent.buildRequest({input: 'test input'}).options?.temperature,
77+
agent.buildRequest({text: 'test input'}).options?.temperature,
7878
1,
7979
);
8080
});
@@ -85,7 +85,7 @@ describeWithEnvironment('AiAgent', () => {
8585
});
8686
agent.options.temperature = -1;
8787
assert.strictEqual(
88-
agent.buildRequest({input: 'test input'}).options?.temperature,
88+
agent.buildRequest({text: 'test input'}).options?.temperature,
8989
undefined,
9090
);
9191
});
@@ -95,7 +95,7 @@ describeWithEnvironment('AiAgent', () => {
9595
aidaClient: {} as Host.AidaClient.AidaClient,
9696
});
9797
assert.strictEqual(
98-
agent.buildRequest({input: 'test input'}).options?.model_id,
98+
agent.buildRequest({text: 'test input'}).options?.model_id,
9999
'test model',
100100
);
101101
});
@@ -106,7 +106,7 @@ describeWithEnvironment('AiAgent', () => {
106106
serverSideLoggingEnabled: true,
107107
});
108108
assert.strictEqual(
109-
agent.buildRequest({input: 'test input'}).metadata?.disable_user_content_logging,
109+
agent.buildRequest({text: 'test input'}).metadata?.disable_user_content_logging,
110110
false,
111111
);
112112
});
@@ -119,7 +119,7 @@ describeWithEnvironment('AiAgent', () => {
119119
assert.strictEqual(
120120
agent
121121
.buildRequest({
122-
input: 'test input',
122+
text: 'test input',
123123
})
124124
.metadata?.disable_user_content_logging,
125125
true,
@@ -131,27 +131,27 @@ describeWithEnvironment('AiAgent', () => {
131131
aidaClient: {} as Host.AidaClient.AidaClient,
132132
serverSideLoggingEnabled: false,
133133
});
134-
const request = agent.buildRequest({input: 'test input'});
135-
assert.strictEqual(request.input, 'test input');
136-
assert.strictEqual(request.chat_history, undefined);
134+
const request = agent.buildRequest({text: 'test input'});
135+
assert.strictEqual(request.current_message?.parts[0].text, 'test input');
136+
assert.strictEqual(request.historical_contexts, undefined);
137137
});
138138

139139
it('builds a request with a sessionId', async () => {
140140
const agent = new AiAgentMock({
141141
aidaClient: {} as Host.AidaClient.AidaClient,
142142
});
143-
const request = agent.buildRequest({input: 'test input'});
143+
const request = agent.buildRequest({text: 'test input'});
144144
assert.strictEqual(request.metadata?.string_session_id, 'sessionId');
145145
});
146146

147147
it('builds a request with preamble', async () => {
148148
const agent = new AiAgentMock({
149149
aidaClient: {} as Host.AidaClient.AidaClient,
150150
});
151-
const request = agent.buildRequest({input: 'test input'});
152-
assert.strictEqual(request.input, 'test input');
151+
const request = agent.buildRequest({text: 'test input'});
152+
assert.strictEqual(request.current_message?.parts[0].text, 'test input');
153153
assert.strictEqual(request.preamble, 'preamble');
154-
assert.strictEqual(request.chat_history, undefined);
154+
assert.strictEqual(request.historical_contexts, undefined);
155155
});
156156

157157
it('builds a request with chat history', async () => {
@@ -190,26 +190,24 @@ describeWithEnvironment('AiAgent', () => {
190190
text: 'answer',
191191
},
192192
];
193-
const request = agent.buildRequest({
194-
input: 'test input',
195-
});
196-
assert.strictEqual(request.input, 'test input');
197-
assert.deepStrictEqual(request.chat_history, [
193+
const request = agent.buildRequest({text: 'test input'});
194+
assert.strictEqual(request.current_message?.parts[0].text, 'test input');
195+
assert.deepStrictEqual(request.historical_contexts, [
198196
{
199-
text: 'test',
200-
entity: 1,
197+
parts: [{text: 'test'}],
198+
role: 1,
201199
},
202200
{
203-
entity: 2,
204-
text: 'THOUGHT: thought\nTITLE: title\nACTION\naction\nSTOP',
201+
role: 2,
202+
parts: [{text: 'THOUGHT: thought\nTITLE: title\nACTION\naction\nSTOP'}],
205203
},
206204
{
207-
entity: 1,
208-
text: 'OBSERVATION: result',
205+
role: 1,
206+
parts: [{text: 'OBSERVATION: result'}],
209207
},
210208
{
211-
entity: 2,
212-
text: 'answer',
209+
role: 2,
210+
parts: [{text: 'answer'}],
213211
},
214212
]);
215213
});
@@ -240,11 +238,9 @@ describeWithEnvironment('AiAgent', () => {
240238
error: ErrorType.ABORT,
241239
},
242240
];
243-
const request = agent.buildRequest({
244-
input: 'test input',
245-
});
246-
assert.strictEqual(request.input, 'test input');
247-
assert.deepStrictEqual(request.chat_history, undefined);
241+
const request = agent.buildRequest({text: 'test input'});
242+
assert.strictEqual(request.current_message?.parts[0].text, 'test input');
243+
assert.deepStrictEqual(request.historical_contexts, undefined);
248244
});
249245

250246
it('builds a request with aborted query in history before a real request', async () => {
@@ -303,26 +299,24 @@ describeWithEnvironment('AiAgent', () => {
303299
text: 'answer2',
304300
},
305301
];
306-
const request = agent.buildRequest({
307-
input: 'test input',
308-
});
309-
assert.strictEqual(request.input, 'test input');
310-
assert.deepStrictEqual(request.chat_history, [
302+
const request = agent.buildRequest({text: 'test input'});
303+
assert.strictEqual(request.current_message?.parts[0].text, 'test input');
304+
assert.deepStrictEqual(request.historical_contexts, [
311305
{
312-
text: 'test2',
313-
entity: 1,
306+
parts: [{text: 'test2'}],
307+
role: 1,
314308
},
315309
{
316-
entity: 2,
317-
text: 'THOUGHT: thought2\nTITLE: title2\nACTION\naction2\nSTOP',
310+
role: 2,
311+
parts: [{text: 'THOUGHT: thought2\nTITLE: title2\nACTION\naction2\nSTOP'}],
318312
},
319313
{
320-
entity: 1,
321-
text: 'OBSERVATION: result2',
314+
role: 1,
315+
parts: [{text: 'OBSERVATION: result2'}],
322316
},
323317
{
324-
entity: 2,
325-
text: 'answer2',
318+
role: 2,
319+
parts: [{text: 'answer2'}],
326320
},
327321
]);
328322
});
@@ -395,12 +389,12 @@ describeWithEnvironment('AiAgent', () => {
395389

396390
assert.deepStrictEqual(agent.chatHistoryForTesting, [
397391
{
398-
entity: Host.AidaClient.Entity.USER,
399-
text: 'query',
392+
role: Host.AidaClient.Role.USER,
393+
parts: [{text: 'query'}],
400394
},
401395
{
402-
entity: Host.AidaClient.Entity.SYSTEM,
403-
text: 'Partial answer is now completed',
396+
role: Host.AidaClient.Role.MODEL,
397+
parts: [{text: 'Partial answer is now completed'}],
404398
},
405399
]);
406400
});

0 commit comments

Comments
 (0)