Skip to content

Commit a8a24f5

Browse files
Samiya CaurDevtools-frontend LUCI CQ
authored andcommitted
Add request, response and function call for GenerateCode
Bug: 448793181 Change-Id: Ib6164001b043f7e7b8fc8278b91fcc0247e59e20 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7094291 Commit-Queue: Samiya Caur <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]>
1 parent 356f623 commit a8a24f5

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

front_end/core/host/AidaClient.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as Common from '../common/common.js';
66
import * as Root from '../root/root.js';
77

8+
import * as DispatchHttpRequestClient from './DispatchHttpRequestClient.js';
89
import {InspectorFrontendHostInstance} from './InspectorFrontendHost.js';
910
import type {AidaClientResult, AidaCodeCompleteResult, SyncInformation} from './InspectorFrontendHostAPI.js';
1011
import {bindOutputStream} from './ResourceLoader.js';
@@ -213,6 +214,24 @@ export interface CompleteCodeOptions {
213214
}
214215
/* eslint-enable @typescript-eslint/naming-convention */
215216

217+
/* eslint-disable @typescript-eslint/naming-convention */
218+
export interface GenerateCodeOptions {
219+
temperature?: number;
220+
model_id?: string;
221+
inference_language?: AidaInferenceLanguage;
222+
expect_code_output?: boolean;
223+
}
224+
/* eslint-enable @typescript-eslint/naming-convention */
225+
226+
/* eslint-disable @typescript-eslint/naming-convention */
227+
export interface ContextFile {
228+
path: string;
229+
full_content: string;
230+
selected_content?: string;
231+
programming_language: AidaInferenceLanguage;
232+
}
233+
/* eslint-enable @typescript-eslint/naming-convention */
234+
216235
export enum EditType {
217236
// Unknown edit type
218237
EDIT_TYPE_UNSPECIFIED = 0,
@@ -269,6 +288,27 @@ export interface CompletionRequest {
269288
}
270289
/* eslint-enable @typescript-eslint/naming-convention */
271290

291+
export enum UseCase {
292+
// Unspecified usecase.
293+
USE_CASE_UNSPECIFIED = 0,
294+
295+
// Code generation use case is expected to generate code from scratch
296+
CODE_GENERATION = 1,
297+
}
298+
299+
/* eslint-disable @typescript-eslint/naming-convention */
300+
export interface GenerateCodeRequest {
301+
client: string;
302+
preamble: string;
303+
current_message: Content;
304+
options?: GenerateCodeOptions;
305+
context_files?: ContextFile[];
306+
use_case: UseCase;
307+
metadata: RequestMetadata;
308+
client_feature?: ClientFeature;
309+
}
310+
/* eslint-enable @typescript-eslint/naming-convention */
311+
272312
/* eslint-disable @typescript-eslint/naming-convention */
273313
export interface DoConversationClientEvent {
274314
user_feedback: {
@@ -365,6 +405,11 @@ export interface CompletionResponse {
365405
metadata: ResponseMetadata;
366406
}
367407

408+
export interface GenerateCodeResponse {
409+
samples: GenerationSample[];
410+
metadata: ResponseMetadata;
411+
}
412+
368413
export interface GenerationSample {
369414
generationString: string;
370415
score: number;
@@ -418,6 +463,7 @@ const AidaLanguageToMarkdown: Record<AidaInferenceLanguage, string> = {
418463
};
419464

420465
export const CLIENT_NAME = 'CHROME_DEVTOOLS';
466+
export const SERVICE_NAME = 'aidaService';
421467

422468
const CODE_CHUNK_SEPARATOR = (lang = ''): string => ('\n`````' + lang + '\n');
423469

@@ -659,6 +705,17 @@ export class AidaClient {
659705

660706
return {generatedSamples, metadata};
661707
}
708+
709+
async generateCode(request: GenerateCodeRequest): Promise<GenerateCodeResponse|null> {
710+
const response = await DispatchHttpRequestClient.makeHttpRequest<GenerateCodeResponse>({
711+
service: SERVICE_NAME,
712+
path: '/v1/aida:generateCode',
713+
method: 'POST',
714+
body: JSON.stringify(request),
715+
});
716+
717+
return response;
718+
}
662719
}
663720

664721
export function convertToUserTierEnum(userTier: string|undefined): UserTier {

0 commit comments

Comments
 (0)