@contentgrowth/llm-service 0.4.0 → 0.5.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 +1 -1
- package/src/llm-service.js +17 -7
package/package.json
CHANGED
package/src/llm-service.js
CHANGED
|
@@ -162,20 +162,27 @@ export class LLMService {
|
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
164
|
* Wrap of chatCompletion to handle toolcalls from LLM.
|
|
165
|
+
* @param {Array} messages - Conversation messages
|
|
166
|
+
* @param {string} tenantId - Tenant identifier
|
|
167
|
+
* @param {string} systemPrompt - System instructions
|
|
168
|
+
* @param {Array} tools - Tools array
|
|
169
|
+
* @param {Object} options - Options object (for responseFormat, etc.)
|
|
170
|
+
* @returns {Object} Response with content, tool_calls, and optionally parsedContent
|
|
165
171
|
*/
|
|
166
|
-
async chatWithTools(messages, tenantId, systemPrompt, tools = []) {
|
|
172
|
+
async chatWithTools(messages, tenantId, systemPrompt, tools = [], options = {}) {
|
|
167
173
|
const provider = await this._getProvider(tenantId);
|
|
168
174
|
|
|
169
175
|
let currentMessages = [...messages];
|
|
170
176
|
|
|
171
|
-
// Initial call
|
|
177
|
+
// Initial call - pass options to enable JSON mode, etc.
|
|
172
178
|
const initialResponse = await provider.chatCompletion(
|
|
173
179
|
currentMessages,
|
|
174
180
|
systemPrompt,
|
|
175
|
-
tools
|
|
181
|
+
tools,
|
|
182
|
+
options
|
|
176
183
|
);
|
|
177
184
|
|
|
178
|
-
let { content, tool_calls } = initialResponse;
|
|
185
|
+
let { content, tool_calls, parsedContent } = initialResponse;
|
|
179
186
|
|
|
180
187
|
// Tool execution loop
|
|
181
188
|
while (tool_calls) {
|
|
@@ -185,18 +192,21 @@ export class LLMService {
|
|
|
185
192
|
// Execute tools using the provider's helper (which formats results for that provider)
|
|
186
193
|
await provider.executeTools(tool_calls, currentMessages, tenantId, this.toolImplementations, this.env);
|
|
187
194
|
|
|
188
|
-
// Next call
|
|
195
|
+
// Next call - also pass options
|
|
189
196
|
const nextResponse = await provider.chatCompletion(
|
|
190
197
|
currentMessages,
|
|
191
198
|
systemPrompt,
|
|
192
|
-
tools
|
|
199
|
+
tools,
|
|
200
|
+
options
|
|
193
201
|
);
|
|
194
202
|
|
|
195
203
|
content = nextResponse.content;
|
|
196
204
|
tool_calls = nextResponse.tool_calls;
|
|
205
|
+
parsedContent = nextResponse.parsedContent; // Preserve parsedContent from final response
|
|
197
206
|
}
|
|
198
207
|
|
|
199
|
-
|
|
208
|
+
// Return both content and parsedContent (if available)
|
|
209
|
+
return { content, parsedContent, toolCalls: tool_calls };
|
|
200
210
|
}
|
|
201
211
|
|
|
202
212
|
/**
|