Skip to content

Commit 416139e

Browse files
Testing for chapgpt integrations
1 parent 10efc42 commit 416139e

File tree

1 file changed

+36
-18
lines changed
  • src/app/(protected)/api/webhook/instagram

1 file changed

+36
-18
lines changed

src/app/(protected)/api/webhook/instagram/route.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,24 @@ export async function POST(req: NextRequest) {
8282
) {
8383
console.log("Smart AI", automation);
8484

85-
const smart_ai_message = await openai.chat.completions.create({
86-
model: "gpt-4o-mini",
87-
messages: [
88-
{
89-
role: "assistant",
90-
content: `${automation.listener?.prompt}: Keep responses under 2 sentences`,
91-
},
92-
],
93-
});
85+
let smart_ai_message;
86+
try {
87+
smart_ai_message = await openai.chat.completions.create({
88+
model: "gpt-3.5-turbo",
89+
messages: [
90+
{
91+
role: "assistant",
92+
content: `${automation.listener?.prompt}: Keep responses under 2 sentences`,
93+
},
94+
],
95+
});
96+
} catch (error) {
97+
console.error("OpenAI API error:", error);
98+
return NextResponse.json(
99+
{ message: "Error generating AI response" },
100+
{ status: 500 }
101+
);
102+
}
94103
console.log("answers?", smart_ai_message);
95104

96105
if (smart_ai_message.choices[0].message.content) {
@@ -204,15 +213,24 @@ export async function POST(req: NextRequest) {
204213
automation.listener.listener === "SMARTAI" &&
205214
automation.User?.subscription?.plan === "PRO"
206215
) {
207-
const smart_ai_message = await openai.chat.completions.create({
208-
model: "gpt-4o-mini",
209-
messages: [
210-
{
211-
role: "assistant",
212-
content: `${automation.listener?.prompt}: keep responses under 2 sentences`,
213-
},
214-
],
215-
});
216+
let smart_ai_message;
217+
try {
218+
smart_ai_message = await openai.chat.completions.create({
219+
model: "gpt-3.5-turbo",
220+
messages: [
221+
{
222+
role: "assistant",
223+
content: `${automation.listener?.prompt}: keep responses under 2 sentences`,
224+
},
225+
],
226+
});
227+
} catch (error) {
228+
console.error("OpenAI API error:", error);
229+
return NextResponse.json(
230+
{ message: "Error generating AI response" },
231+
{ status: 500 }
232+
);
233+
}
216234
console.log("answers?", smart_ai_message);
217235

218236
if (smart_ai_message.choices[0].message.content) {

0 commit comments

Comments
 (0)