The Problem:
When using LangChain with the GPT-4 model for summarization, an error occurs: ValueError: Got unknown type S
. This error does not occur when using the GPT-3.5-turbo model instead of GPT-4. The error arises from the _convert_message_to_dict
function in the langchain.chat_models.openai
module when attempting to convert messages to a dictionary format.
The Solutions:
Solution 1: Replace PromptTemplate with ChatPromptTemplate
As llm uses ChatOpenAI model, it’s necessary to change the prompt template to ChatPromptTemplate instead of PromptTemplate. Additionally, change the human message prompt to a ChatPromptTemplate using from_template function.
Q&A
How to fix ValueError: Got unknown type S when using GPT-4 with LangChain for Summarization?
Replace your PromptTemplate with a ChatPromptTemplate since it’s a ChatOpenAI model.
Video Explanation:
The following video, titled "How to install Unstructured for Langchain Document loaders ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
I wish I had found this video before wasting 2 hours. New to coding and my one main gripe is how user 'unfriendly' all the set up steps are.
The following video, titled "How to install Unstructured for Langchain Document loaders ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
I wish I had found this video before wasting 2 hours. New to coding and my one main gripe is how user 'unfriendly' all the set up steps are.