Skip to content

Commit

Permalink
fix: ESLint issues in bobuilder-ai-orchestrator (#4837)
Browse files Browse the repository at this point in the history
* fix ESLint issues in botbuilder-ai-orchestrator

* Merge branch 'southworks/update/eslint-packages' into southworks/fix/eslint-issues-botbuilder-ai-orchestrator

* remove eslint config file

* update yarn.lock
  • Loading branch information
JhontSouth authored Jan 6, 2025
1 parent 050ee9f commit 9198d2a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 31 deletions.
11 changes: 0 additions & 11 deletions libraries/botbuilder-ai-orchestrator/eslint.config.cjs

This file was deleted.

3 changes: 1 addition & 2 deletions libraries/botbuilder-ai-orchestrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"botbuilder-dialogs-adaptive": "4.1.6",
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"botbuilder-dialogs-declarative": "4.1.6",
"eslint-plugin-only-warn": "^1.1.0",
"@microsoft/orchestrator-core": "~4.15.1",
"uuid": "^10.0.0"
},
Expand All @@ -45,7 +44,7 @@
"build:rollup": "yarn clean && yarn build && api-extractor run --verbose --local",
"clean": "rimraf _ts3.4 lib tsconfig.tsbuildinfo",
"depcheck": "depcheck --config ../../.depcheckrc",
"lint": "eslint .",
"lint": "eslint . --config ../../eslint.config.cjs",
"postbuild": "downlevel-dts lib _ts3.4/lib --checksum",
"test": "yarn build && nyc mocha tests/",
"test:compat": "api-extractor run --verbose"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class OrchestratorBotComponent extends BotComponent {
},
];
},
})
}),
);
}
}
33 changes: 18 additions & 15 deletions libraries/botbuilder-ai-orchestrator/src/orchestratorRecognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { AdaptiveRecognizer } from 'botbuilder-dialogs-adaptive';
import { Activity, RecognizerResult } from 'botbuilder-core';
import { Converter, ConverterFactory, DialogContext, Recognizer, RecognizerConfiguration } from 'botbuilder-dialogs';

// eslint-disable-next-line @typescript-eslint/no-var-requires
//eslint-disable-next-line @typescript-eslint/no-require-imports
const oc = require('@microsoft/orchestrator-core');

export interface OrchestratorRecognizerConfiguration extends RecognizerConfiguration {
Expand Down Expand Up @@ -173,7 +173,7 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
dc: DialogContext,
activity: Partial<Activity>,
telemetryProperties?: Record<string, string>,
telemetryMetrics?: Record<string, number>
telemetryMetrics?: Record<string, number>,
): Promise<RecognizerResult> {
if (!this._resolver) {
const modelFolder: string = this.modelFolder.getValue(dc.state);
Expand Down Expand Up @@ -209,30 +209,28 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
// add all scores
recognizerResult.intents = results.reduce(function (
intents: { [index: string]: { score: number } },
result
result,
) {
intents[result.label.name] = { score: result.score };
return intents;
},
{});
}, {});
recognizerResult.intents.None = { score: 1.0 };
} else {
// add all scores
recognizerResult.intents = results.reduce(function (
intents: { [index: string]: { score: number } },
result
result,
) {
intents[result.label.name] = { score: result.score };
return intents;
},
{});
}, {});

// disambiguate
if (detectAmbiguity) {
const disambiguationScoreThreshold = this.disambiguationScoreThreshold.getValue(dc.state);
const classifyingScore = topScore - disambiguationScoreThreshold;
const ambiguousResults = results.filter(
(item: { score: number }) => item.score >= classifyingScore
(item: { score: number }) => item.score >= classifyingScore,
);
if (ambiguousResults.length > 1) {
const recognizerResults: Record<string, RecognizerResult> = ambiguousResults
Expand All @@ -242,7 +240,7 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
alteredText: result.closest_text,
entities: recognizerResult.entities,
intents: { [result.label.name]: { score: result.score } },
})
}),
)
.reduce((results: Record<string, RecognizerResult>, result: RecognizerResult) => {
const guid = uuidv4();
Expand All @@ -266,7 +264,7 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
dc,
activity,
telemetryProperties,
telemetryMetrics
telemetryMetrics,
);
recognizerResult.entities = externalResults.entities;
}
Expand All @@ -277,13 +275,13 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
'OrchestratorRecognizer',
recognizerResult,
'OrchestratorRecognizer',
'Orchestrator Recognition'
'Orchestrator Recognition',
);
this.trackRecognizerResult(
dc,
'OrchestratorRecognizerResult',
this.fillRecognizerResultTelemetryProperties(recognizerResult, telemetryProperties, dc),
telemetryMetrics
telemetryMetrics,
);

return recognizerResult;
Expand Down Expand Up @@ -318,7 +316,7 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
protected fillRecognizerResultTelemetryProperties(
recognizerResult: RecognizerResult,
telemetryProperties?: Record<string, string>,
dialogContext?: DialogContext
dialogContext?: DialogContext,
): Record<string, string> {
const topTwo = this.getTopTwoIntents(recognizerResult);
const intent = Object.entries(recognizerResult.intents);
Expand Down Expand Up @@ -379,16 +377,19 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
this._orchestrator = OrchestratorRecognizer.orchestratorMap.has(fullModelFolder)
? OrchestratorRecognizer.orchestratorMap.get(fullModelFolder)
: ((): OrchestratorDictionaryEntry => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
if (!existsSync(fullModelFolder)) {
throw new Error(`Model folder does not exist at ${fullModelFolder}.`);
}

const entityModelFolder: string = resolve(modelFolder, 'entity');
// eslint-disable-next-line security/detect-non-literal-fs-filename
const isEntityExtractionCapable: boolean = existsSync(entityModelFolder);
const orchestrator = new oc.Orchestrator();
if (isEntityExtractionCapable) {
if (!orchestrator.load(fullModelFolder, entityModelFolder)) {
throw new Error(
`Model load failed - model folder ${fullModelFolder}, entity model folder ${entityModelFolder}.`
`Model load failed - model folder ${fullModelFolder}, entity model folder ${entityModelFolder}.`,
);
}
} else {
Expand All @@ -405,11 +406,13 @@ export class OrchestratorRecognizer extends AdaptiveRecognizer implements Orches
})();

const fullSnapshotPath = resolve(snapshotFile);
// eslint-disable-next-line security/detect-non-literal-fs-filename
if (!existsSync(fullSnapshotPath)) {
throw new Error(`Snapshot file does not exist at ${fullSnapshotPath}.`);
}

// Load the snapshot
// eslint-disable-next-line security/detect-non-literal-fs-filename
const snapshot: Uint8Array = readFileSync(fullSnapshotPath);

// Load snapshot and create resolver
Expand Down
2 changes: 0 additions & 2 deletions libraries/botbuilder-ai-orchestrator/tests/mockResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License.
*/

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

const { LabelType } = require('../lib');
class MockResolver {
constructor(score, entityScore) {
Expand Down

0 comments on commit 9198d2a

Please sign in to comment.