Skip to content

Commit f3ca35f

Browse files
committed
add support for streaming grounding responses in gemini
1 parent 65a5494 commit f3ca35f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/providers/google-vertex-ai/chatComplete.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,9 @@ export const GoogleChatCompleteStreamChunkTransform: (
802802
...(!strictOpenAiCompliance && {
803803
safetyRatings: generation.safetyRatings,
804804
}),
805+
...(!strictOpenAiCompliance && generation.groundingMetadata
806+
? { groundingMetadata: generation.groundingMetadata }
807+
: {}),
805808
};
806809
}) ?? [],
807810
usage: usageMetadata,

src/providers/google/chatComplete.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,15 @@ export const GoogleChatCompleteResponseTransform: (
520520

521521
export const GoogleChatCompleteStreamChunkTransform: (
522522
response: string,
523-
fallbackId: string
524-
) => string = (responseChunk, fallbackId) => {
523+
fallbackId: string,
524+
streamState: any,
525+
strictOpenAiCompliance: boolean
526+
) => string = (
527+
responseChunk,
528+
fallbackId,
529+
_streamState,
530+
strictOpenAiCompliance
531+
) => {
525532
let chunk = responseChunk.trim();
526533
if (chunk.startsWith('[')) {
527534
chunk = chunk.slice(1);
@@ -578,6 +585,9 @@ export const GoogleChatCompleteStreamChunkTransform: (
578585
delta: message,
579586
index: generation.index ?? index,
580587
finish_reason: generation.finishReason,
588+
...(!strictOpenAiCompliance && generation.groundingMetadata
589+
? { groundingMetadata: generation.groundingMetadata }
590+
: {}),
581591
};
582592
}) ?? [],
583593
usage: {

0 commit comments

Comments
 (0)