@huggingface/tasks
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "@huggingface/tasks", | ||
"packageManager": "pnpm@8.10.5", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "List of ML tasks for huggingface.co/tasks", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/huggingface/huggingface.js.git", |
@@ -1,6 +0,6 @@ | ||
import type { ModelData } from "../model-data.js"; | ||
import type { PipelineType } from "../pipelines.js"; | ||
import { getModelInputSnippet } from "./inputs.js"; | ||
import type { ModelDataMinimal } from "./types.js"; | ||
export const snippetBasic = (model: ModelData, accessToken: string): string => | ||
export const snippetBasic = (model: ModelDataMinimal, accessToken: string): string => | ||
`curl https://api-inference.huggingface.co/models/${model.id} \\ | ||
@@ -13,3 +13,3 @@ -X POST \\ | ||
export const snippetZeroShotClassification = (model: ModelData, accessToken: string): string => | ||
export const snippetZeroShotClassification = (model: ModelDataMinimal, accessToken: string): string => | ||
`curl https://api-inference.huggingface.co/models/${model.id} \\ | ||
@@ -22,3 +22,3 @@ -X POST \\ | ||
export const snippetFile = (model: ModelData, accessToken: string): string => | ||
export const snippetFile = (model: ModelDataMinimal, accessToken: string): string => | ||
`curl https://api-inference.huggingface.co/models/${model.id} \\ | ||
@@ -30,3 +30,3 @@ -X POST \\ | ||
export const curlSnippets: Partial<Record<PipelineType, (model: ModelData, accessToken: string) => string>> = { | ||
export const curlSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string) => string>> = { | ||
// Same order as in js/src/lib/interfaces/Types.ts | ||
@@ -57,3 +57,3 @@ "text-classification": snippetBasic, | ||
export function getCurlInferenceSnippet(model: ModelData, accessToken: string): string { | ||
export function getCurlInferenceSnippet(model: ModelDataMinimal, accessToken: string): string { | ||
return model.pipeline_tag && model.pipeline_tag in curlSnippets | ||
@@ -64,4 +64,4 @@ ? curlSnippets[model.pipeline_tag]?.(model, accessToken) ?? "" | ||
export function hasCurlInferenceSnippet(model: ModelData): boolean { | ||
export function hasCurlInferenceSnippet(model: Pick<ModelDataMinimal, "pipeline_tag">): boolean { | ||
return !!model.pipeline_tag && model.pipeline_tag in curlSnippets; | ||
} |
@@ -1,3 +0,3 @@ | ||
import type { ModelData } from "../model-data"; | ||
import type { PipelineType } from "../pipelines"; | ||
import type { ModelDataMinimal } from "./types"; | ||
@@ -47,3 +47,3 @@ const inputsZeroShotClassification = () => | ||
const inputsFillMask = (model: ModelData) => `"The answer to the universe is ${model.mask_token}."`; | ||
const inputsFillMask = (model: ModelDataMinimal) => `"The answer to the universe is ${model.mask_token}."`; | ||
@@ -88,3 +88,3 @@ const inputsSentenceSimilarity = () => | ||
const modelInputSnippets: { | ||
[key in PipelineType]?: (model: ModelData) => string; | ||
[key in PipelineType]?: (model: ModelDataMinimal) => string; | ||
} = { | ||
@@ -121,3 +121,3 @@ "audio-to-audio": inputsAudioToAudio, | ||
// Use noQuotes to strip quotes from start & end (example: "abc" -> abc) | ||
export function getModelInputSnippet(model: ModelData, noWrap = false, noQuotes = false): string { | ||
export function getModelInputSnippet(model: ModelDataMinimal, noWrap = false, noQuotes = false): string { | ||
if (model.pipeline_tag) { | ||
@@ -124,0 +124,0 @@ const inputs = modelInputSnippets[model.pipeline_tag]; |
@@ -1,6 +0,6 @@ | ||
import type { ModelData } from "../model-data.js"; | ||
import type { PipelineType } from "../pipelines.js"; | ||
import { getModelInputSnippet } from "./inputs.js"; | ||
import type { ModelDataMinimal } from "./types.js"; | ||
export const snippetBasic = (model: ModelData, accessToken: string): string => | ||
export const snippetBasic = (model: ModelDataMinimal, accessToken: string): string => | ||
`async function query(data) { | ||
@@ -23,3 +23,3 @@ const response = await fetch( | ||
export const snippetZeroShotClassification = (model: ModelData, accessToken: string): string => | ||
export const snippetZeroShotClassification = (model: ModelDataMinimal, accessToken: string): string => | ||
`async function query(data) { | ||
@@ -44,3 +44,3 @@ const response = await fetch( | ||
export const snippetTextToImage = (model: ModelData, accessToken: string): string => | ||
export const snippetTextToImage = (model: ModelDataMinimal, accessToken: string): string => | ||
`async function query(data) { | ||
@@ -62,3 +62,3 @@ const response = await fetch( | ||
export const snippetTextToAudio = (model: ModelData, accessToken: string): string => { | ||
export const snippetTextToAudio = (model: ModelDataMinimal, accessToken: string): string => { | ||
const commonSnippet = `async function query(data) { | ||
@@ -99,3 +99,3 @@ const response = await fetch( | ||
export const snippetFile = (model: ModelData, accessToken: string): string => | ||
export const snippetFile = (model: ModelDataMinimal, accessToken: string): string => | ||
`async function query(filename) { | ||
@@ -119,3 +119,3 @@ const data = fs.readFileSync(filename); | ||
export const jsSnippets: Partial<Record<PipelineType, (model: ModelData, accessToken: string) => string>> = { | ||
export const jsSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string) => string>> = { | ||
// Same order as in js/src/lib/interfaces/Types.ts | ||
@@ -146,3 +146,3 @@ "text-classification": snippetBasic, | ||
export function getJsInferenceSnippet(model: ModelData, accessToken: string): string { | ||
export function getJsInferenceSnippet(model: ModelDataMinimal, accessToken: string): string { | ||
return model.pipeline_tag && model.pipeline_tag in jsSnippets | ||
@@ -153,4 +153,4 @@ ? jsSnippets[model.pipeline_tag]?.(model, accessToken) ?? "" | ||
export function hasJsInferenceSnippet(model: ModelData): boolean { | ||
export function hasJsInferenceSnippet(model: ModelDataMinimal): boolean { | ||
return !!model.pipeline_tag && model.pipeline_tag in jsSnippets; | ||
} |
@@ -1,6 +0,6 @@ | ||
import type { ModelData } from "../model-data.js"; | ||
import type { PipelineType } from "../pipelines.js"; | ||
import { getModelInputSnippet } from "./inputs.js"; | ||
import type { ModelDataMinimal } from "./types.js"; | ||
export const snippetZeroShotClassification = (model: ModelData): string => | ||
export const snippetZeroShotClassification = (model: ModelDataMinimal): string => | ||
`def query(payload): | ||
@@ -15,3 +15,3 @@ response = requests.post(API_URL, headers=headers, json=payload) | ||
export const snippetZeroShotImageClassification = (model: ModelData): string => | ||
export const snippetZeroShotImageClassification = (model: ModelDataMinimal): string => | ||
`def query(data): | ||
@@ -32,3 +32,3 @@ with open(data["image_path"], "rb") as f: | ||
export const snippetBasic = (model: ModelData): string => | ||
export const snippetBasic = (model: ModelDataMinimal): string => | ||
`def query(payload): | ||
@@ -42,3 +42,3 @@ response = requests.post(API_URL, headers=headers, json=payload) | ||
export const snippetFile = (model: ModelData): string => | ||
export const snippetFile = (model: ModelDataMinimal): string => | ||
`def query(filename): | ||
@@ -52,3 +52,3 @@ with open(filename, "rb") as f: | ||
export const snippetTextToImage = (model: ModelData): string => | ||
export const snippetTextToImage = (model: ModelDataMinimal): string => | ||
`def query(payload): | ||
@@ -65,3 +65,3 @@ response = requests.post(API_URL, headers=headers, json=payload) | ||
export const snippetTabular = (model: ModelData): string => | ||
export const snippetTabular = (model: ModelDataMinimal): string => | ||
`def query(payload): | ||
@@ -74,3 +74,3 @@ response = requests.post(API_URL, headers=headers, json=payload) | ||
export const snippetTextToAudio = (model: ModelData): string => { | ||
export const snippetTextToAudio = (model: ModelDataMinimal): string => { | ||
// Transformers TTS pipeline and api-inference-community (AIC) pipeline outputs are diverged | ||
@@ -104,3 +104,3 @@ // with the latest update to inference-api (IA). | ||
export const snippetDocumentQuestionAnswering = (model: ModelData): string => | ||
export const snippetDocumentQuestionAnswering = (model: ModelDataMinimal): string => | ||
`def query(payload): | ||
@@ -117,3 +117,3 @@ with open(payload["image"], "rb") as f: | ||
export const pythonSnippets: Partial<Record<PipelineType, (model: ModelData) => string>> = { | ||
export const pythonSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal) => string>> = { | ||
// Same order as in tasks/src/pipelines.ts | ||
@@ -148,3 +148,3 @@ "text-classification": snippetBasic, | ||
export function getPythonInferenceSnippet(model: ModelData, accessToken: string): string { | ||
export function getPythonInferenceSnippet(model: ModelDataMinimal, accessToken: string): string { | ||
const body = | ||
@@ -161,4 +161,4 @@ model.pipeline_tag && model.pipeline_tag in pythonSnippets ? pythonSnippets[model.pipeline_tag]?.(model) ?? "" : ""; | ||
export function hasPythonInferenceSnippet(model: ModelData): boolean { | ||
export function hasPythonInferenceSnippet(model: ModelDataMinimal): boolean { | ||
return !!model.pipeline_tag && model.pipeline_tag in pythonSnippets; | ||
} |
@@ -24,3 +24,3 @@ export const SPECIAL_TOKENS_ATTRIBUTES = [ | ||
export type SpecialTokensMap = { | ||
[key in (typeof SPECIAL_TOKENS_ATTRIBUTES)[number]]?: string | AddedToken; | ||
[key in (typeof SPECIAL_TOKENS_ATTRIBUTES)[number]]?: string | AddedToken | null; | ||
}; | ||
@@ -27,0 +27,0 @@ /** |
Sorry, the diff of this file is too big to display
980048
179
24116