diff --git a/packages/inference/src/config.ts b/packages/inference/src/config.ts index 00593f892f..5f31a1e759 100644 --- a/packages/inference/src/config.ts +++ b/packages/inference/src/config.ts @@ -1,3 +1,4 @@ export const HF_HUB_URL = "https://huggingface.co"; export const HF_ROUTER_URL = "https://router.huggingface.co"; +export const HF_ROUTER_AUTO_ENDPOINT = `${HF_ROUTER_URL}/v1`; export const HF_HEADER_X_BILL_TO = "X-HF-Bill-To"; diff --git a/packages/inference/src/snippets/getInferenceSnippets.ts b/packages/inference/src/snippets/getInferenceSnippets.ts index 878edb8f38..7dc160497b 100644 --- a/packages/inference/src/snippets/getInferenceSnippets.ts +++ b/packages/inference/src/snippets/getInferenceSnippets.ts @@ -13,6 +13,7 @@ import { makeRequestOptionsFromResolvedModel } from "../lib/makeRequestOptions.j import type { InferenceProviderMappingEntry, InferenceProviderOrPolicy, InferenceTask, RequestArgs } from "../types.js"; import { templates } from "./templates.exported.js"; import { getLogger } from "../lib/logger.js"; +import { HF_ROUTER_AUTO_ENDPOINT } from "../config.js"; export type InferenceSnippetOptions = { streaming?: boolean; @@ -37,7 +38,7 @@ const CLIENTS: Record = { const CLIENTS_AUTO_POLICY: Partial> = { js: ["huggingface.js"], - python: ["huggingface_hub"], + python: ["huggingface_hub", "openai"], }; type InputPreparationFn = (model: ModelDataMinimal, opts?: Record) => object; @@ -179,7 +180,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar { accessToken: accessTokenOrPlaceholder, provider, - endpointUrl: opts?.endpointUrl, + endpointUrl: opts?.endpointUrl ?? (provider === "auto" ? HF_ROUTER_AUTO_ENDPOINT : undefined), ...inputs, } as RequestArgs, inferenceProviderMapping,