@firebase/ai 2.3.0-canary.7a7634f79 → 2.3.0-canary.ea8512812
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/esm/index.esm.js +23 -19
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/index.cjs.js +23 -19
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.node.cjs.js +23 -19
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +23 -19
- package/dist/index.node.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.node.cjs.js
CHANGED
|
@@ -8,7 +8,7 @@ var util = require('@firebase/util');
|
|
|
8
8
|
var logger$1 = require('@firebase/logger');
|
|
9
9
|
|
|
10
10
|
var name = "@firebase/ai";
|
|
11
|
-
var version = "2.3.0-canary.
|
|
11
|
+
var version = "2.3.0-canary.ea8512812";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @license
|
|
@@ -1596,7 +1596,7 @@ function mapGenerateContentCandidates(candidates) {
|
|
|
1596
1596
|
// videoMetadata is not supported.
|
|
1597
1597
|
// Throw early since developers may send a long video as input and only expect to pay
|
|
1598
1598
|
// for inference on a small portion of the video.
|
|
1599
|
-
if (candidate.content?.parts
|
|
1599
|
+
if (candidate.content?.parts?.some(part => part?.videoMetadata)) {
|
|
1600
1600
|
throw new AIError(AIErrorCode.UNSUPPORTED, 'Part.videoMetadata is not supported in the Gemini Developer API. Please remove this property.');
|
|
1601
1601
|
}
|
|
1602
1602
|
const mappedCandidate = {
|
|
@@ -1698,6 +1698,14 @@ async function* generateResponseSequence(stream, apiSettings) {
|
|
|
1698
1698
|
else {
|
|
1699
1699
|
enhancedResponse = createEnhancedContentResponse(value);
|
|
1700
1700
|
}
|
|
1701
|
+
const firstCandidate = enhancedResponse.candidates?.[0];
|
|
1702
|
+
// Don't yield a response with no useful data for the developer.
|
|
1703
|
+
if (!firstCandidate?.content?.parts &&
|
|
1704
|
+
!firstCandidate?.finishReason &&
|
|
1705
|
+
!firstCandidate?.citationMetadata &&
|
|
1706
|
+
!firstCandidate?.urlContextMetadata) {
|
|
1707
|
+
continue;
|
|
1708
|
+
}
|
|
1701
1709
|
yield enhancedResponse;
|
|
1702
1710
|
}
|
|
1703
1711
|
}
|
|
@@ -1792,32 +1800,28 @@ function aggregateResponses(responses) {
|
|
|
1792
1800
|
* Candidates should always have content and parts, but this handles
|
|
1793
1801
|
* possible malformed responses.
|
|
1794
1802
|
*/
|
|
1795
|
-
if (candidate.content
|
|
1803
|
+
if (candidate.content) {
|
|
1804
|
+
// Skip a candidate without parts.
|
|
1805
|
+
if (!candidate.content.parts) {
|
|
1806
|
+
continue;
|
|
1807
|
+
}
|
|
1796
1808
|
if (!aggregatedResponse.candidates[i].content) {
|
|
1797
1809
|
aggregatedResponse.candidates[i].content = {
|
|
1798
1810
|
role: candidate.content.role || 'user',
|
|
1799
1811
|
parts: []
|
|
1800
1812
|
};
|
|
1801
1813
|
}
|
|
1802
|
-
const newPart = {};
|
|
1803
1814
|
for (const part of candidate.content.parts) {
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
}
|
|
1811
|
-
newPart.text = part.text;
|
|
1812
|
-
}
|
|
1813
|
-
if (part.functionCall) {
|
|
1814
|
-
newPart.functionCall = part.functionCall;
|
|
1815
|
+
const newPart = { ...part };
|
|
1816
|
+
// The backend can send empty text parts. If these are sent back
|
|
1817
|
+
// (e.g. in chat history), the backend will respond with an error.
|
|
1818
|
+
// To prevent this, ignore empty text parts.
|
|
1819
|
+
if (part.text === '') {
|
|
1820
|
+
continue;
|
|
1815
1821
|
}
|
|
1816
|
-
if (Object.keys(newPart).length
|
|
1817
|
-
|
|
1818
|
-
'by a malformed response from the backend.');
|
|
1822
|
+
if (Object.keys(newPart).length > 0) {
|
|
1823
|
+
aggregatedResponse.candidates[i].content.parts.push(newPart);
|
|
1819
1824
|
}
|
|
1820
|
-
aggregatedResponse.candidates[i].content.parts.push(newPart);
|
|
1821
1825
|
}
|
|
1822
1826
|
}
|
|
1823
1827
|
}
|