ChatPromptTemplate.from_template returns serialized object from vectorstore retriever #21140
Open
5 tasks done
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
🔌: openai
Primarily related to OpenAI integrations
Ɑ: retriever
Related to retriever module
Ɑ: vector store
Related to vector store module
Checked other resources
Example Code
from operator import itemgetter
from langchain_community.vectorstores import FAISS
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
vectorstore = FAISS.from_texts(
["harrison worked at kensho"], embedding=OpenAIEmbeddings()
)
retriever = vectorstore.as_retriever()
template = """Answer the question based only on the following context:
{context}
Question: {question}
Answer in the following language: {language}
"""
prompt = ChatPromptTemplate.from_template(template)
chain = (
{
"context": itemgetter("question") | retriever,
"question": itemgetter("question"),
"language": itemgetter("language"),
}
| prompt
)
chain.invoke({"question": "where did harrison work", "language": "italian"})
Error Message and Stack Trace (if applicable)
ChatPromptValue(messages=[HumanMessage(content="Answer the question based only on the following context:\n[Document(page_content='harrison worked at kensho')]\n\nQuestion: where did harrison work\n\nAnswer in the following language: italian\n")])
Description
ChatPromptValue(messages=[HumanMessage(content="Answer the question based only on the following context:\n"""\nharrison worked at kensho\n"""\n\nQuestion: where did harrison work\n\nAnswer in the following language: italian\n")])
System Info
pip install --upgrade --quiet langchain langchain-openai
The text was updated successfully, but these errors were encountered: