handle powershell prompt objects
This commit is contained in:
@@ -203,8 +203,24 @@ function uploadedFileToPart(file: Express.Multer.File): GeminiPart {
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeTextInput(value: unknown) {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item) => normalizeTextInput(item)).join('\n');
|
||||
}
|
||||
|
||||
if (value && typeof value === 'object' && 'value' in value) {
|
||||
return normalizeTextInput((value as { value: unknown }).value);
|
||||
}
|
||||
|
||||
return value == null ? '' : String(value);
|
||||
}
|
||||
|
||||
async function buildParts(body: GenerateRequest, files: Express.Multer.File[] = []) {
|
||||
const prompt = (body.prompt || body.instruction || '').trim();
|
||||
const prompt = normalizeTextInput(body.prompt || body.instruction).trim();
|
||||
if (!prompt) {
|
||||
throw new Error('prompt or instruction is required.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user