@razzium/piece-aimw-api 0.0.14 → 0.0.16
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/index.ts +4 -3
- package/src/lib/actions/send-prompt.ts +22 -10
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -57,16 +57,17 @@ export const openaiAuth = PieceAuth.SecretText({
|
|
|
57
57
|
authentication: {
|
|
58
58
|
type: AuthenticationType.BEARER_TOKEN,
|
|
59
59
|
token: auth.auth as string,
|
|
60
|
-
//token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImZjY2Y4NzQyLTUyZWItNDdmZS05YWNjLTFjYzUyZjc2ZDdkYiJ9.NSWnWMO0ERGRU3QT4are2u-fo7R1FJxb2byyIwInTj4",
|
|
61
60
|
},
|
|
62
61
|
});
|
|
63
62
|
return {
|
|
64
63
|
valid: true,
|
|
65
64
|
};
|
|
66
|
-
} catch (e) {
|
|
65
|
+
} catch (e: any) {
|
|
66
|
+
console.error('Auth validation error:', e?.message || e);
|
|
67
|
+
const errorMessage = e?.message || e?.response?.data?.message || 'Invalid API key';
|
|
67
68
|
return {
|
|
68
69
|
valid: false,
|
|
69
|
-
error:
|
|
70
|
+
error: errorMessage,
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
},
|
|
@@ -219,16 +219,28 @@ export const askOpenAI = createAction({
|
|
|
219
219
|
// });
|
|
220
220
|
|
|
221
221
|
// Send prompt
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
222
|
+
let completion;
|
|
223
|
+
try {
|
|
224
|
+
completion = await openai.chat.completions.create({
|
|
225
|
+
model: model,
|
|
226
|
+
messages: [...messageHistory],
|
|
227
|
+
// messages: [...roles, ...messageHistory],
|
|
228
|
+
// temperature: temperature,
|
|
229
|
+
// top_p: topP,
|
|
230
|
+
// frequency_penalty: frequencyPenalty,
|
|
231
|
+
// presence_penalty: presencePenalty,
|
|
232
|
+
// max_completion_tokens: maxTokens,
|
|
233
|
+
});
|
|
234
|
+
} catch (error: any) {
|
|
235
|
+
const errorMessage = error?.message || error?.error?.message || JSON.stringify(error);
|
|
236
|
+
const errorStatus = error?.status || error?.response?.status || 'unknown';
|
|
237
|
+
throw new Error(`AIMW API Error (${errorStatus}): ${errorMessage}`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Validate API response
|
|
241
|
+
if (!completion?.choices?.[0]?.message) {
|
|
242
|
+
throw new Error('Invalid API response: no completion message returned');
|
|
243
|
+
}
|
|
232
244
|
|
|
233
245
|
// Add response to message history
|
|
234
246
|
messageHistory = [...messageHistory, completion.choices[0].message];
|