Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'FewShotChatMessagePromptTemplate<any, any>' is not assignable to type 'ChatPromptTemplate<InputValues, string> | BaseMessagePromptTemplateLike' #5331

Closed
5 tasks done
youngsupchoi opened this issue May 10, 2024 · 3 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@youngsupchoi
Copy link

youngsupchoi commented May 10, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

import { ChatOpenAI } from "@langchain/openai";
import {
  ChatPromptTemplate,
  FewShotChatMessagePromptTemplate,
} from "@langchain/core/prompts";

const chat = new ChatOpenAI({});

const examples = [
  { input: "2+2", output: "4" },
  { input: "2+3", output: "5" },
];

const examplePrompt = ChatPromptTemplate.fromMessages([
  ["human", "{input}"],
  ["ai", "{output}"],
]);

const fewShotPrompt = new FewShotChatMessagePromptTemplate({
  examplePrompt,
  examples,
  inputVariables: ["input"],
});

const finalPrompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a trustworthy AI assistant."],
  fewShotPrompt,
  ["human", "{input}"],
]);

const formattedPrompt = await finalPrompt.format({
  input: "What is 2+2?",
});
Type 'FewShotChatMessagePromptTemplate<any, any>' is not assignable to type 'ChatPromptTemplate<InputValues, string> | BaseMessagePromptTemplateLike'.
  Type 'FewShotChatMessagePromptTemplate<any, any>' is missing the following properties from type 'ChatPromptTemplate<InputValues, string>': promptMessages, _parseImagePromptsts(2322)

Error Message and Stack Trace (if applicable)

Type 'FewShotChatMessagePromptTemplate<any, any>' is not assignable to type 'ChatPromptTemplate<InputValues, string> | BaseMessagePromptTemplateLike'.
  Type 'FewShotChatMessagePromptTemplate<any, any>' is missing the following properties from type 'ChatPromptTemplate<InputValues, string>': promptMessages, _parseImagePromptsts(2322)

https://www.youtube.com/watch?v=5ozH2z_vtj4&list=PLbGui_ZYuhigsI3cWlv-Dl3_R7CDNQR0u&index=8

Description

I followed the instructions in the YouTube video exactly, but I am experiencing a bug like the one mentioned above. I have been trying to resolve this bug for 10 hours but haven't been able to fix it yet, so I need your help.

Additionally, I am curious about something mentioned in the video. It refers to a langchain version 0.1.9, but such a version does not exist.

System Info

"@langchain/openai": "^0.0.28",
"langchain": "^0.1.36",

node -v
v20.5.1

Copy link

dosubot bot commented May 10, 2024

The issue you're encountering with FewShotChatMessagePromptTemplate not being assignable to ChatPromptTemplate in LangChain.js is due to a type mismatch between these two. This typically happens when the expected properties or methods in one type are not present in the other. To resolve this, you have a few options:

  1. Check for Missing Properties or Methods: Ensure that FewShotChatMessagePromptTemplate includes all properties and methods expected by ChatPromptTemplate. If there are any missing, you'll need to implement them.

  2. Type Assertion: If you're sure that FewShotChatMessagePromptTemplate fulfills the requirements of ChatPromptTemplate at runtime, you can bypass TypeScript's static checks using type assertion:

    const template: ChatPromptTemplate = fewShotChatMessagePromptTemplate as unknown as ChatPromptTemplate;

    Be cautious with this approach, as it skips TypeScript's type checking.

  3. Extend the Class Properly: If FewShotChatMessagePromptTemplate is supposed to extend ChatPromptTemplate, ensure that it does so correctly, including implementing any required methods or properties.

  4. Update Interfaces or Types: If possible, adjust the ChatPromptTemplate interface or type to make it compatible with FewShotChatMessagePromptTemplate, such as by making certain properties optional.

For a more detailed solution, you might need to refer to the LangChain.js documentation or the source code for these templates. If these steps don't resolve your issue, providing more specific details about the missing properties or methods could help in offering further assistance.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label May 10, 2024
@jeasonnow
Copy link
Contributor

jeasonnow commented May 10, 2024

This is because fewShotPromptTemplate is not actually a chatPromptTemplate. fewShot should be a set of question-and-answer pairs used as a knowledge base. You can refer to few-shot-example for more information.
@youngsupchoi

@youngsupchoi
Copy link
Author

Thankyou!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants