Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*

.tshy-build
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down
3 changes: 2 additions & 1 deletion packages/inference/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
tapes.json
src/vendor
src/vendor
.tshy-build
4 changes: 3 additions & 1 deletion packages/inference/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ pnpm-lock.yaml
README.md
dist
test/tapes.json
src/vendor
src/vendor
.tshy-build
.tshy
8 changes: 8 additions & 0 deletions packages/inference/.tshy/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"module": "nodenext",
"moduleResolution": "nodenext"
}
}
16 changes: 16 additions & 0 deletions packages/inference/.tshy/commonjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.cts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../src/**/*.mts",
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/commonjs"
}
}
15 changes: 15 additions & 0 deletions packages/inference/.tshy/esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/esm"
}
}
36 changes: 25 additions & 11 deletions packages/inference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
"!src/snippets/templates/**/*.jinja"
],
"source": "src/index.ts",
"types": "./dist/src/index.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
"types": "./dist/src/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
"types": "./dist/commonjs/index.d.ts",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js",
"tshy": {
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"type": "module",
"scripts": {
"build": "pnpm run export-templates && tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
"dts": "tsx scripts/generate-dts.ts && tsc --noEmit dist/index.d.ts",
"build": "pnpm run export-templates && pnpm run package-to-ts && tshy",
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
"lint:check": "eslint --ext .cjs,.ts .",
"format": "prettier --write .",
Expand All @@ -52,7 +52,8 @@
"test:browser": "vitest run --browser.name=chrome --browser.headless --config vitest.config.mts",
"check": "tsc",
"dev": "pnpm run export-templates && tsup src/index.ts --format cjs,esm --watch",
"export-templates": "tsx scripts/export-templates.ts"
"export-templates": "tsx scripts/export-templates.ts",
"package-to-ts": "tsx scripts/package-json-to-ts.ts"
},
"dependencies": {
"@huggingface/tasks": "workspace:^",
Expand All @@ -61,5 +62,18 @@
"devDependencies": {
"@types/node": "18.13.0"
},
"resolutions": {}
"resolutions": {},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
}
}
198 changes: 0 additions & 198 deletions packages/inference/scripts/generate-dts.ts

This file was deleted.

12 changes: 12 additions & 0 deletions packages/inference/scripts/package-json-to-ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { readFileSync, writeFileSync } from "node:fs";

const pkg = JSON.parse(readFileSync("./package.json", "utf8"));

const content = [
"// Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783",
`export const PACKAGE_VERSION = ${JSON.stringify(pkg.version)};`,
`export const PACKAGE_NAME = ${JSON.stringify(pkg.name)};`,
"",
].join("\n");

writeFileSync("./src/package.ts", content);
8 changes: 4 additions & 4 deletions packages/inference/src/InferenceClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as tasks from "./tasks";
import type { Options } from "./types";
import { omit } from "./utils/omit";
import { typedEntries } from "./utils/typedEntries";
import * as tasks from "./tasks/index.js";
import type { Options } from "./types.js";
import { omit } from "./utils/omit.js";
import { typedEntries } from "./utils/typedEntries.js";

/* eslint-disable @typescript-eslint/no-empty-interface */
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
Expand Down
8 changes: 4 additions & 4 deletions packages/inference/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient";
export { InferenceOutputError } from "./lib/InferenceOutputError";
export * from "./types";
export * from "./tasks";
export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient.js";
export { InferenceOutputError } from "./lib/InferenceOutputError.js";
export * from "./types.js";
export * from "./tasks/index.js";
import * as snippets from "./snippets/index.js";

export { snippets };
4 changes: 2 additions & 2 deletions packages/inference/src/lib/getDefaultTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HF_HUB_URL } from "../config";
import { isUrl } from "./isUrl";
import { HF_HUB_URL } from "../config.js";
import { isUrl } from "./isUrl.js";

/**
* We want to make calls to the huggingface hub the least possible, eg if
Expand Down
10 changes: 5 additions & 5 deletions packages/inference/src/lib/getInferenceProviderMapping.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { WidgetType } from "@huggingface/tasks";
import { HF_HUB_URL } from "../config";
import { HARDCODED_MODEL_INFERENCE_MAPPING } from "../providers/consts";
import { EQUIVALENT_SENTENCE_TRANSFORMERS_TASKS } from "../providers/hf-inference";
import type { InferenceProvider, InferenceProviderOrPolicy, ModelId } from "../types";
import { typedInclude } from "../utils/typedInclude";
import { HF_HUB_URL } from "../config.js";
import { HARDCODED_MODEL_INFERENCE_MAPPING } from "../providers/consts.js";
import { EQUIVALENT_SENTENCE_TRANSFORMERS_TASKS } from "../providers/hf-inference.js";
import type { InferenceProvider, InferenceProviderOrPolicy, ModelId } from "../types.js";
import { typedInclude } from "../utils/typedInclude.js";

export const inferenceProviderMappingCache = new Map<ModelId, InferenceProviderMapping>();

Expand Down
Loading