@@ -23,9 +23,9 @@ export abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<s
23
23
) : GroundingInfo | undefined {
24
24
if ( "message" in generation ) {
25
25
const responseMetadata = generation ?. message ?. response_metadata ;
26
- const metadata = responseMetadata . groundingMetadata ;
26
+ const metadata = responseMetadata ? .groundingMetadata ;
27
27
const supports =
28
- responseMetadata . groundingSupport ?? metadata . groundingSupports ?? [ ] ;
28
+ responseMetadata ? .groundingSupport ?? metadata ? .groundingSupports ?? [ ] ;
29
29
if ( metadata ) {
30
30
return {
31
31
metadata,
@@ -144,7 +144,7 @@ export abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<s
144
144
* @param grounding
145
145
*/
146
146
protected searchSuggestion ( grounding : GroundingInfo ) : string {
147
- return grounding . metadata . searchEntryPoint ?. renderedContent ?? "" ;
147
+ return grounding ? .metadata ? .searchEntryPoint ?. renderedContent ?? "" ;
148
148
}
149
149
150
150
protected annotateText ( text : string , grounding : GroundingInfo ) : string {
@@ -198,7 +198,8 @@ export class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser
198
198
199
199
protected textSuffix ( _text : string , grounding : GroundingInfo ) : string {
200
200
let ret = "\n" ;
201
- const chunks : GeminiGroundingChunk [ ] = grounding . metadata . groundingChunks ;
201
+ const chunks : GeminiGroundingChunk [ ] =
202
+ grounding ?. metadata ?. groundingChunks ?? [ ] ;
202
203
chunks . forEach ( ( chunk , index ) => {
203
204
ret = `${ ret } ${ this . chunkToString ( chunk , index ) } \n` ;
204
205
} ) ;
0 commit comments