Skip to content

Commit 2a8d153

Browse files
committed
fix text-generation
1 parent 9ef486b commit 2a8d153

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

packages/inference/src/tasks/nlp/textGeneration.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError";
88
import type { BaseArgs, Options } from "../../types";
99
import { toArray } from "../../utils/toArray";
1010
import { request } from "../custom/request";
11+
import { omit } from "../../utils/omit";
1112

1213
export type { TextGenerationInput, TextGenerationOutput };
1314

@@ -50,8 +51,15 @@ export async function textGeneration(
5051
generated_text: completion.text,
5152
};
5253
} else if (args.provider === "hyperbolic") {
53-
args.prompt = args.inputs;
54-
const raw = await request<HyperbolicTextCompletionOutput>(args, {
54+
const payload = {
55+
messages: [{ content: args.inputs, role: "user" }],
56+
...(args.parameters ? {
57+
max_tokens: args.parameters.max_new_tokens,
58+
...omit(args.parameters, "max_new_tokens"),
59+
} : undefined),
60+
...omit(args, ["inputs", "parameters"]),
61+
}
62+
const raw = await request<HyperbolicTextCompletionOutput>(payload, {
5563
...options,
5664
taskHint: "text-generation",
5765
});

packages/inference/test/tapes.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7268,5 +7268,53 @@
72687268
"server": "cloudflare"
72697269
}
72707270
}
7271+
},
7272+
"5ffb543765bb5fb2c759321a62828095eda7608939187ce57197ae1a618336ae": {
7273+
"url": "https://api.hyperbolic.xyz/v1/chat/completions",
7274+
"init": {
7275+
"headers": {
7276+
"Content-Type": "application/json"
7277+
},
7278+
"method": "POST",
7279+
"body": "{\"messages\":[{\"content\":\"Paris is\",\"role\":\"user\"}],\"temperature\":0,\"top_p\":0.01,\"max_new_tokens\":10,\"model\":\"meta-llama/Meta-Llama-3.1-405B-Instruct\"}"
7280+
},
7281+
"response": {
7282+
"body": "{\"id\":\"chatcmpl-a583deb706944d9796d405f87cb28c8c\",\"object\":\"chat.completion\",\"created\":1739528712,\"model\":\"meta-llama/Meta-Llama-3.1-405B-Instruct\",\"choices\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"...the capital and most populous city of France, known for its stunning architecture, art museums, fashion, and romantic atmosphere. It's often called the \\\"City of Light\\\" (La Ville Lumière) and is famous for its iconic landmarks such as the Eiffel Tower, Notre-Dame Cathedral, and the Louvre Museum.\"},\"finish_reason\":\"stop\",\"logprobs\":null}],\"usage\":{\"prompt_tokens\":37,\"total_tokens\":105,\"completion_tokens\":68}}",
7283+
"status": 200,
7284+
"statusText": "OK",
7285+
"headers": {
7286+
"cf-cache-status": "DYNAMIC",
7287+
"cf-ray": "911c5a4dee0c78fe-CDG",
7288+
"connection": "keep-alive",
7289+
"content-encoding": "gzip",
7290+
"content-type": "application/json",
7291+
"server": "cloudflare",
7292+
"transfer-encoding": "chunked"
7293+
}
7294+
}
7295+
},
7296+
"949ba2dd449c32f12183e7caf5a79f67db7531a2e77961d2aacc04d4a456d88c": {
7297+
"url": "https://api.hyperbolic.xyz/v1/chat/completions",
7298+
"init": {
7299+
"headers": {
7300+
"Content-Type": "application/json"
7301+
},
7302+
"method": "POST",
7303+
"body": "{\"messages\":[{\"content\":\"Paris is\",\"role\":\"user\"}],\"max_tokens\":10,\"temperature\":0,\"top_p\":0.01,\"model\":\"meta-llama/Meta-Llama-3.1-405B-Instruct\"}"
7304+
},
7305+
"response": {
7306+
"body": "{\"id\":\"chatcmpl-02699e2a1ea24037a2f1d6622a849f1f\",\"object\":\"chat.completion\",\"created\":1739528880,\"model\":\"meta-llama/Meta-Llama-3.1-405B-Instruct\",\"choices\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"...the capital and most populous city of France,\"},\"finish_reason\":\"length\",\"logprobs\":null}],\"usage\":{\"prompt_tokens\":37,\"total_tokens\":47,\"completion_tokens\":10}}",
7307+
"status": 200,
7308+
"statusText": "OK",
7309+
"headers": {
7310+
"cf-cache-status": "DYNAMIC",
7311+
"cf-ray": "911c5e690de9d706-CDG",
7312+
"connection": "keep-alive",
7313+
"content-encoding": "gzip",
7314+
"content-type": "application/json",
7315+
"server": "cloudflare",
7316+
"transfer-encoding": "chunked"
7317+
}
7318+
}
72717319
}
72727320
}

0 commit comments

Comments
 (0)