@contentgrowth/llm-service 0.6.9 → 0.6.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -135,21 +135,36 @@ export class GeminiProvider extends BaseLLMProvider {
|
|
|
135
135
|
tools: tools ? [{ functionDeclarations: tools.map(t => t.function) }] : undefined,
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
// New SDK returns candidates directly on result
|
|
139
|
+
// Extract function calls from parts
|
|
140
|
+
let toolCalls = null;
|
|
141
|
+
if (result.candidates?.[0]?.content?.parts) {
|
|
142
|
+
const functionCallParts = result.candidates[0].content.parts.filter(p => p.functionCall);
|
|
143
|
+
if (functionCallParts.length > 0) {
|
|
144
|
+
toolCalls = functionCallParts.map(p => p.functionCall);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
140
147
|
|
|
148
|
+
// Extract text content from parts
|
|
141
149
|
let textContent = '';
|
|
142
150
|
try {
|
|
143
|
-
|
|
151
|
+
if (result.candidates?.[0]?.content?.parts) {
|
|
152
|
+
// Concatenate text from parts
|
|
153
|
+
textContent = result.candidates[0].content.parts
|
|
154
|
+
.filter(p => p.text)
|
|
155
|
+
.map(p => p.text)
|
|
156
|
+
.join('');
|
|
157
|
+
} else if (result.text) {
|
|
158
|
+
textContent = typeof result.text === 'function' ? result.text() : result.text;
|
|
159
|
+
}
|
|
144
160
|
} catch (e) {
|
|
145
|
-
// response.text() throws if there is no text content (e.g. only tool calls)
|
|
146
161
|
// This is expected behavior for tool-only responses
|
|
147
162
|
}
|
|
148
163
|
|
|
149
164
|
// Validate that we have EITHER content OR tool calls
|
|
150
165
|
if (!textContent && (!toolCalls || toolCalls.length === 0)) {
|
|
151
166
|
console.error('[GeminiProvider] Model returned empty response (no text, no tool calls)');
|
|
152
|
-
console.error('[GeminiProvider]
|
|
167
|
+
console.error('[GeminiProvider] Full result:', JSON.stringify(result, null, 2));
|
|
153
168
|
throw new LLMServiceException(
|
|
154
169
|
'Model returned empty response. This usually means the prompt or schema is confusing the model.',
|
|
155
170
|
500
|
|
@@ -343,12 +358,13 @@ export class GeminiProvider extends BaseLLMProvider {
|
|
|
343
358
|
generationConfig
|
|
344
359
|
});
|
|
345
360
|
|
|
346
|
-
|
|
347
|
-
const imagePart =
|
|
361
|
+
// New SDK returns candidates directly on result, not result.response
|
|
362
|
+
const imagePart = result.candidates?.[0]?.content?.parts?.find(
|
|
348
363
|
part => part.inlineData && part.inlineData.mimeType?.startsWith('image/')
|
|
349
364
|
);
|
|
350
365
|
|
|
351
366
|
if (!imagePart || !imagePart.inlineData) {
|
|
367
|
+
console.error('[GeminiProvider] No image in response. Result:', JSON.stringify(result, null, 2));
|
|
352
368
|
throw new Error('No image data in response');
|
|
353
369
|
}
|
|
354
370
|
|