ai-speedometer-headless 2.1.4 → 2.1.6
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/dist/ai-speedometer-headless +23 -5
- package/package.json +1 -1
|
@@ -592,7 +592,8 @@ async function benchmarkSingleModelRest(model) {
|
|
|
592
592
|
messages: [{ role: "user", content: TEST_PROMPT }],
|
|
593
593
|
max_tokens: 500,
|
|
594
594
|
temperature: 0.7,
|
|
595
|
-
stream: true
|
|
595
|
+
stream: true,
|
|
596
|
+
stream_options: { include_usage: true }
|
|
596
597
|
};
|
|
597
598
|
if (model.providerType === "google") {
|
|
598
599
|
body["contents"] = [{ parts: [{ text: TEST_PROMPT }] }];
|
|
@@ -600,6 +601,9 @@ async function benchmarkSingleModelRest(model) {
|
|
|
600
601
|
delete body["messages"];
|
|
601
602
|
delete body["max_tokens"];
|
|
602
603
|
delete body["stream"];
|
|
604
|
+
delete body["stream_options"];
|
|
605
|
+
} else if (model.providerType === "anthropic") {
|
|
606
|
+
delete body["stream_options"];
|
|
603
607
|
}
|
|
604
608
|
const response = await fetch(url, {
|
|
605
609
|
method: "POST",
|
|
@@ -607,8 +611,22 @@ async function benchmarkSingleModelRest(model) {
|
|
|
607
611
|
body: JSON.stringify(body)
|
|
608
612
|
});
|
|
609
613
|
if (!response.ok) {
|
|
610
|
-
await response.text();
|
|
611
|
-
|
|
614
|
+
const errBody = await response.text();
|
|
615
|
+
let errDetail = "";
|
|
616
|
+
try {
|
|
617
|
+
const parsed = JSON.parse(errBody);
|
|
618
|
+
if (typeof parsed.error === "object" && parsed.error?.message)
|
|
619
|
+
errDetail = parsed.error.message;
|
|
620
|
+
else if (typeof parsed.error === "string")
|
|
621
|
+
errDetail = parsed.error;
|
|
622
|
+
else if (parsed.message)
|
|
623
|
+
errDetail = parsed.message;
|
|
624
|
+
else
|
|
625
|
+
errDetail = errBody.slice(0, 200);
|
|
626
|
+
} catch {
|
|
627
|
+
errDetail = errBody.slice(0, 200);
|
|
628
|
+
}
|
|
629
|
+
throw new Error(`${response.status} ${response.statusText}${errDetail ? ": " + errDetail : ""}`);
|
|
612
630
|
}
|
|
613
631
|
const reader = response.body.getReader();
|
|
614
632
|
const decoder = new TextDecoder;
|
|
@@ -635,7 +653,7 @@ async function benchmarkSingleModelRest(model) {
|
|
|
635
653
|
if (trimmedLine.startsWith("data: ")) {
|
|
636
654
|
const jsonStr = trimmedLine.slice(6);
|
|
637
655
|
if (jsonStr === "[DONE]")
|
|
638
|
-
|
|
656
|
+
continue;
|
|
639
657
|
const chunk = JSON.parse(jsonStr);
|
|
640
658
|
const chunkTyped = chunk;
|
|
641
659
|
if (chunkTyped.type === "content_block_delta" && chunkTyped.delta?.text) {
|
|
@@ -676,7 +694,7 @@ async function benchmarkSingleModelRest(model) {
|
|
|
676
694
|
if (trimmedLine.startsWith("data: ")) {
|
|
677
695
|
const jsonStr = trimmedLine.slice(6);
|
|
678
696
|
if (jsonStr === "[DONE]")
|
|
679
|
-
|
|
697
|
+
continue;
|
|
680
698
|
const chunk = JSON.parse(jsonStr);
|
|
681
699
|
if (chunk.choices?.[0]?.delta?.content)
|
|
682
700
|
streamedText += chunk.choices[0].delta.content;
|
package/package.json
CHANGED