@@ -35,11 +35,6 @@ import { ExternalApiUsage } from "./external-api-usage";
3535import { ModeledMethod } from "./modeled-method" ;
3636import { ExtensionPack } from "./shared/extension-pack" ;
3737import { autoModel , ModelRequest , ModelResponse } from "./auto-model-api" ;
38- import {
39- autoModelV2 ,
40- ModelRequest as ModelRequestV2 ,
41- ModelResponse as ModelResponseV2 ,
42- } from "./auto-model-api-v2" ;
4338import {
4439 createAutoModelRequest ,
4540 parsePredictedClassifications ,
@@ -56,16 +51,14 @@ import { loadModeledMethods, saveModeledMethods } from "./modeled-method-fs";
5651import { join } from "path" ;
5752import { pickExtensionPack } from "./extension-pack-picker" ;
5853import { getLanguageDisplayName } from "../common/query-language" ;
59- import { runAutoModelQueries } from "./auto-model-codeml-queries" ;
60- import { createAutoModelV2Request , getCandidates } from "./auto-model-v2" ;
61- import { load as loadYaml } from "js-yaml" ;
62- import { loadDataExtensionYaml } from "./yaml" ;
63- import { extLogger } from "../common/logging/vscode" ;
54+ import { AutoModeler } from "./auto-modeler" ;
6455
6556export class DataExtensionsEditorView extends AbstractWebview <
6657 ToDataExtensionsEditorMessage ,
6758 FromDataExtensionsEditorMessage
6859> {
60+ private readonly autoModeler : AutoModeler ;
61+
6962 public constructor (
7063 ctx : ExtensionContext ,
7164 private readonly app : App ,
@@ -82,6 +75,17 @@ export class DataExtensionsEditorView extends AbstractWebview<
8275 ) => void ,
8376 ) {
8477 super ( ctx ) ;
78+
79+ this . autoModeler = new AutoModeler (
80+ app ,
81+ cliServer ,
82+ queryRunner ,
83+ queryStorageDir ,
84+ databaseItem ,
85+ async ( modeledMethods ) => {
86+ await this . postMessage ( { t : "addModeledMethods" , modeledMethods } ) ;
87+ } ,
88+ ) ;
8589 }
8690
8791 public async openView ( ) {
@@ -458,107 +462,11 @@ export class DataExtensionsEditorView extends AbstractWebview<
458462 externalApiUsages : ExternalApiUsage [ ] ,
459463 modeledMethods : Record < string , ModeledMethod > ,
460464 ) : Promise < void > {
461- await withProgress ( async ( progress ) => {
462- const maxStep = 3000 ;
463-
464- progress ( {
465- step : 0 ,
466- maxStep,
467- message : "Retrieving usages" ,
468- } ) ;
469-
470- // Fetch the candidates to send to the model
471- const candidateMethods = getCandidates (
472- this . mode ,
473- externalApiUsages ,
474- modeledMethods ,
475- ) ;
476-
477- // If there are no candidates, there is nothing to model and we just return
478- if ( candidateMethods . length === 0 ) {
479- void extLogger . log ( "No candidates to model. Stopping." ) ;
480- return ;
481- }
482-
483- const usages = await runAutoModelQueries ( {
484- mode : this . mode ,
485- candidateMethods,
486- cliServer : this . cliServer ,
487- queryRunner : this . queryRunner ,
488- queryStorageDir : this . queryStorageDir ,
489- databaseItem : this . databaseItem ,
490- progress : ( update ) => progress ( { ...update , maxStep } ) ,
491- } ) ;
492- if ( ! usages ) {
493- return ;
494- }
495-
496- progress ( {
497- step : 1800 ,
498- maxStep,
499- message : "Creating request" ,
500- } ) ;
501-
502- const request = await createAutoModelV2Request ( this . mode , usages ) ;
503-
504- progress ( {
505- step : 2000 ,
506- maxStep,
507- message : "Sending request" ,
508- } ) ;
509-
510- const response = await this . callAutoModelApiV2 ( request ) ;
511- if ( ! response ) {
512- return ;
513- }
514-
515- progress ( {
516- step : 2500 ,
517- maxStep,
518- message : "Parsing response" ,
519- } ) ;
520-
521- const models = loadYaml ( response . models , {
522- filename : "auto-model.yml" ,
523- } ) ;
524-
525- const loadedMethods = loadDataExtensionYaml ( models ) ;
526- if ( ! loadedMethods ) {
527- return ;
528- }
529-
530- // Any candidate that was part of the response is a negative result
531- // meaning that the canidate is not a sink for the kinds that the LLM is checking for.
532- // For now we model this as a sink neutral method, however this is subject
533- // to discussion.
534- for ( const candidate of candidateMethods ) {
535- if ( ! ( candidate . signature in loadedMethods ) ) {
536- loadedMethods [ candidate . signature ] = {
537- type : "neutral" ,
538- kind : "sink" ,
539- input : "" ,
540- output : "" ,
541- provenance : "ai-generated" ,
542- signature : candidate . signature ,
543- packageName : candidate . packageName ,
544- typeName : candidate . typeName ,
545- methodName : candidate . methodName ,
546- methodParameters : candidate . methodParameters ,
547- } ;
548- }
549- }
550-
551- progress ( {
552- step : 2800 ,
553- maxStep,
554- message : "Applying results" ,
555- } ) ;
556-
557- await this . postMessage ( {
558- t : "addModeledMethods" ,
559- modeledMethods : loadedMethods ,
560- } ) ;
561- } ) ;
465+ await this . autoModeler . startModeling (
466+ externalApiUsages ,
467+ modeledMethods ,
468+ this . mode ,
469+ ) ;
562470 }
563471
564472 private async modelDependency ( ) : Promise < void > {
@@ -688,23 +596,4 @@ export class DataExtensionsEditorView extends AbstractWebview<
688596 }
689597 }
690598 }
691-
692- private async callAutoModelApiV2 (
693- request : ModelRequestV2 ,
694- ) : Promise < ModelResponseV2 | null > {
695- try {
696- return await autoModelV2 ( this . app . credentials , request ) ;
697- } catch ( e ) {
698- if ( e instanceof RequestError && e . status === 429 ) {
699- void showAndLogExceptionWithTelemetry (
700- this . app . logger ,
701- this . app . telemetry ,
702- redactableError ( e ) `Rate limit hit, please try again soon.` ,
703- ) ;
704- return null ;
705- } else {
706- throw e ;
707- }
708- }
709- }
710599}
0 commit comments