n8n-nodes-openai-compatible-chat-trigger 1.0.3 → 1.0.5
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.
|
@@ -146,6 +146,7 @@ class OpenAiCompatibleTrigger {
|
|
|
146
146
|
};
|
|
147
147
|
return {
|
|
148
148
|
webhookResponse: {
|
|
149
|
+
statusCode: 200,
|
|
149
150
|
body: responseData,
|
|
150
151
|
},
|
|
151
152
|
};
|
|
@@ -157,6 +158,7 @@ class OpenAiCompatibleTrigger {
|
|
|
157
158
|
let messageContent = '';
|
|
158
159
|
let messagesArray = [];
|
|
159
160
|
let modelName = '';
|
|
161
|
+
const binaryData = {};
|
|
160
162
|
if (webhookName === 'completions') {
|
|
161
163
|
messageContent = (body.prompt || '');
|
|
162
164
|
modelName = (body.model || '');
|
|
@@ -166,21 +168,61 @@ class OpenAiCompatibleTrigger {
|
|
|
166
168
|
messagesArray = (body.messages || []);
|
|
167
169
|
if (messagesArray.length > 0) {
|
|
168
170
|
const lastMsg = messagesArray[messagesArray.length - 1];
|
|
169
|
-
|
|
171
|
+
if (typeof lastMsg.content === 'string') {
|
|
172
|
+
messageContent = lastMsg.content;
|
|
173
|
+
}
|
|
174
|
+
else if (Array.isArray(lastMsg.content)) {
|
|
175
|
+
// Handle multimodal prompt content (e.g. containing text parts and image data URLs)
|
|
176
|
+
for (const part of lastMsg.content) {
|
|
177
|
+
if (part.type === 'text') {
|
|
178
|
+
messageContent += part.text || '';
|
|
179
|
+
}
|
|
180
|
+
else if (part.type === 'image_url') {
|
|
181
|
+
const url = part.image_url?.url || '';
|
|
182
|
+
if (url.startsWith('data:')) {
|
|
183
|
+
try {
|
|
184
|
+
const matches = url.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
|
|
185
|
+
if (matches && matches.length === 3) {
|
|
186
|
+
const mimeType = matches[1];
|
|
187
|
+
const base64Data = matches[2];
|
|
188
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
189
|
+
const extension = mimeType.split('/')[1] || 'png';
|
|
190
|
+
const fileCount = Object.keys(binaryData).length;
|
|
191
|
+
const propertyName = `data_${fileCount}`;
|
|
192
|
+
const fileName = `chat_image_${Date.now()}_${fileCount}.${extension}`;
|
|
193
|
+
binaryData[propertyName] = await this.helpers.prepareBinaryData(buffer, fileName, mimeType);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
// ignore invalid file formats
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
170
203
|
}
|
|
171
204
|
modelName = (body.model || '');
|
|
172
205
|
}
|
|
206
|
+
const responseItem = {
|
|
207
|
+
chatInput: messageContent,
|
|
208
|
+
sessionId: (body.user || body.sessionId || body.conversationId || 'default-session'),
|
|
209
|
+
message: messageContent,
|
|
210
|
+
messages: messagesArray.length > 0 ? messagesArray : undefined,
|
|
211
|
+
model: modelName || undefined,
|
|
212
|
+
body: body,
|
|
213
|
+
headers: headers,
|
|
214
|
+
query: query,
|
|
215
|
+
webhookType: webhookName,
|
|
216
|
+
};
|
|
217
|
+
const executionData = {
|
|
218
|
+
json: responseItem,
|
|
219
|
+
};
|
|
220
|
+
if (Object.keys(binaryData).length > 0) {
|
|
221
|
+
executionData.binary = binaryData;
|
|
222
|
+
}
|
|
173
223
|
return {
|
|
174
224
|
workflowData: [
|
|
175
|
-
|
|
176
|
-
message: messageContent,
|
|
177
|
-
messages: messagesArray.length > 0 ? messagesArray : undefined,
|
|
178
|
-
model: modelName || undefined,
|
|
179
|
-
body: body,
|
|
180
|
-
headers: headers,
|
|
181
|
-
query: query,
|
|
182
|
-
webhookType: webhookName,
|
|
183
|
-
}),
|
|
225
|
+
[executionData]
|
|
184
226
|
],
|
|
185
227
|
};
|
|
186
228
|
}
|
|
@@ -154,6 +154,7 @@ export class OpenAiCompatibleTrigger implements INodeType {
|
|
|
154
154
|
};
|
|
155
155
|
return {
|
|
156
156
|
webhookResponse: {
|
|
157
|
+
statusCode: 200,
|
|
157
158
|
body: responseData,
|
|
158
159
|
},
|
|
159
160
|
};
|
|
@@ -167,6 +168,7 @@ export class OpenAiCompatibleTrigger implements INodeType {
|
|
|
167
168
|
let messageContent = '';
|
|
168
169
|
let messagesArray: any[] = [];
|
|
169
170
|
let modelName = '';
|
|
171
|
+
const binaryData: any = {};
|
|
170
172
|
|
|
171
173
|
if (webhookName === 'completions') {
|
|
172
174
|
messageContent = (body.prompt || '') as string;
|
|
@@ -176,22 +178,65 @@ export class OpenAiCompatibleTrigger implements INodeType {
|
|
|
176
178
|
messagesArray = (body.messages || []) as any[];
|
|
177
179
|
if (messagesArray.length > 0) {
|
|
178
180
|
const lastMsg = messagesArray[messagesArray.length - 1];
|
|
179
|
-
|
|
181
|
+
|
|
182
|
+
if (typeof lastMsg.content === 'string') {
|
|
183
|
+
messageContent = lastMsg.content;
|
|
184
|
+
} else if (Array.isArray(lastMsg.content)) {
|
|
185
|
+
// Handle multimodal prompt content (e.g. containing text parts and image data URLs)
|
|
186
|
+
for (const part of lastMsg.content) {
|
|
187
|
+
if (part.type === 'text') {
|
|
188
|
+
messageContent += part.text || '';
|
|
189
|
+
} else if (part.type === 'image_url') {
|
|
190
|
+
const url = part.image_url?.url || '';
|
|
191
|
+
if (url.startsWith('data:')) {
|
|
192
|
+
try {
|
|
193
|
+
const matches = url.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
|
|
194
|
+
if (matches && matches.length === 3) {
|
|
195
|
+
const mimeType = matches[1];
|
|
196
|
+
const base64Data = matches[2];
|
|
197
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
198
|
+
|
|
199
|
+
const extension = mimeType.split('/')[1] || 'png';
|
|
200
|
+
const fileCount = Object.keys(binaryData).length;
|
|
201
|
+
const propertyName = `data_${fileCount}`;
|
|
202
|
+
const fileName = `chat_image_${Date.now()}_${fileCount}.${extension}`;
|
|
203
|
+
|
|
204
|
+
binaryData[propertyName] = await this.helpers.prepareBinaryData(buffer, fileName, mimeType);
|
|
205
|
+
}
|
|
206
|
+
} catch (e) {
|
|
207
|
+
// ignore invalid file formats
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
180
213
|
}
|
|
181
214
|
modelName = (body.model || '') as string;
|
|
182
215
|
}
|
|
183
216
|
|
|
217
|
+
const responseItem: any = {
|
|
218
|
+
chatInput: messageContent,
|
|
219
|
+
sessionId: (body.user || body.sessionId || body.conversationId || 'default-session') as string,
|
|
220
|
+
message: messageContent,
|
|
221
|
+
messages: messagesArray.length > 0 ? messagesArray : undefined,
|
|
222
|
+
model: modelName || undefined,
|
|
223
|
+
body: body,
|
|
224
|
+
headers: headers,
|
|
225
|
+
query: query,
|
|
226
|
+
webhookType: webhookName,
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const executionData: any = {
|
|
230
|
+
json: responseItem,
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
if (Object.keys(binaryData).length > 0) {
|
|
234
|
+
executionData.binary = binaryData;
|
|
235
|
+
}
|
|
236
|
+
|
|
184
237
|
return {
|
|
185
238
|
workflowData: [
|
|
186
|
-
|
|
187
|
-
message: messageContent,
|
|
188
|
-
messages: messagesArray.length > 0 ? messagesArray : undefined,
|
|
189
|
-
model: modelName || undefined,
|
|
190
|
-
body: body,
|
|
191
|
-
headers: headers,
|
|
192
|
-
query: query,
|
|
193
|
-
webhookType: webhookName,
|
|
194
|
-
}),
|
|
239
|
+
[executionData]
|
|
195
240
|
],
|
|
196
241
|
};
|
|
197
242
|
|