Skip to content

Commit

Permalink
another test
Browse files Browse the repository at this point in the history
  • Loading branch information
radames committed Mar 26, 2024
1 parent 71d1dee commit ff66687
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/inference/src/tasks/nlp/textGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export async function textGeneration(
...options,
taskHint: "text-generation",
});
if (typeof res === "object" && res.hasOwnProperty("choices")) {
return res;
}
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.generated_text === "string");
if (!isValidOutput) {
throw new InferenceOutputError("Expected Array<{generated_text: string}>");
Expand Down
19 changes: 19 additions & 0 deletions packages/inference/test/HfInference.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,25 @@ describe.concurrent(
expect(generated_text).toEqual("three");
});

it("textGeneration - OpenAI Specs", async () => {
const ep = hf.endpoint(
"https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2/v1/chat/completions"
);
const res = await ep.textGeneration({
model: "tgi",
messages: [{ role: "user", content: "Complete the this sentence with words one plus one is equal " }],
parameters: {
max_tokens: 500,
return_full_text: false,
temperature: 0.0,
seed: 0,
},
});
if (res.choices && res.choices.length > 0) {
const completion = res.choices[0].message.content;
expect(completion).toContain(" One plus one is equal to two.");
}
});
it("textGenerationStream - OpenAI Specs", async () => {
const ep = hf.endpoint(
"https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2/v1/chat/completions"
Expand Down

0 comments on commit ff66687

Please sign in to comment.