@5minds/node-red-dashboard-2-processcube-chat 0.1.1-add-functionality-dd2f3b-mdej6h1e → 0.1.1-add-functionality-043ee8-mdy8o5ki
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.
|
@@ -187,55 +187,108 @@ export default {
|
|
|
187
187
|
},
|
|
188
188
|
|
|
189
189
|
formatForChatGPT(conversation, textOnly = false) {
|
|
190
|
-
|
|
191
|
-
messages: conversation.map((msg) =>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
role: msg.role === 'ai' ? 'assistant' : 'user',
|
|
195
|
-
content: msg.text,
|
|
196
|
-
};
|
|
197
|
-
} else if (msg.files && msg.files.length > 0) {
|
|
198
|
-
const content = [{ type: 'text', text: msg.text || '' }];
|
|
199
|
-
|
|
200
|
-
msg.files.forEach((file) => {
|
|
201
|
-
if (file.type && file.type.startsWith('image/') && file.src) {
|
|
202
|
-
content.push({
|
|
203
|
-
type: 'image_url',
|
|
204
|
-
image_url: { url: file.src },
|
|
205
|
-
});
|
|
206
|
-
} else if (!textOnly && file.type && file.type.startsWith('audio/') && file.base64Data) {
|
|
207
|
-
const format = this.getAudioFormat(file.type);
|
|
208
|
-
content.push({
|
|
209
|
-
type: 'input_audio',
|
|
210
|
-
input_audio: {
|
|
211
|
-
data: file.base64Data,
|
|
212
|
-
format: format,
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
} else if (!textOnly && file.fileData) {
|
|
216
|
-
content.push({
|
|
217
|
-
type: 'file',
|
|
218
|
-
file: {
|
|
219
|
-
filename: file.name,
|
|
220
|
-
file_data: file.fileData,
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
});
|
|
190
|
+
const payload = {
|
|
191
|
+
messages: conversation.map((msg) => this.formatMessage(msg, textOnly)),
|
|
192
|
+
model: this.props.model,
|
|
193
|
+
};
|
|
225
194
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
195
|
+
// Add ChatGPT API extensions
|
|
196
|
+
if (this.props.tools) {
|
|
197
|
+
payload.tools = this.props.tools;
|
|
198
|
+
}
|
|
231
199
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
200
|
+
if (this.props.tool_choice) {
|
|
201
|
+
payload.tool_choice = this.props.tool_choice;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (this.props.temperature !== undefined) {
|
|
205
|
+
payload.temperature = this.props.temperature;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (this.props.max_tokens) {
|
|
209
|
+
payload.max_tokens = this.props.max_tokens;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (this.props.top_p !== undefined) {
|
|
213
|
+
payload.top_p = this.props.top_p;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (this.props.frequency_penalty !== undefined) {
|
|
217
|
+
payload.frequency_penalty = this.props.frequency_penalty;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (this.props.presence_penalty !== undefined) {
|
|
221
|
+
payload.presence_penalty = this.props.presence_penalty;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (this.props.response_format) {
|
|
225
|
+
payload.response_format = this.props.response_format;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return payload;
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
formatMessage(msg, textOnly = false) {
|
|
232
|
+
const message = {
|
|
233
|
+
role: msg.role === 'ai' ? 'assistant' : 'user',
|
|
238
234
|
};
|
|
235
|
+
|
|
236
|
+
// Handle tool calls (for assistant messages)
|
|
237
|
+
if (msg.tool_calls) {
|
|
238
|
+
message.tool_calls = msg.tool_calls;
|
|
239
|
+
message.content = msg.content || null;
|
|
240
|
+
return message;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Handle tool responses (for tool messages)
|
|
244
|
+
if (msg.role === 'tool') {
|
|
245
|
+
message.role = 'tool';
|
|
246
|
+
message.content = msg.content;
|
|
247
|
+
message.tool_call_id = msg.tool_call_id;
|
|
248
|
+
return message;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Handle messages with files
|
|
252
|
+
if (msg.files && msg.files.length > 0) {
|
|
253
|
+
message.content = this.buildContentArray(msg, textOnly);
|
|
254
|
+
return message;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Handle text-only messages
|
|
258
|
+
message.content = msg.text || msg.content || '';
|
|
259
|
+
return message;
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
buildContentArray(msg, textOnly) {
|
|
263
|
+
const content = [{ type: 'text', text: msg.text || '' }];
|
|
264
|
+
|
|
265
|
+
msg.files.forEach((file) => {
|
|
266
|
+
if (file.type && file.type.startsWith('image/') && file.src) {
|
|
267
|
+
content.push({
|
|
268
|
+
type: 'image_url',
|
|
269
|
+
image_url: { url: file.src },
|
|
270
|
+
});
|
|
271
|
+
} else if (!textOnly && file.type && file.type.startsWith('audio/') && file.base64Data) {
|
|
272
|
+
const format = this.getAudioFormat(file.type);
|
|
273
|
+
content.push({
|
|
274
|
+
type: 'input_audio',
|
|
275
|
+
input_audio: {
|
|
276
|
+
data: file.base64Data,
|
|
277
|
+
format: format,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
} else if (!textOnly && file.fileData) {
|
|
281
|
+
content.push({
|
|
282
|
+
type: 'file',
|
|
283
|
+
file: {
|
|
284
|
+
filename: file.name,
|
|
285
|
+
file_data: file.fileData,
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
return content;
|
|
239
292
|
},
|
|
240
293
|
|
|
241
294
|
getAudioFormat(mimeType) {
|
|
@@ -256,16 +309,36 @@ export default {
|
|
|
256
309
|
|
|
257
310
|
handleNodeREDResponse(msg, signals) {
|
|
258
311
|
try {
|
|
312
|
+
// Store the complete ChatGPT response in conversation
|
|
313
|
+
const fullResponse = msg.payload;
|
|
314
|
+
|
|
315
|
+
// Create AI message with complete response data
|
|
259
316
|
const aiMessage = {
|
|
260
|
-
text: msg.payload.text || msg.payload.content,
|
|
261
317
|
role: 'ai',
|
|
318
|
+
content: fullResponse.message?.content || fullResponse.content,
|
|
319
|
+
text: fullResponse.message?.content || fullResponse.content,
|
|
320
|
+
fullResponse: fullResponse,
|
|
262
321
|
};
|
|
263
322
|
|
|
323
|
+
// Handle tool calls if present
|
|
324
|
+
if (fullResponse.message?.tool_calls) {
|
|
325
|
+
aiMessage.tool_calls = fullResponse.message.tool_calls;
|
|
326
|
+
aiMessage.content = fullResponse.message.content || null;
|
|
327
|
+
}
|
|
328
|
+
|
|
264
329
|
this.conversation.push(aiMessage);
|
|
265
330
|
|
|
266
|
-
|
|
331
|
+
// For the chat display, show appropriate response
|
|
332
|
+
if (fullResponse.message?.tool_calls) {
|
|
333
|
+
// If ChatGPT wants to call tools, show a message
|
|
334
|
+
signals.onResponse({
|
|
335
|
+
text: 'Function call requested...',
|
|
336
|
+
role: 'ai',
|
|
337
|
+
});
|
|
338
|
+
} else if (fullResponse.message?.content || fullResponse.content) {
|
|
339
|
+
// Normal text response
|
|
267
340
|
signals.onResponse({
|
|
268
|
-
text:
|
|
341
|
+
text: fullResponse.message?.content || fullResponse.content,
|
|
269
342
|
role: 'ai',
|
|
270
343
|
});
|
|
271
344
|
}
|