Next.js Discord

Discord Forum

Element type is invalid. Received a promise that resolves to: [object Promise]. Lazy element error

Unanswered
Sirex woodwasp posted this in #help-forum
Open in Discord
Sirex woodwaspOP
I am getting the above error when I am trying to make a call to my route handler

import { NextResponse } from "next/server"; import { TextServiceClient } from "@google-ai/generativelanguage"; import { GoogleAuth } from "google-auth-library"; const MODEL_NAME = "models/text-bison-001"; const API_KEY = process.env.NEXT_PUBLIC_GOOGLE_API_KEY; const client = new TextServiceClient({ authClient: new GoogleAuth().fromAPIKey(API_KEY), }); export async function POST(req, res) { const { snacks, answer } = req.body const prompt = "Based on the user answer that they prefer" + answer +"choose 1 snack from the following list of snacks:" + snacks; const question = await client.generateText({ model: MODEL_NAME, prompt: { text: prompt, }, }) const data = await question.json() return new NextResponse.json({ output: data[0].candidates[0].output }); }

0 Replies