@gammatech/aijsx 0.9.1-dev.2024-05-28 → 0.9.2-dev.2024-05-30
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/index.js +17 -8
- package/dist/index.mjs +17 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2546,10 +2546,10 @@ var GoogleClientContext = createContext(() => {
|
|
|
2546
2546
|
return defaultClient3;
|
|
2547
2547
|
});
|
|
2548
2548
|
var defaultClient3 = null;
|
|
2549
|
-
var buildGoogleMessages = (
|
|
2549
|
+
var buildGoogleMessages = (chatMessages) => {
|
|
2550
2550
|
let systemInstruction;
|
|
2551
2551
|
const messages = [];
|
|
2552
|
-
|
|
2552
|
+
chatMessages.forEach(({ role, content }) => {
|
|
2553
2553
|
if (role === "system") {
|
|
2554
2554
|
systemInstruction = content;
|
|
2555
2555
|
return;
|
|
@@ -2690,7 +2690,6 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2690
2690
|
try {
|
|
2691
2691
|
for await (const event of response.stream) {
|
|
2692
2692
|
if (event.candidates) {
|
|
2693
|
-
const chunk = event.candidates[0].content;
|
|
2694
2693
|
if (event.candidates[0]?.finishReason) {
|
|
2695
2694
|
finishReason = event.candidates[0].finishReason;
|
|
2696
2695
|
}
|
|
@@ -2702,12 +2701,22 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2702
2701
|
outputUsage = event.usageMetadata.candidatesTokenCount;
|
|
2703
2702
|
}
|
|
2704
2703
|
}
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2704
|
+
const chunk = event.candidates[0].content;
|
|
2705
|
+
if (!chunk || !chunk.parts) {
|
|
2706
|
+
console.error(
|
|
2707
|
+
`Google response chunk is missing 'parts' field: ${JSON.stringify(
|
|
2708
|
+
chunk
|
|
2709
|
+
)}`
|
|
2710
|
+
);
|
|
2711
|
+
continue;
|
|
2710
2712
|
}
|
|
2713
|
+
if (chunk.parts)
|
|
2714
|
+
for (const block of chunk.parts) {
|
|
2715
|
+
if (block.text) {
|
|
2716
|
+
content += block.text;
|
|
2717
|
+
yield block.text;
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2711
2720
|
}
|
|
2712
2721
|
}
|
|
2713
2722
|
} catch (err) {
|
package/dist/index.mjs
CHANGED
|
@@ -2448,10 +2448,10 @@ var GoogleClientContext = createContext(() => {
|
|
|
2448
2448
|
return defaultClient3;
|
|
2449
2449
|
});
|
|
2450
2450
|
var defaultClient3 = null;
|
|
2451
|
-
var buildGoogleMessages = (
|
|
2451
|
+
var buildGoogleMessages = (chatMessages) => {
|
|
2452
2452
|
let systemInstruction;
|
|
2453
2453
|
const messages = [];
|
|
2454
|
-
|
|
2454
|
+
chatMessages.forEach(({ role, content }) => {
|
|
2455
2455
|
if (role === "system") {
|
|
2456
2456
|
systemInstruction = content;
|
|
2457
2457
|
return;
|
|
@@ -2592,7 +2592,6 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2592
2592
|
try {
|
|
2593
2593
|
for await (const event of response.stream) {
|
|
2594
2594
|
if (event.candidates) {
|
|
2595
|
-
const chunk = event.candidates[0].content;
|
|
2596
2595
|
if (event.candidates[0]?.finishReason) {
|
|
2597
2596
|
finishReason = event.candidates[0].finishReason;
|
|
2598
2597
|
}
|
|
@@ -2604,12 +2603,22 @@ async function* GoogleChatCompletionInner(props, ctx) {
|
|
|
2604
2603
|
outputUsage = event.usageMetadata.candidatesTokenCount;
|
|
2605
2604
|
}
|
|
2606
2605
|
}
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2606
|
+
const chunk = event.candidates[0].content;
|
|
2607
|
+
if (!chunk || !chunk.parts) {
|
|
2608
|
+
console.error(
|
|
2609
|
+
`Google response chunk is missing 'parts' field: ${JSON.stringify(
|
|
2610
|
+
chunk
|
|
2611
|
+
)}`
|
|
2612
|
+
);
|
|
2613
|
+
continue;
|
|
2612
2614
|
}
|
|
2615
|
+
if (chunk.parts)
|
|
2616
|
+
for (const block of chunk.parts) {
|
|
2617
|
+
if (block.text) {
|
|
2618
|
+
content += block.text;
|
|
2619
|
+
yield block.text;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2613
2622
|
}
|
|
2614
2623
|
}
|
|
2615
2624
|
} catch (err) {
|