Я не уверен, как это исправить, так как все параметры выполняются, и импорт принимается во внимание, и были установлены приличия, может кто -нибудь предоставить некоторое понимание и или решение. для контекста. Я строю проект из 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/@langchain+core@0.3.42_openai@4.87.0_zod@3.24.2_/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/@langchain+core@0.1.63_openai@4.87.0_zod@3.24.2_/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
Форум по Javascript
1741824296
Anonymous
Я не уверен, как это исправить, так как все параметры выполняются, и импорт принимается во внимание, и были установлены приличия, может кто -нибудь предоставить некоторое понимание и или решение. для контекста. Я строю проект из 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/@langchain+core@0.3.42_openai@4.87.0_zod@3.24.2_/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/@langchain+core@0.1.63_openai@4.87.0_zod@3.24.2_/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 });
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79505120/type-humanmessage-is-not-assignable-to-type-basemessagelike-type-humanmess[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия