n8n-nodes-rooyai 1.0.1 → 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.
package/dist/RooyaiAgent.node.js
CHANGED
|
@@ -10,10 +10,10 @@ class RooyaiAgent {
|
|
|
10
10
|
this.description = {
|
|
11
11
|
displayName: 'Rooyai AI Agent',
|
|
12
12
|
name: 'rooyaiAgent',
|
|
13
|
-
icon: '
|
|
13
|
+
icon: 'file:rooyai.svg',
|
|
14
14
|
group: ['transform'],
|
|
15
15
|
version: 1,
|
|
16
|
-
description: 'Chat with AI models via OpenRouter',
|
|
16
|
+
description: 'Chat with AI models via OpenRouter or OpenAI',
|
|
17
17
|
defaults: { name: 'Rooyai AI Agent' },
|
|
18
18
|
inputs: ['main'],
|
|
19
19
|
outputs: ['main'],
|
|
@@ -23,14 +23,10 @@ class RooyaiAgent {
|
|
|
23
23
|
displayName: 'Model',
|
|
24
24
|
name: 'model',
|
|
25
25
|
type: 'options',
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{ name: 'Gemini Pro 1.5', value: 'google/gemini-pro-1.5' },
|
|
31
|
-
{ name: 'Llama 3.1 70B', value: 'meta-llama/llama-3.1-70b-instruct' },
|
|
32
|
-
],
|
|
33
|
-
default: 'openai/gpt-4o-mini',
|
|
26
|
+
typeOptions: {
|
|
27
|
+
loadOptionsMethod: 'getModels',
|
|
28
|
+
},
|
|
29
|
+
default: '',
|
|
34
30
|
description: 'Select AI model',
|
|
35
31
|
},
|
|
36
32
|
{
|
|
@@ -103,49 +99,79 @@ class RooyaiAgent {
|
|
|
103
99
|
},
|
|
104
100
|
],
|
|
105
101
|
};
|
|
102
|
+
this.methods = {
|
|
103
|
+
loadOptions: {
|
|
104
|
+
async getModels() {
|
|
105
|
+
const credentials = await this.getCredentials('rooyaiOpenRouter');
|
|
106
|
+
const providerType = credentials.providerType;
|
|
107
|
+
if (providerType === 'openrouter') {
|
|
108
|
+
return [
|
|
109
|
+
{ name: 'GPT-4o', value: 'openai/gpt-4o' },
|
|
110
|
+
{ name: 'GPT-4o Mini', value: 'openai/gpt-4o-mini' },
|
|
111
|
+
{ name: 'Claude 3.5 Sonnet', value: 'anthropic/claude-3.5-sonnet' },
|
|
112
|
+
{ name: 'Claude 3 Opus', value: 'anthropic/claude-3-opus' },
|
|
113
|
+
{ name: 'Gemini Pro 1.5', value: 'google/gemini-pro-1.5' },
|
|
114
|
+
{ name: 'Llama 3.1 70B', value: 'meta-llama/llama-3.1-70b-instruct' },
|
|
115
|
+
{ name: 'Mistral Large', value: 'mistralai/mistral-large' },
|
|
116
|
+
{ name: 'DeepSeek V3', value: 'deepseek/deepseek-chat' },
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return [
|
|
121
|
+
{ name: 'GPT-4o', value: 'gpt-4o' },
|
|
122
|
+
{ name: 'GPT-4o Mini', value: 'gpt-4o-mini' },
|
|
123
|
+
{ name: 'GPT-4 Turbo', value: 'gpt-4-turbo' },
|
|
124
|
+
{ name: 'GPT-3.5 Turbo', value: 'gpt-3.5-turbo' },
|
|
125
|
+
{ name: 'GPT-4', value: 'gpt-4' },
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
};
|
|
106
131
|
}
|
|
107
132
|
async execute() {
|
|
108
|
-
var _a, _b, _c, _d
|
|
133
|
+
var _a, _b, _c, _d;
|
|
109
134
|
const items = this.getInputData();
|
|
110
135
|
const returnData = [];
|
|
111
136
|
const credentials = await this.getCredentials('rooyaiOpenRouter');
|
|
137
|
+
const providerType = credentials.providerType;
|
|
112
138
|
for (let i = 0; i < items.length; i++) {
|
|
113
139
|
try {
|
|
114
140
|
const model = this.getNodeParameter('model', i);
|
|
115
141
|
const messagesInput = this.getNodeParameter('messages', i, {});
|
|
116
142
|
const options = this.getNodeParameter('options', i, {});
|
|
117
143
|
const simplifyOutput = this.getNodeParameter('simplifyOutput', i);
|
|
118
|
-
// Build messages array
|
|
119
144
|
const messages = [];
|
|
120
145
|
if (messagesInput.messageValues && Array.isArray(messagesInput.messageValues)) {
|
|
121
146
|
for (const msg of messagesInput.messageValues) {
|
|
122
|
-
messages.push({
|
|
123
|
-
role: msg.role,
|
|
124
|
-
content: msg.text
|
|
125
|
-
});
|
|
147
|
+
messages.push({ role: msg.role, content: msg.text });
|
|
126
148
|
}
|
|
127
149
|
}
|
|
128
|
-
|
|
129
|
-
|
|
150
|
+
let apiUrl = '';
|
|
151
|
+
let headers = {
|
|
152
|
+
'Authorization': `Bearer ${credentials.apiKey}`,
|
|
153
|
+
'Content-Type': 'application/json',
|
|
154
|
+
};
|
|
155
|
+
if (providerType === 'openrouter') {
|
|
156
|
+
apiUrl = 'https://openrouter.ai/api/v1/chat/completions';
|
|
157
|
+
headers['HTTP-Referer'] = 'https://rooyai.com';
|
|
158
|
+
headers['X-Title'] = 'Rooyai AI Agent';
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
apiUrl = 'https://api.openai.com/v1/chat/completions';
|
|
162
|
+
}
|
|
163
|
+
const response = await axios_1.default.post(apiUrl, {
|
|
130
164
|
model,
|
|
131
165
|
messages,
|
|
132
166
|
temperature: options.temperature || 0.7,
|
|
133
167
|
max_tokens: options.maxTokens || 2000,
|
|
134
|
-
}, {
|
|
135
|
-
headers: {
|
|
136
|
-
'Authorization': `Bearer ${credentials.apiKey}`,
|
|
137
|
-
'Content-Type': 'application/json',
|
|
138
|
-
'HTTP-Referer': 'https://rooyai.com',
|
|
139
|
-
'X-Title': 'Rooyai AI Agent',
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
// Return response
|
|
168
|
+
}, { headers });
|
|
143
169
|
if (simplifyOutput) {
|
|
144
170
|
returnData.push({
|
|
145
171
|
json: {
|
|
146
172
|
message: response.data.choices[0].message.content,
|
|
147
173
|
model: response.data.model,
|
|
148
|
-
}
|
|
174
|
+
},
|
|
149
175
|
});
|
|
150
176
|
}
|
|
151
177
|
else {
|
|
@@ -153,32 +179,29 @@ class RooyaiAgent {
|
|
|
153
179
|
}
|
|
154
180
|
}
|
|
155
181
|
catch (error) {
|
|
156
|
-
// Enhanced error handling
|
|
157
182
|
const errorMsg = ((_c = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) || error.message;
|
|
158
183
|
const errorStatus = (_d = error.response) === null || _d === void 0 ? void 0 : _d.status;
|
|
159
|
-
const errorCode = (_g = (_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.code;
|
|
160
184
|
let hint = '';
|
|
161
185
|
if (errorStatus === 401) {
|
|
162
|
-
hint = 'Invalid API Key. Check your
|
|
186
|
+
hint = 'Invalid API Key. Check your credential.';
|
|
163
187
|
}
|
|
164
188
|
else if (errorStatus === 429) {
|
|
165
|
-
hint = 'Rate limit exceeded.
|
|
189
|
+
hint = 'Rate limit exceeded.';
|
|
166
190
|
}
|
|
167
191
|
else if (errorStatus === 402) {
|
|
168
|
-
hint = 'Insufficient credits.
|
|
192
|
+
hint = 'Insufficient credits.';
|
|
169
193
|
}
|
|
170
194
|
if (this.continueOnFail()) {
|
|
171
195
|
returnData.push({
|
|
172
196
|
json: {
|
|
173
197
|
error: errorMsg,
|
|
174
198
|
status: errorStatus,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
199
|
+
hint: hint || 'Unknown error',
|
|
200
|
+
},
|
|
178
201
|
});
|
|
179
202
|
}
|
|
180
203
|
else {
|
|
181
|
-
throw new Error(`
|
|
204
|
+
throw new Error(`API Error (${errorStatus}): ${errorMsg}. ${hint}`);
|
|
182
205
|
}
|
|
183
206
|
}
|
|
184
207
|
}
|
|
@@ -4,9 +4,26 @@ exports.RooyaiOpenRouter = void 0;
|
|
|
4
4
|
class RooyaiOpenRouter {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.name = 'rooyaiOpenRouter';
|
|
7
|
-
this.displayName = 'Rooyai OpenRouter
|
|
7
|
+
this.displayName = 'Rooyai OpenRouter account';
|
|
8
8
|
this.documentationUrl = 'https://openrouter.ai/docs';
|
|
9
9
|
this.properties = [
|
|
10
|
+
{
|
|
11
|
+
displayName: 'Provider Type',
|
|
12
|
+
name: 'providerType',
|
|
13
|
+
type: 'options',
|
|
14
|
+
options: [
|
|
15
|
+
{
|
|
16
|
+
name: 'OpenRouter',
|
|
17
|
+
value: 'openrouter',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'OpenAI',
|
|
21
|
+
value: 'openai',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
default: 'openrouter',
|
|
25
|
+
description: 'Select AI provider',
|
|
26
|
+
},
|
|
10
27
|
{
|
|
11
28
|
displayName: 'API Key',
|
|
12
29
|
name: 'apiKey',
|
|
@@ -14,6 +31,7 @@ class RooyaiOpenRouter {
|
|
|
14
31
|
typeOptions: { password: true },
|
|
15
32
|
default: '',
|
|
16
33
|
required: true,
|
|
34
|
+
description: 'Your API Key',
|
|
17
35
|
},
|
|
18
36
|
];
|
|
19
37
|
}
|