Skip to content

Commit

Permalink
[ai] Precise Typechecking
Browse files Browse the repository at this point in the history
  • Loading branch information
deyaaeldeen committed Dec 10, 2024
1 parent 53155a8 commit 2680455
Show file tree
Hide file tree
Showing 121 changed files with 614 additions and 375 deletions.
15 changes: 8 additions & 7 deletions sdk/ai/ai-inference-rest/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ export default azsdkEslint.config([
{
rules: {
"@azure/azure-sdk/ts-modules-only-named": "warn",
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
"@azure/azure-sdk/ts-package-json-types": "warn",
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
"tsdoc/syntax": "warn",
"@azure/azure-sdk/ts-package-json-module": "off",
"@azure/azure-sdk/ts-package-json-files-required": "off",
"@azure/azure-sdk/ts-package-json-main-is-cjs": "off",
}
},
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
7 changes: 6 additions & 1 deletion sdk/ai/ai-inference-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"browser",
"react-native"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"type": "module",
"files": [
Expand Down Expand Up @@ -94,7 +95,11 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "^4.3.0",
"@azure/monitor-opentelemetry-exporter": "1.0.0-beta.27",
"@opentelemetry/instrumentation": "0.56.0",
"@azure/opentelemetry-instrumentation-azure-sdk": "1.0.0-beta.7",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/sdk-trace-node": "1.29.0",
"@types/node": "^18.0.0",
"@vitest/browser": "^2.0.5",
"@vitest/coverage-istanbul": "^2.0.5",
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/ai-inference-rest/src/tracingHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { isError } from "@azure/core-util";
import type { PipelineRequest, PipelineResponse } from "@azure/core-rest-pipeline";

const INFERENCE_GEN_AI_SYSTEM_NAME = "az.ai.inference";
const isContentRecordingEnabled = () =>
const isContentRecordingEnabled = (): boolean =>
envVarToBoolean("AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED");

enum TracingAttributesEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe("chat test suite", () => {
const reader = (readableStream as any).getReader();
const buffers: Uint8Array[] = [];
try {
// eslint-disable-next-line no-constant-condition
while (true) {
const { value, done } = await reader.read();
if (done) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getImageDataUrl(imageFile: string, imageFormat: string): string {
} catch (error) {
console.error(`Could not read '${imageFile}'.`);
console.error("Set the correct path to the image file before running this sample.");
process.exit(1);
throw error;
}
}

Expand Down
11 changes: 9 additions & 2 deletions sdk/ai/ai-inference-rest/test/public/tracing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("tracing test suite", () => {
return `The temperature in ${location} is 72 degrees ${unit}`;
};

const updateToolCalls = (toolCallArray: Array<any>, functionArray: Array<any>) => {
const updateToolCalls = (toolCallArray: Array<any>, functionArray: Array<any>): void => {
const dummyFunction = { name: "", arguments: "", id: "" };
while (functionArray.length < toolCallArray.length) {
functionArray.push(dummyFunction);
Expand All @@ -78,7 +78,14 @@ describe("tracing test suite", () => {
}
};

const handleToolCalls = (functionArray: Array<any>) => {
const handleToolCalls = (
functionArray: Array<any>,
): {
role: string;
content: string;
tool_call_id: any;
name: any;
}[] => {
const messageArray = [];
for (const func of functionArray) {
const funcArgs = JSON.parse(func.arguments);
Expand Down
9 changes: 1 addition & 8 deletions sdk/ai/ai-inference-rest/tsconfig.browser.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"extends": "./.tshy/build.json",
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts"],
"exclude": ["./test/**/node/**/*.ts"],
"compilerOptions": {
"outDir": "./dist-test/browser",
"rootDir": ".",
"skipLibCheck": true
}
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
14 changes: 6 additions & 8 deletions sdk/ai/ai-inference-rest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"paths": { "@azure-rest/ai-inference": ["./src/index"] },
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"ts-node": { "esm": true },
"include": ["./src/**/*.ts", "test/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
9 changes: 9 additions & 0 deletions sdk/ai/ai-inference-rest/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig.samples.base.json",
"compilerOptions": {
"paths": {
"@azure-rest/ai-inference": ["./dist/esm"]
},
"lib": ["DOM"]
}
}
3 changes: 3 additions & 0 deletions sdk/ai/ai-inference-rest/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
3 changes: 3 additions & 0 deletions sdk/ai/ai-inference-rest/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"]
}
7 changes: 6 additions & 1 deletion sdk/ai/ai-inference-rest/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export default mergeConfig(
defineConfig({
test: {
testTimeout: 50000,
include: ["test/internal/**/*.spec.ts", "test/public/**/*.spec.ts"],
include: ["test/**/*.spec.ts"],
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
},
}),
);
11 changes: 11 additions & 0 deletions sdk/ai/ai-inference-rest/vitest.esm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);
12 changes: 12 additions & 0 deletions sdk/cognitivelanguage/ai-language-conversations/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default azsdkEslint.config([
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
5 changes: 3 additions & 2 deletions sdk/cognitivelanguage/ai-language-conversations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"integration-test:node": "dev-tool run test:vitest",
"integration-test:node": "dev-tool run test:vitest --esm",
"lint": "eslint package.json api-extractor.json src test",
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
"pack": "npm pack 2>&1",
Expand Down Expand Up @@ -115,7 +115,8 @@
"browser",
"react-native"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"browser": "./dist/browser/index.js",
"exports": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type { ConversationAnalysisOptions } from "../../../src/index.js";
import { ConversationAnalysisClient } from "../../../src/index.js";
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
import type { RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder";
import { Recorder, assertEnvironmentVariable } from "@azure-tools/test-recorder";
import { AzureKeyCredential } from "@azure/core-auth";
import { createTestCredential } from "@azure-tools/test-credential";
Expand Down Expand Up @@ -64,7 +64,7 @@ export function createClient(options: {
* Should be called first in the test suite to make sure environment variables are
* read before they are being used.
*/
export async function startRecorder(currentTest?: Test): Promise<Recorder> {
export async function startRecorder(currentTest?: TestInfo): Promise<Recorder> {
const recorder = new Recorder(currentTest);
await recorder.start(recorderStartOptions);
await recorder.setMatcher("CustomDefaultMatcher", { excludedHeaders: ["Accept-Language"] });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"extends": "./.tshy/build.json",
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"],
"exclude": ["./test/**/node/**/*.ts"],
"compilerOptions": {
"outDir": "./dist-test/browser",
"rootDir": ".",
"skipLibCheck": true
}
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
23 changes: 6 additions & 17 deletions sdk/cognitivelanguage/ai-language-conversations/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"paths": {
"@azure/ai-language-conversations": ["./src/index"]
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": [
"src/**/*.ts",
"src/**/*.mts",
"src/**/*.cts",
"samples-dev/**/*.ts",
"test/**/*.ts",
"test/**/*.mts",
"test/**/*.cts"
]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.samples.base.json",
"compilerOptions": {
"paths": {
"@azure/ai-language-conversations": ["./dist/esm"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default mergeConfig(
include: ["test/**/*.spec.ts"],
hookTimeout: 5000000,
testTimeout: 5000000,
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
},
}),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { mergeConfig } from "vitest/config";
import vitestConfig from "./vitest.config.ts";
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";

export default mergeConfig(
vitestConfig,
vitestEsmConfig
);
12 changes: 12 additions & 0 deletions sdk/cognitivelanguage/ai-language-text/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default azsdkEslint.config([
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
5 changes: 3 additions & 2 deletions sdk/cognitivelanguage/ai-language-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"generate:client": "autorest --typescript swagger/README.md",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
"integration-test:node": "dev-tool run test:vitest",
"integration-test:node": "dev-tool run test:vitest --esm",
"lint": "eslint package.json api-extractor.json src test",
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
"pack": "npm pack 2>&1",
Expand Down Expand Up @@ -132,7 +132,8 @@
"browser",
"react-native"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"browser": "./dist/browser/index.js",
"exports": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{
"extends": "./.tshy/build.json",
"include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"],
"exclude": ["./test/**/node/**/*.ts"],
"compilerOptions": {
"outDir": "./dist-test/browser",
"rootDir": ".",
"skipLibCheck": true
}
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
23 changes: 6 additions & 17 deletions sdk/cognitivelanguage/ai-language-text/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"paths": {
"@azure/ai-language-text": ["./src/index"]
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": [
"src/**/*.ts",
"src/**/*.mts",
"src/**/*.cts",
"samples-dev/**/*.ts",
"test/**/*.ts",
"test/**/*.mts",
"test/**/*.cts"
]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
8 changes: 8 additions & 0 deletions sdk/cognitivelanguage/ai-language-text/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.samples.base.json",
"compilerOptions": {
"paths": {
"@azure/ai-language-text": ["./dist/esm"]
}
}
}
3 changes: 3 additions & 0 deletions sdk/cognitivelanguage/ai-language-text/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
3 changes: 3 additions & 0 deletions sdk/cognitivelanguage/ai-language-text/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"]
}
5 changes: 5 additions & 0 deletions sdk/cognitivelanguage/ai-language-text/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default mergeConfig(
include: ["test/**/*.spec.ts"],
hookTimeout: 5000000,
testTimeout: 5000000,
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
},
}),
);
Loading

0 comments on commit 2680455

Please sign in to comment.