I have a prompt which consists of some fixed text parts and other varient text parts. I am using langchain 0.2 I would like to build up ChatPromptTemplate from multiple parts, and then use it in a chain to get answer from llm. I have the following 3 parts:
[Part 1] system_message_prompt: System, fixed text
[Part 2] notes_message_prompt: varient, May be considered system or human, in this question I will consider it human
[Part 3] user_message_prompt Human, varient text
But I have a problem with selecting/using the correct parts/libraries.
from langchain_huggingface import HuggingFaceEndpoint
from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate, ChatPromptTemplate, MessagesPlaceholder
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.prompts.chat import HumanMessagePromptTemplate, SystemMessagePromptTemplate
....
system_template = "ABC"
system_message_prompt = SystemMessagePromptTemplate.from_template(system_template)
notes_template = "EFG"
notes_message_prompt = HumanMessagePromptTemplate.from_template(notes_template)
user_template = "YXZ {this}"
user_message_prompt = HumanMessagePromptTemplate.from_template(user_template)
chat_prompt = ChatPromptTemplate.from_messages([
system_message_prompt,
notes_message_prompt,
user_message_prompt
])
filled_chat_prompt = chat_prompt.format(this = 'some data')
........
llm_chain = filled_chat_prompt | myllmFromHuggingFace
The error I get is
/usr/local/lib/python3.10/dist-packages/langchain_core/runnables/base.py in coerce_to_runnable(thing)
5513 return cast(Runnable[Input, Output], RunnableParallel(thing))
5514 else:
-> 5515 raise TypeError(
5516 f"Expected a Runnable, callable or dict."
5517 f"Instead got an unsupported type: {type(thing)}"
TypeError: Expected a Runnable, callable or dict.Instead got an unsupported type: <class 'str'>
user84209 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.