| |
| |
| |
| |
| |
|
|
| import type { GenerateContentParameters } from '@google/genai'; |
|
|
| |
| |
| |
| |
| |
| export function convertToRestPayload( |
| req: GenerateContentParameters, |
| ): Record<string, unknown> { |
| |
| |
| const { |
| systemInstruction: sdkSystemInstruction, |
| tools: sdkTools, |
| toolConfig: sdkToolConfig, |
| safetySettings: sdkSafetySettings, |
| cachedContent: sdkCachedContent, |
| abortSignal: _sdkAbortSignal, |
| ...pureGenerationConfig |
| } = req.config || {}; |
|
|
| |
| let restSystemInstruction; |
| if (typeof sdkSystemInstruction === 'string') { |
| restSystemInstruction = { |
| parts: [{ text: sdkSystemInstruction }], |
| }; |
| } else if (sdkSystemInstruction !== undefined) { |
| restSystemInstruction = sdkSystemInstruction; |
| } |
|
|
| const restPayload: Record<string, unknown> = { |
| contents: req.contents, |
| }; |
|
|
| |
| if (Object.keys(pureGenerationConfig).length > 0) { |
| restPayload['generationConfig'] = pureGenerationConfig; |
| } |
|
|
| |
| if (restSystemInstruction) |
| restPayload['systemInstruction'] = restSystemInstruction; |
| if (sdkTools) restPayload['tools'] = sdkTools; |
| if (sdkToolConfig) restPayload['toolConfig'] = sdkToolConfig; |
| if (sdkSafetySettings) restPayload['safetySettings'] = sdkSafetySettings; |
| if (sdkCachedContent) restPayload['cachedContent'] = sdkCachedContent; |
|
|
| return restPayload; |
| } |
|
|