@contentgrowth/llm-service 0.6.2 → 0.6.3

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.2",
3
+ "version": "0.6.3",
4
4
  "description": "Unified LLM Service for Content Growth",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -130,13 +130,30 @@ export class GeminiProvider extends BaseLLMProvider {
130
130
  const response = result.response;
131
131
  const toolCalls = response.functionCalls();
132
132
 
133
+ let textContent = '';
134
+ try {
135
+ textContent = response.text();
136
+ } catch (e) {
137
+ // response.text() throws if there is no text content (e.g. only tool calls)
138
+ // This is expected behavior for tool-only responses
139
+ }
140
+ // Validate that we have EITHER content OR tool calls
141
+ if (!textContent && (!toolCalls || toolCalls.length === 0)) {
142
+ console.error('[GeminiProvider] Model returned empty response (no text, no tool calls)');
143
+ console.error('[GeminiProvider] Last message:', JSON.stringify(lastMessage, null, 2));
144
+ throw new LLMServiceException(
145
+ 'Model returned empty response. This usually means the prompt or schema is confusing the model.',
146
+ 500
147
+ );
148
+ }
149
+
133
150
  // Return with parsed JSON if applicable
134
151
  return {
135
- content: response.text(),
152
+ content: textContent,
136
153
  tool_calls: toolCalls ? toolCalls.map(fc => ({ type: 'function', function: fc })) : null,
137
154
  _responseFormat: options.responseFormat,
138
155
  ...(options.responseFormat && this._shouldAutoParse(options) ? {
139
- parsedContent: this._safeJsonParse(response.text())
156
+ parsedContent: this._safeJsonParse(textContent)
140
157
  } : {})
141
158
  };
142
159
  }
@@ -1,6 +1,7 @@
1
1
  import OpenAI from 'openai';
2
2
  import { BaseLLMProvider } from './base-provider.js';
3
3
  import { extractJsonFromResponse } from '../json-utils.js';
4
+ import { LLMServiceException } from '../../llm-service.js';
4
5
 
5
6
  export class OpenAIProvider extends BaseLLMProvider {
6
7
  constructor(config) {
@@ -58,6 +59,15 @@ export class OpenAIProvider extends BaseLLMProvider {
58
59
  const response = await this.client.chat.completions.create(requestPayload);
59
60
  const message = response.choices[0].message;
60
61
 
62
+ // Validate that we have EITHER content OR tool calls
63
+ if (!message.content && (!message.tool_calls || message.tool_calls.length === 0)) {
64
+ console.error('[OpenAIProvider] Model returned empty response (no text, no tool calls)');
65
+ throw new LLMServiceException(
66
+ 'Model returned empty response. This usually means the prompt or schema is confusing the model.',
67
+ 500
68
+ );
69
+ }
70
+
61
71
  // Return with parsed JSON if applicable
62
72
  return {
63
73
  content: message.content,