Skip to content

Commit 02b4bb3

Browse files
radamescoyotte508
andauthored
fix streaming test (#140)
Co-authored-by: coyotte508 <[email protected]>
1 parent 2402f72 commit 02b4bb3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/inference/src/HfInference.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,12 @@ export class HfInference {
10481048

10491049
if (options?.blob) {
10501050
if (!response.ok) {
1051+
if (response.headers.get("Content-Type")?.startsWith("application/json")) {
1052+
const output = await response.json();
1053+
if (output.error) {
1054+
throw new Error(output.error);
1055+
}
1056+
}
10511057
throw new Error("An error occurred while fetching the blob");
10521058
}
10531059
return (await response.blob()) as T;

packages/inference/test/HfInference.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe.concurrent(
151151
token: {
152152
id: expect.any(Number),
153153
logprob: expect.any(Number),
154-
text: eot ? tokenText : " " + tokenText,
154+
text: expect.stringContaining(tokenText),
155155
special: eot,
156156
},
157157
generated_text: eot ? fullPhrase : null,

packages/inference/test/tapes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"method": "POST"
6969
},
7070
"response": {
71-
"body": "[{\"generated_text\":\"The answer to the universe is this: it is all of history.\\n\\nIt's time to reclaim our right to see it as we see it. It's time to take back the right to think and to make our opinions heard in the process\"}]",
71+
"body": "[{\"generated_text\":\"The answer to the universe is the fundamental property of space, but we're dealing only with the simplest possible set of answers, which is why we need to talk about how we come to know and understand what sets matter.\\n\\nLet's take a\"}]",
7272
"status": 200,
7373
"statusText": "OK",
7474
"headers": {
@@ -378,7 +378,7 @@
378378
"method": "POST"
379379
},
380380
"response": {
381-
"body": "data:{\"token\":{\"id\":80,\"text\":\" one\",\"logprob\":-0.75390625,\"special\":false},\"generated_text\":null,\"details\":null}\n\ndata:{\"token\":{\"id\":192,\"text\":\" two\",\"logprob\":-0.01940918,\"special\":false},\"generated_text\":null,\"details\":null}\n\ndata:{\"token\":{\"id\":386,\"text\":\" three\",\"logprob\":-0.015197754,\"special\":false},\"generated_text\":null,\"details\":null}\n\ndata:{\"token\":{\"id\":662,\"text\":\" four\",\"logprob\":-0.01940918,\"special\":false},\"generated_text\":null,\"details\":null}\n\ndata:{\"token\":{\"id\":1,\"text\":\"</s>\",\"logprob\":-0.030883789,\"special\":true},\"generated_text\":\"one two three four\",\"details\":null}\n\n",
381+
"body": "data:{\"token\":{\"id\":80,\"text\":\"one\",\"logprob\":-0.75390625,\"special\":false},\"generated_text\":null,\"details\":null}\n\ndata:{\"token\":{\"id\":192,\"text\":\" two\",\"logprob\":-0.01940918,\"special\":false},\"generated_text\":null,\"details\":null}\n\ndata:{\"token\":{\"id\":386,\"text\":\" three\",\"logprob\":-0.015197754,\"special\":false},\"generated_text\":null,\"details\":null}\n\ndata:{\"token\":{\"id\":662,\"text\":\" four\",\"logprob\":-0.01940918,\"special\":false},\"generated_text\":null,\"details\":null}\n\ndata:{\"token\":{\"id\":1,\"text\":\"</s>\",\"logprob\":-0.030883789,\"special\":true},\"generated_text\":\"one two three four\",\"details\":null}\n\n",
382382
"status": 200,
383383
"statusText": "OK",
384384
"headers": {

0 commit comments

Comments
 (0)