|
6 | 6 | ContentType,
|
7 | 7 | Message,
|
8 | 8 | Params,
|
| 9 | + Tool, |
9 | 10 | ToolCall,
|
10 | 11 | } from '../../types/requestBody';
|
11 | 12 | import {
|
@@ -36,9 +37,21 @@ import type {
|
36 | 37 | GoogleGenerateContentResponse,
|
37 | 38 | VertexLlamaChatCompleteStreamChunk,
|
38 | 39 | VertexLLamaChatCompleteResponse,
|
| 40 | + GoogleSearchRetrievalTool, |
39 | 41 | } from './types';
|
40 | 42 | import { getMimeType } from './utils';
|
41 | 43 |
|
| 44 | +const buildGoogleSearchRetrievalTool = (tool: Tool) => { |
| 45 | + const googleSearchRetrievalTool: GoogleSearchRetrievalTool = { |
| 46 | + googleSearchRetrieval: {}, |
| 47 | + }; |
| 48 | + if (tool.function.parameters?.dynamicRetrievalConfig) { |
| 49 | + googleSearchRetrievalTool.googleSearchRetrieval.dynamicRetrievalConfig = |
| 50 | + tool.function.parameters.dynamicRetrievalConfig; |
| 51 | + } |
| 52 | + return googleSearchRetrievalTool; |
| 53 | +}; |
| 54 | + |
42 | 55 | export const VertexGoogleChatCompleteConfig: ProviderConfig = {
|
43 | 56 | // https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versioning#gemini-model-versions
|
44 | 57 | model: {
|
@@ -253,12 +266,20 @@ export const VertexGoogleChatCompleteConfig: ProviderConfig = {
|
253 | 266 | default: '',
|
254 | 267 | transform: (params: Params) => {
|
255 | 268 | const functionDeclarations: any = [];
|
| 269 | + const tools: any = []; |
256 | 270 | params.tools?.forEach((tool) => {
|
257 | 271 | if (tool.type === 'function') {
|
258 |
| - functionDeclarations.push(tool.function); |
| 272 | + if (tool.function.name === 'googleSearchRetrieval') { |
| 273 | + tools.push(buildGoogleSearchRetrievalTool(tool)); |
| 274 | + } else { |
| 275 | + functionDeclarations.push(tool.function); |
| 276 | + } |
259 | 277 | }
|
260 | 278 | });
|
261 |
| - return { functionDeclarations }; |
| 279 | + if (functionDeclarations.length) { |
| 280 | + tools.push({ functionDeclarations }); |
| 281 | + } |
| 282 | + return tools; |
262 | 283 | },
|
263 | 284 | },
|
264 | 285 | tool_choice: {
|
@@ -648,6 +669,9 @@ export const GoogleChatCompleteResponseTransform: (
|
648 | 669 | ...(!strictOpenAiCompliance && {
|
649 | 670 | safetyRatings: generation.safetyRatings,
|
650 | 671 | }),
|
| 672 | + ...(!strictOpenAiCompliance && generation.groundingMetadata |
| 673 | + ? { groundingMetadata: generation.groundingMetadata } |
| 674 | + : {}), |
651 | 675 | };
|
652 | 676 | }) ?? [],
|
653 | 677 | usage: {
|
|
0 commit comments