diff --git a/e2e/ts/tsconfig.json b/e2e/ts/tsconfig.json index 6bb54701e..5a705a418 100644 --- a/e2e/ts/tsconfig.json +++ b/e2e/ts/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2015", + "target": "ES2022", "module": "commonjs", "strict": true, "esModuleInterop": true, diff --git a/packages/inference/src/index.ts b/packages/inference/src/index.ts index 566b5c1ab..3cd1d8fca 100644 --- a/packages/inference/src/index.ts +++ b/packages/inference/src/index.ts @@ -2,3 +2,6 @@ export { HfInference, HfInferenceEndpoint } from "./HfInference"; export { InferenceOutputError } from "./lib/InferenceOutputError"; export * from "./types"; export * from "./tasks"; + +import * as snippets from "./snippets/index.js"; +export { snippets }; diff --git a/packages/tasks/src/snippets/curl.ts b/packages/inference/src/snippets/curl.ts similarity index 93% rename from packages/tasks/src/snippets/curl.ts rename to packages/inference/src/snippets/curl.ts index 7c846b602..bd86caaba 100644 --- a/packages/tasks/src/snippets/curl.ts +++ b/packages/inference/src/snippets/curl.ts @@ -1,9 +1,13 @@ -import { HF_HUB_INFERENCE_PROXY_TEMPLATE, type SnippetInferenceProvider } from "../inference-providers.js"; -import type { PipelineType } from "../pipelines.js"; -import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js"; -import { stringifyGenerationConfig, stringifyMessages } from "./common.js"; -import { getModelInputSnippet } from "./inputs.js"; -import type { InferenceSnippet, ModelDataMinimal } from "./types.js"; +import { HF_HUB_INFERENCE_PROXY_TEMPLATE, type SnippetInferenceProvider } from "@huggingface/tasks"; +import type { PipelineType } from "@huggingface/tasks/src/pipelines.js"; +import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js"; +import { + type InferenceSnippet, + type ModelDataMinimal, + getModelInputSnippet, + stringifyGenerationConfig, + stringifyMessages, +} from "@huggingface/tasks"; export const snippetBasic = ( model: ModelDataMinimal, diff --git a/packages/inference/src/snippets/index.ts b/packages/inference/src/snippets/index.ts new file mode 100644 index 000000000..142c96564 --- /dev/null +++ b/packages/inference/src/snippets/index.ts @@ -0,0 +1,5 @@ +import * as curl from "./curl.js"; +import * as python from "./python.js"; +import * as js from "./js.js"; + +export { curl, python, js }; diff --git a/packages/tasks/src/snippets/js.ts b/packages/inference/src/snippets/js.ts similarity index 96% rename from packages/tasks/src/snippets/js.ts rename to packages/inference/src/snippets/js.ts index bcb96dce8..c8d38b00b 100644 --- a/packages/tasks/src/snippets/js.ts +++ b/packages/inference/src/snippets/js.ts @@ -1,9 +1,13 @@ -import { openAIbaseUrl, type SnippetInferenceProvider } from "../inference-providers.js"; -import type { PipelineType, WidgetType } from "../pipelines.js"; -import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js"; -import { stringifyGenerationConfig, stringifyMessages } from "./common.js"; -import { getModelInputSnippet } from "./inputs.js"; -import type { InferenceSnippet, ModelDataMinimal } from "./types.js"; +import { openAIbaseUrl, type SnippetInferenceProvider } from "@huggingface/tasks"; +import type { PipelineType, WidgetType } from "@huggingface/tasks/src/pipelines.js"; +import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js"; +import { + type InferenceSnippet, + type ModelDataMinimal, + getModelInputSnippet, + stringifyGenerationConfig, + stringifyMessages, +} from "@huggingface/tasks"; const HFJS_METHODS: Partial> = { "text-classification": "textClassification", diff --git a/packages/tasks/src/snippets/python.ts b/packages/inference/src/snippets/python.ts similarity index 96% rename from packages/tasks/src/snippets/python.ts rename to packages/inference/src/snippets/python.ts index 3ce2d16e1..b1f35bedc 100644 --- a/packages/tasks/src/snippets/python.ts +++ b/packages/inference/src/snippets/python.ts @@ -1,9 +1,13 @@ -import { openAIbaseUrl, type SnippetInferenceProvider } from "../inference-providers.js"; -import type { PipelineType, WidgetType } from "../pipelines.js"; -import type { ChatCompletionInputMessage, GenerationParameters } from "../tasks/index.js"; -import { stringifyGenerationConfig, stringifyMessages } from "./common.js"; -import { getModelInputSnippet } from "./inputs.js"; -import type { InferenceSnippet, ModelDataMinimal } from "./types.js"; +import { openAIbaseUrl, type SnippetInferenceProvider } from "@huggingface/tasks"; +import type { PipelineType, WidgetType } from "@huggingface/tasks/src/pipelines.js"; +import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js"; +import { + type InferenceSnippet, + type ModelDataMinimal, + getModelInputSnippet, + stringifyGenerationConfig, + stringifyMessages, +} from "@huggingface/tasks"; const HFH_INFERENCE_CLIENT_METHODS: Partial> = { "audio-classification": "audio_classification", diff --git a/packages/inference/test/vcr.ts b/packages/inference/test/vcr.ts index 79a548af0..b32cdc202 100644 --- a/packages/inference/test/vcr.ts +++ b/packages/inference/test/vcr.ts @@ -191,9 +191,15 @@ async function vcr( statusText: response.statusText, headers: Object.fromEntries( // Remove varying headers as much as possible - [...response.headers.entries()].filter( - ([key]) => key !== "date" && key !== "content-length" && !key.startsWith("x-") && key !== "via" - ) + (() => { + const entries: [string, string][] = []; + response.headers.forEach((value, key) => { + if (key !== "date" && key !== "content-length" && !key.startsWith("x-") && key !== "via") { + entries.push([key, value]); + } + }); + return entries; + })() ), }, }; diff --git a/packages/tasks-gen/scripts/generate-snippets-fixtures.ts b/packages/tasks-gen/scripts/generate-snippets-fixtures.ts index 56d265820..017e06150 100644 --- a/packages/tasks-gen/scripts/generate-snippets-fixtures.ts +++ b/packages/tasks-gen/scripts/generate-snippets-fixtures.ts @@ -19,14 +19,14 @@ import { existsSync as pathExists } from "node:fs"; import * as fs from "node:fs/promises"; import * as path from "node:path/posix"; -import type { SnippetInferenceProvider, InferenceSnippet } from "@huggingface/tasks"; -import { snippets } from "@huggingface/tasks"; +import { snippets } from "@huggingface/inference"; +import type { SnippetInferenceProvider, InferenceSnippet, ModelDataMinimal } from "@huggingface/tasks"; type LANGUAGE = "sh" | "js" | "py"; const TEST_CASES: { testName: string; - model: snippets.ModelDataMinimal; + model: ModelDataMinimal; languages: LANGUAGE[]; providers: SnippetInferenceProvider[]; opts?: Record; diff --git a/packages/tasks/src/index.ts b/packages/tasks/src/index.ts index 921acfa94..69afd2584 100644 --- a/packages/tasks/src/index.ts +++ b/packages/tasks/src/index.ts @@ -45,11 +45,15 @@ export type { } from "./widget-example.js"; export { SPECIAL_TOKENS_ATTRIBUTES } from "./tokenizer-data.js"; -import * as snippets from "./snippets/index.js"; export * from "./gguf.js"; -export { snippets }; -export type { InferenceSnippet } from "./snippets/index.js"; +export { + type InferenceSnippet, + type ModelDataMinimal, + stringifyGenerationConfig, + stringifyMessages, + getModelInputSnippet, +} from "./snippets/index.js"; export { SKUS, DEFAULT_MEMORY_OPTIONS } from "./hardware.js"; export type { HardwareSpec, SkuType } from "./hardware.js"; diff --git a/packages/tasks/src/snippets/index.ts b/packages/tasks/src/snippets/index.ts index c37645815..bd77dfd52 100644 --- a/packages/tasks/src/snippets/index.ts +++ b/packages/tasks/src/snippets/index.ts @@ -1,7 +1,3 @@ -import * as inputs from "./inputs.js"; -import * as curl from "./curl.js"; -import * as python from "./python.js"; -import * as js from "./js.js"; +export * from "./common.js"; +export * from "./inputs.js"; export * from "./types.js"; - -export { inputs, curl, python, js };