@contentgrowth/llm-service 0.6.98 → 0.7.0

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentgrowth/llm-service",
3
- "version": "0.6.98",
3
+ "version": "0.7.0",
4
4
  "description": "Unified LLM Service for Content Growth",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -102,7 +102,7 @@ export class GeminiProvider extends BaseLLMProvider {
102
102
  }
103
103
  break;
104
104
  case 'tool':
105
- role = 'function';
105
+ role = 'user';
106
106
  const preceding_message = messages[index - 1];
107
107
  const tool_call = preceding_message?.tool_calls?.find(tc => tc.id === msg.tool_call_id);
108
108
  parts = [{
@@ -111,6 +111,16 @@ export class GeminiProvider extends BaseLLMProvider {
111
111
  response: { content: msg.content },
112
112
  }
113
113
  }];
114
+
115
+ // Fix for JSON mode: If JSON is requested, remind the model to output JSON after tool execution
116
+ // This is necessary because strict JSON mode is disabled when tools are present.
117
+ if (options.responseFormat === 'json' || options.responseFormat?.type === 'json_schema' || options.responseSchema) {
118
+ parts.push({ text: "Please ensure the final response is valid JSON as per the system instructions." });
119
+ } else {
120
+ // Generic reminder to help model stay on track with system prompt instructions (e.g. formatting)
121
+ // even if no specific JSON mode is configured.
122
+ parts.push({ text: "Please ensure the final response follows the system prompt instructions." });
123
+ }
114
124
  break;
115
125
  default:
116
126
  return null;
@@ -140,6 +150,14 @@ export class GeminiProvider extends BaseLLMProvider {
140
150
 
141
151
  if (tools && tools.length > 0) {
142
152
  requestOptions.config.tools = [{ functionDeclarations: tools.map(t => t.function) }];
153
+ // CRITICAL: Cannot enforce JSON mode (responseMimeType/responseSchema) when tools are present
154
+ // because the model needs to be able to return tool calls (which are not JSON text).
155
+ // We must rely on the system prompt for JSON formatting in this case.
156
+ if (requestOptions.config.responseMimeType === 'application/json') {
157
+ console.warn('[GeminiProvider] Disabling strict JSON mode because tools are present. Relying on system prompt.');
158
+ delete requestOptions.config.responseMimeType;
159
+ delete requestOptions.config.responseSchema;
160
+ }
143
161
  }
144
162
 
145
163
  console.log('[GeminiProvider] generateContent request:', JSON.stringify(requestOptions, null, 2));