Я не уверен, как это исправить, так как все параметры выполняются, и импорт принимается во внимание, и были установлены приличия, может кто -нибудь предоставить некоторое понимание и или решение. для контекста. Я строю проект из A, который был загружен в начале 2024 года, и это март 2025 года, если это может помочь. Вот картинки. < /p>
ошибка < /p>
./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);
< /code>
Я использую Hummanmessage из Langchain для генератора викторины ИИ и не могу правильно запустить свою сборку из -за этой ошибки. Сделать так, чтобы я не могу развернуть на Vercel. < /p>
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 });
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -humanmess
Тип «HumanMessage» не присваивается типу «assemessagelike». Тип «HumanMessage» не присваивается для типа «BaseMessage» ⇐ Javascript
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Type 'String' не присваивается параметру типа 'keyof staticContentData
Anonymous » » в форуме Javascript - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-