From 500022d4b99736b0d13b6d20dafb474342176a3a Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 10 Apr 2024 21:01:30 +0530 Subject: [PATCH] Import onnxruntime with TypeScript types Refs: - https://github.com/microsoft/onnxruntime/issues/17979 --- desktop/src/main/services/clip.ts | 4 ++-- desktop/src/main/types/onnx-runtime.d.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 desktop/src/main/types/onnx-runtime.d.ts diff --git a/desktop/src/main/services/clip.ts b/desktop/src/main/services/clip.ts index 0ef6053183..525e613424 100644 --- a/desktop/src/main/services/clip.ts +++ b/desktop/src/main/services/clip.ts @@ -14,13 +14,13 @@ import { existsSync } from "fs"; import jpeg from "jpeg-js"; import fs from "node:fs/promises"; import path from "node:path"; -import { CustomErrors } from "../../types/ipc"; +import * as ort from "onnxruntime-node"; import Tokenizer from "../../thirdparty/clip-bpe-ts/mod"; +import { CustomErrors } from "../../types/ipc"; import { writeStream } from "../fs"; import log from "../log"; import { generateTempFilePath } from "../temp"; import { deleteTempFile } from "./ffmpeg"; -const ort = require("onnxruntime-node"); const textModelName = "clip-text-vit-32-uint8.onnx"; const textModelByteSize = 64173509; // 61.2 MB diff --git a/desktop/src/main/types/onnx-runtime.d.ts b/desktop/src/main/types/onnx-runtime.d.ts new file mode 100644 index 0000000000..85fc00ab6f --- /dev/null +++ b/desktop/src/main/types/onnx-runtime.d.ts @@ -0,0 +1,9 @@ +/** + * Types for [onnxruntime-node](https://onnxruntime.ai/docs/api/js/index.html). + * + * Note: these are not the official types but are based on a temporary + * [workaround](https://github.com/microsoft/onnxruntime/issues/17979). + */ +declare module "onnxruntime-node" { + export * from "onnxruntime-common"; +}