Replies: 2 comments 4 replies
-
Hey @intern162! 👋 I'm here to help you tackle any bugs, answer questions, and guide you on how to contribute. If you have any issues or queries, feel free to ask! To resolve the type error "Expected mapping type as input to PromptTemplate. Received <class 'langchain_core.messages.ai.AIMessage>" when using a LangChain graph with a prompt template, ensure that you are passing a dictionary (mapping type) to the Here is an example of how to correctly use the from langchain_core.prompts import ChatPromptTemplate
chat_template = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful AI bot. Your name is {name}."),
("human", "Hello, how are you doing?"),
("ai", "I'm doing well, thanks!"),
("human", "{user_input}"),
]
)
messages = chat_template.format_messages(name="Bob", user_input="What is your name?") In your case, ensure that the Here's how you can modify your def supervisor_node(state: CustomState) -> CustomState:
# Append the new message to the messages list
state['messages'].append(HumanMessage(content="Based on the current state and the information provided, determine the next step."))
# Convert messages to dictionaries
messages_dict = [{"content": msg.content, "type": msg.type} for msg in state['messages']]
# Invoke the supervisor chain
supervisor_response = supervisor_chain.invoke({
"file_in_focus": state['file_in_focus'],
"error_list": state['error_list'],
"messages": messages_dict,
"root_dir": state['root_dir']
})
# Append the supervisor's response to the messages list
state['messages'].append(HumanMessage(content=supervisor_response.message))
# Return the updated state
return {
'messages': state['messages'],
'next': supervisor_response.next,
'file_in_focus': state['file_in_focus'],
'root_dir': state['root_dir'],
'error_list': state['error_list'],
'iterations': 0
} This should resolve the type error you are encountering [1][2]. |
Beta Was this translation helpful? Give feedback.
-
Fixed, I had a typo in there. Sorry |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to use this graph just to test if the supervisor components works but the promp template keeps failing with type error:
Expected mapping type as input to PromptTemplate. Received <class 'langchain_core.messages.ai.AIMessage
Switching to str instead of HumanMessage, also does not seem to help.
System Info
M1 Pro Mac
Beta Was this translation helpful? Give feedback.
All reactions