n8n-nodes-openai-compatible-chat-trigger 1.0.2 → 1.0.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.
|
@@ -19,16 +19,22 @@ class OpenAiCompatibleTrigger {
|
|
|
19
19
|
outputs: ['main'],
|
|
20
20
|
webhooks: [
|
|
21
21
|
{
|
|
22
|
-
name: '
|
|
22
|
+
name: 'chatCompletions',
|
|
23
23
|
httpMethod: 'POST',
|
|
24
24
|
responseMode: '={{$parameter["responseMode"]}}',
|
|
25
|
-
path: '={{$parameter["path"]}}
|
|
25
|
+
path: '={{$parameter["path"]}}/v1/chat/completions',
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
name: '
|
|
28
|
+
name: 'completions',
|
|
29
|
+
httpMethod: 'POST',
|
|
30
|
+
responseMode: '={{$parameter["responseMode"]}}',
|
|
31
|
+
path: '={{$parameter["path"]}}/v1/completions',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'models',
|
|
29
35
|
httpMethod: 'GET',
|
|
30
36
|
responseMode: 'onReceived',
|
|
31
|
-
path: '={{$parameter["path"]}}
|
|
37
|
+
path: '={{$parameter["path"]}}/v1/models',
|
|
32
38
|
},
|
|
33
39
|
],
|
|
34
40
|
properties: [
|
|
@@ -104,8 +110,7 @@ class OpenAiCompatibleTrigger {
|
|
|
104
110
|
};
|
|
105
111
|
async webhook() {
|
|
106
112
|
const req = this.getRequestObject();
|
|
107
|
-
const
|
|
108
|
-
const method = req.method || 'POST';
|
|
113
|
+
const webhookName = this.getWebhookName();
|
|
109
114
|
// 1. Verify Authorization Header if required
|
|
110
115
|
const authentication = this.getNodeParameter('authentication', 'none');
|
|
111
116
|
if (authentication === 'headerAuth') {
|
|
@@ -127,7 +132,7 @@ class OpenAiCompatibleTrigger {
|
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
// 2. Handle /v1/models endpoint (GET)
|
|
130
|
-
if (
|
|
135
|
+
if (webhookName === 'models') {
|
|
131
136
|
const mockModelsStr = this.getNodeParameter('mockModels', 'gpt-3.5-turbo, gpt-4o, n8n-bot');
|
|
132
137
|
const modelsList = mockModelsStr.split(',').map((m) => m.trim()).filter((m) => m !== '');
|
|
133
138
|
const responseData = {
|
|
@@ -152,12 +157,9 @@ class OpenAiCompatibleTrigger {
|
|
|
152
157
|
let messageContent = '';
|
|
153
158
|
let messagesArray = [];
|
|
154
159
|
let modelName = '';
|
|
155
|
-
|
|
156
|
-
const isCompletions = url.endsWith('/v1/completions') || url.endsWith('/completions');
|
|
157
|
-
if (isCompletions) {
|
|
160
|
+
if (webhookName === 'completions') {
|
|
158
161
|
messageContent = (body.prompt || '');
|
|
159
162
|
modelName = (body.model || '');
|
|
160
|
-
webhookType = 'completions';
|
|
161
163
|
}
|
|
162
164
|
else {
|
|
163
165
|
// default to chatCompletions
|
|
@@ -177,7 +179,7 @@ class OpenAiCompatibleTrigger {
|
|
|
177
179
|
body: body,
|
|
178
180
|
headers: headers,
|
|
179
181
|
query: query,
|
|
180
|
-
webhookType:
|
|
182
|
+
webhookType: webhookName,
|
|
181
183
|
}),
|
|
182
184
|
],
|
|
183
185
|
};
|
|
@@ -24,16 +24,22 @@ export class OpenAiCompatibleTrigger implements INodeType {
|
|
|
24
24
|
outputs: ['main'],
|
|
25
25
|
webhooks: [
|
|
26
26
|
{
|
|
27
|
-
name: '
|
|
27
|
+
name: 'chatCompletions' as any,
|
|
28
28
|
httpMethod: 'POST',
|
|
29
29
|
responseMode: '={{$parameter["responseMode"]}}',
|
|
30
|
-
path: '={{$parameter["path"]}}
|
|
30
|
+
path: '={{$parameter["path"]}}/v1/chat/completions',
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
name: '
|
|
33
|
+
name: 'completions' as any,
|
|
34
|
+
httpMethod: 'POST',
|
|
35
|
+
responseMode: '={{$parameter["responseMode"]}}',
|
|
36
|
+
path: '={{$parameter["path"]}}/v1/completions',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'models' as any,
|
|
34
40
|
httpMethod: 'GET',
|
|
35
41
|
responseMode: 'onReceived',
|
|
36
|
-
path: '={{$parameter["path"]}}
|
|
42
|
+
path: '={{$parameter["path"]}}/v1/models',
|
|
37
43
|
},
|
|
38
44
|
],
|
|
39
45
|
properties: [
|
|
@@ -110,8 +116,7 @@ export class OpenAiCompatibleTrigger implements INodeType {
|
|
|
110
116
|
|
|
111
117
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
|
112
118
|
const req = this.getRequestObject();
|
|
113
|
-
const
|
|
114
|
-
const method = req.method || 'POST';
|
|
119
|
+
const webhookName = this.getWebhookName();
|
|
115
120
|
|
|
116
121
|
// 1. Verify Authorization Header if required
|
|
117
122
|
const authentication = this.getNodeParameter('authentication', 'none') as string;
|
|
@@ -135,7 +140,7 @@ export class OpenAiCompatibleTrigger implements INodeType {
|
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
// 2. Handle /v1/models endpoint (GET)
|
|
138
|
-
if (
|
|
143
|
+
if (webhookName === 'models') {
|
|
139
144
|
const mockModelsStr = this.getNodeParameter('mockModels', 'gpt-3.5-turbo, gpt-4o, n8n-bot') as string;
|
|
140
145
|
const modelsList = mockModelsStr.split(',').map((m) => m.trim()).filter((m) => m !== '');
|
|
141
146
|
const responseData = {
|
|
@@ -162,14 +167,10 @@ export class OpenAiCompatibleTrigger implements INodeType {
|
|
|
162
167
|
let messageContent = '';
|
|
163
168
|
let messagesArray: any[] = [];
|
|
164
169
|
let modelName = '';
|
|
165
|
-
let webhookType = 'chatCompletions';
|
|
166
|
-
|
|
167
|
-
const isCompletions = url.endsWith('/v1/completions') || url.endsWith('/completions');
|
|
168
170
|
|
|
169
|
-
if (
|
|
171
|
+
if (webhookName === 'completions') {
|
|
170
172
|
messageContent = (body.prompt || '') as string;
|
|
171
173
|
modelName = (body.model || '') as string;
|
|
172
|
-
webhookType = 'completions';
|
|
173
174
|
} else {
|
|
174
175
|
// default to chatCompletions
|
|
175
176
|
messagesArray = (body.messages || []) as any[];
|
|
@@ -189,7 +190,7 @@ export class OpenAiCompatibleTrigger implements INodeType {
|
|
|
189
190
|
body: body,
|
|
190
191
|
headers: headers,
|
|
191
192
|
query: query,
|
|
192
|
-
webhookType:
|
|
193
|
+
webhookType: webhookName,
|
|
193
194
|
}),
|
|
194
195
|
],
|
|
195
196
|
};
|