@huggingface/inference 2.6.4 → 2.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -1,10 +1,12 @@
1
+ import type { PipelineType } from "@huggingface/tasks";
2
+
1
3
  export interface Options {
2
4
  /**
3
5
  * (Default: true) Boolean. If a request 503s and wait_for_model is set to false, the request will be retried with the same parameters but with wait_for_model set to true.
4
6
  */
5
7
  retry_on_error?: boolean;
6
8
  /**
7
- * (Default: true). Boolean. There is a cache layer on the inference API to speedup requests we have already seen. Most models can use those results as is as models are deterministic (meaning the results will be the same anyway). However if you use a non deterministic model, you can set this parameter to prevent the caching mechanism from being used resulting in a real new query.
9
+ * (Default: true). Boolean. There is a cache layer on Inference API (serverless) to speedup requests we have already seen. Most models can use those results as is as models are deterministic (meaning the results will be the same anyway). However if you use a non deterministic model, you can set this parameter to prevent the caching mechanism from being used resulting in a real new query.
8
10
  */
9
11
  use_cache?: boolean;
10
12
  /**
@@ -35,39 +37,7 @@ export interface Options {
35
37
  includeCredentials?: string | boolean;
36
38
  }
37
39
 
38
- export type InferenceTask =
39
- | "audio-classification"
40
- | "audio-to-audio"
41
- | "automatic-speech-recognition"
42
- | "conversational"
43
- | "depth-estimation"
44
- | "document-question-answering"
45
- | "feature-extraction"
46
- | "fill-mask"
47
- | "image-classification"
48
- | "image-segmentation"
49
- | "image-to-image"
50
- | "image-to-text"
51
- | "object-detection"
52
- | "video-classification"
53
- | "question-answering"
54
- | "reinforcement-learning"
55
- | "sentence-similarity"
56
- | "summarization"
57
- | "table-question-answering"
58
- | "tabular-classification"
59
- | "tabular-regression"
60
- | "text-classification"
61
- | "text-generation"
62
- | "text-to-image"
63
- | "text-to-speech"
64
- | "text-to-video"
65
- | "token-classification"
66
- | "translation"
67
- | "unconditional-image-generation"
68
- | "visual-question-answering"
69
- | "zero-shot-classification"
70
- | "zero-shot-image-classification";
40
+ export type InferenceTask = Exclude<PipelineType, "other">;
71
41
 
72
42
  export interface BaseArgs {
73
43
  /**
@@ -77,7 +47,7 @@ export interface BaseArgs {
77
47
  */
78
48
  accessToken?: string;
79
49
  /**
80
- * The model to use. Can be a full URL for HF inference endpoints.
50
+ * The model to use. Can be a full URL for a dedicated inference endpoint.
81
51
  *
82
52
  * If not specified, will call huggingface.co/api/tasks to get the default model for the task.
83
53
  */
@@ -1,81 +0,0 @@
1
- import { InferenceOutputError } from "../../lib/InferenceOutputError";
2
- import type { BaseArgs, Options } from "../../types";
3
- import { request } from "../custom/request";
4
-
5
- export type ConversationalArgs = BaseArgs & {
6
- inputs: {
7
- /**
8
- * A list of strings corresponding to the earlier replies from the model.
9
- */
10
- generated_responses?: string[];
11
- /**
12
- * A list of strings corresponding to the earlier replies from the user. Should be of the same length of generated_responses.
13
- */
14
- past_user_inputs?: string[];
15
- /**
16
- * The last input from the user in the conversation.
17
- */
18
- text: string;
19
- };
20
- parameters?: {
21
- /**
22
- * (Default: None). Integer to define the maximum length in tokens of the output summary.
23
- */
24
- max_length?: number;
25
- /**
26
- * (Default: None). Float (0-120.0). The amount of time in seconds that the query should take maximum. Network can cause some overhead so it will be a soft limit.
27
- */
28
- max_time?: number;
29
- /**
30
- * (Default: None). Integer to define the minimum length in tokens of the output summary.
31
- */
32
- min_length?: number;
33
- /**
34
- * (Default: None). Float (0.0-100.0). The more a token is used within generation the more it is penalized to not be picked in successive generation passes.
35
- */
36
- repetition_penalty?: number;
37
- /**
38
- * (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.
39
- */
40
- temperature?: number;
41
- /**
42
- * (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
43
- */
44
- top_k?: number;
45
- /**
46
- * (Default: None). Float to define the tokens that are within the sample operation of text generation. Add tokens in the sample for more probable to least probable until the sum of the probabilities is greater than top_p.
47
- */
48
- top_p?: number;
49
- };
50
- };
51
-
52
- export interface ConversationalOutput {
53
- conversation: {
54
- generated_responses: string[];
55
- past_user_inputs: string[];
56
- };
57
- generated_text: string;
58
- warnings: string[];
59
- }
60
-
61
- /**
62
- * This task corresponds to any chatbot like structure. Models tend to have shorter max_length, so please check with caution when using a given model if you need long range dependency or not. Recommended model: microsoft/DialoGPT-large.
63
- *
64
- */
65
- export async function conversational(args: ConversationalArgs, options?: Options): Promise<ConversationalOutput> {
66
- const res = await request<ConversationalOutput>(args, { ...options, taskHint: "conversational" });
67
- const isValidOutput =
68
- Array.isArray(res.conversation.generated_responses) &&
69
- res.conversation.generated_responses.every((x) => typeof x === "string") &&
70
- Array.isArray(res.conversation.past_user_inputs) &&
71
- res.conversation.past_user_inputs.every((x) => typeof x === "string") &&
72
- typeof res.generated_text === "string" &&
73
- (typeof res.warnings === "undefined" ||
74
- (Array.isArray(res.warnings) && res.warnings.every((x) => typeof x === "string")));
75
- if (!isValidOutput) {
76
- throw new InferenceOutputError(
77
- "Expected {conversation: {generated_responses: string[], past_user_inputs: string[]}, generated_text: string, warnings: string[]}"
78
- );
79
- }
80
- return res;
81
- }