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 packages/inference/src/config.ts
Original file line number Diff line number Diff line change
@@ -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";
5 changes: 3 additions & 2 deletions packages/inference/src/snippets/getInferenceSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +38,7 @@ const CLIENTS: Record<InferenceSnippetLanguage, Client[]> = {

const CLIENTS_AUTO_POLICY: Partial<Record<InferenceSnippetLanguage, Client[]>> = {
js: ["huggingface.js"],
python: ["huggingface_hub"],
python: ["huggingface_hub", "openai"],
};

type InputPreparationFn = (model: ModelDataMinimal, opts?: Record<string, unknown>) => object;
Expand Down Expand Up @@ -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,
Expand Down