admin管理员组文章数量:1389768
I am not sure how to fix this, as all parameters are being met and and imports are taken into account and decencies have been installed can someone please provide some insight and or a solution. for context. I am building a project from a that was uploaded in early 2024 and it is march 2025 if that may help. here are pictures.
Error
./src/app/api/quizz/generate/route.ts:94:48
Type error: Type 'HumanMessage' is not assignable to type 'BaseMessageLike'.
Type 'HumanMessage' is not assignable to type 'BaseMessage'.
The types returned by '_getType()' are incompatible between these types.
Type 'import("/Users/connormullins/Documents/Quiz iteration saves/quizz-ai-tutorial latest/node_modules/.pnpm/@[email protected][email protected][email protected]_/node_modules/@langchain/core/dist/messages/base").MessageType' is not assignable to type 'import("/Users/connormullins/Documents/Quiz iteration saves/quizz-ai-tutorial latest/node_modules/.pnpm/@[email protected][email protected][email protected]_/node_modules/@langchain/core/dist/messages/base").MessageType'.
Type '"developer"' is not assignable to type 'MessageType'.
92 | });
93 |
> 94 | const result: any = await runnable.invoke([message]);
| ^
95 | console.log(result);
96 |
97 | const { quizzId } = await saveQuizz(result.quizz);
I am running HummanMessage from Langchain for a AI quiz Generator and cannot run my build properly due to this error. making it so I cannot deploy onto vercel.
import { NextRequest, NextResponse } from "next/server";
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage } from "@langchain/core/messages";
import { PDFLoader } from "langchain/document_loaders/fs/pdf";
import { JsonOutputFunctionsParser } from "langchain/output_parsers";
import saveQuizz from "./saveToDb";
export async function POST(req: NextRequest) {
const body = await req.formData();
const document = body.get("pdf");
try {
const pdfLoader = new PDFLoader(document as Blob, {
parsedItemSeparator: " ",
});
const docs = await pdfLoader.load();
const selectedDocuments = docs.filter(
(doc) => doc.pageContent !== undefined
);
const texts = selectedDocuments.map((doc) => doc.pageContent);
const prompt =
"given the text which is a summary of the document, generate a quiz based on the text. Return json only that contains a quizz object with fields: name, description and questions. The questions is an array of objects with fields: questionText, answers. The answers is an array of objects with fields: answerText, isCorrect.";
if (!process.env.OPENAI_API_KEY) {
return NextResponse.json(
{ error: "OpenAI API key not provided" },
{ status: 500 }
);
}
const model = new ChatOpenAI({
openAIApiKey: process.env.OPENAI_API_KEY,
modelName: "gpt-4-1106-preview",
});
const parser = new JsonOutputFunctionsParser();
const extractionFunctionSchema = {
name: "extractor",
description: "Extracts fields from the output",
parameters: {
type: "object",
properties: {
quizz: {
type: "object",
properties: {
name: { type: "string" },
description: { type: "string" },
questions: {
type: "array",
items: {
type: "object",
properties: {
questionText: { type: "string" },
answers: {
type: "array",
items: {
type: "object",
properties: {
answerText: { type: "string" },
isCorrect: { type: "boolean" },
},
},
},
},
},
},
},
},
},
},
};
const runnable = model
.bind({
functions: [extractionFunctionSchema],
function_call: { name: "extractor" },
})
.pipe(parser);
const message = new HumanMessage({
content: [
{
type: "text",
text: prompt + "\n" + texts.join("\n"),
},
],
});
const result: any = await runnable.invoke([message]);
console.log(result);
const { quizzId } = await saveQuizz(result.quizz);
return NextResponse.json({ quizzId }, { status: 200 });
} catch (e: any) {
return NextResponse.json({ error: e.message }, { status: 500 });
}
}
本文标签:
版权声明:本文标题:javascript - Type 'HumanMessage' is not assignable to type 'BaseMessageLike'. Type 'Huma 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744725170a2621919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论