-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathfeatureExtraction.ts
31 lines (27 loc) · 1.33 KB
/
featureExtraction.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { FeatureExtractionInput } from "@huggingface/tasks";
import { getProviderHelper } from "../../lib/getProviderHelper";
import type { BaseArgs, Options } from "../../types";
import { innerRequest } from "../../utils/request";
interface FeatureExtractionOAICompatInput {
encoding_format?: "float" | "base64";
dimensions?: number | null;
}
export type FeatureExtractionArgs = BaseArgs & FeatureExtractionInput & FeatureExtractionOAICompatInput;
/**
* Returned values are a multidimensional array of floats (dimension depending on if you sent a string or a list of string, and if the automatic reduction, usually mean_pooling for instance was applied for you or not. This should be explained on the model's README).
*/
export type FeatureExtractionOutput = (number | number[] | number[][])[];
/**
* This task reads some text and outputs raw float values, that are usually consumed as part of a semantic database/semantic search.
*/
export async function featureExtraction(
args: FeatureExtractionArgs,
options?: Options
): Promise<FeatureExtractionOutput> {
const providerHelper = getProviderHelper(args.provider ?? "hf-inference", "feature-extraction");
const { data: res } = await innerRequest<FeatureExtractionOutput>(args, providerHelper, {
...options,
task: "feature-extraction",
});
return providerHelper.getResponse(res);
}