-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathtextGeneration.ts
24 lines (22 loc) · 1022 Bytes
/
textGeneration.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
import type { TextGenerationInput, TextGenerationOutput } from "@huggingface/tasks";
import { getProviderHelper } from "../../lib/getProviderHelper";
import type { HyperbolicTextCompletionOutput } from "../../providers/hyperbolic";
import type { BaseArgs, Options } from "../../types";
import { innerRequest } from "../../utils/request";
export type { TextGenerationInput, TextGenerationOutput };
/**
* Use to continue text from a prompt. This is a very generic task. Recommended model: gpt2 (it’s a simple model, but fun to play with).
*/
export async function textGeneration(
args: BaseArgs & TextGenerationInput,
options?: Options
): Promise<TextGenerationOutput> {
const providerHelper = getProviderHelper(args.provider ?? "hf-inference", "text-generation");
const { data: response } = await innerRequest<
HyperbolicTextCompletionOutput | TextGenerationOutput | TextGenerationOutput[]
>(args, providerHelper, {
...options,
task: "text-generation",
});
return providerHelper.getResponse(response);
}