admin管理员组文章数量:1355574
ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: #: required key [messages] not found, please reformat your input and try again.
below is the code snippets
def get_response(llm, vectorstore, question):
## create prompt / template
prompt_template = """
Human: Please use the given context to provide concise answer to the question.
If you don't know the answer, just say that you don't know, don't try to make up an answer.
<context>
{context}
</context>
Question: {question}
Assistant:
"""
# Create the PromptTemplate instance
PROMPT = PromptTemplate(
template=prompt_template, input_variables=["context", "question"]
)
# Use the vectorstore retriever to fetch the relevant documents for the question
retriever = vectorstore.as_retriever(
search_type="similarity", search_kwargs={"k": 5}
)
# Create the RetrievalQA instance
qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriever,
return_source_documents=True,
chain_type_kwargs={"prompt": PROMPT} # Pass the custom prompt template
)
# Retrieve relevant documents based on the question
context = retriever.get_relevant_documents(question)
# Use the qa object to get a response with the context and question
response = qa({"context": context, "question": question})
# Return the generated answer
return response['result']
i have tried many ways such as reformat inputs and also update the versions of libraries and ensure that all model api keys is correct but not getting response from retriever( from vector store) so please help me to resolve this issue.
ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: #: required key [messages] not found, please reformat your input and try again.
below is the code snippets
def get_response(llm, vectorstore, question):
## create prompt / template
prompt_template = """
Human: Please use the given context to provide concise answer to the question.
If you don't know the answer, just say that you don't know, don't try to make up an answer.
<context>
{context}
</context>
Question: {question}
Assistant:
"""
# Create the PromptTemplate instance
PROMPT = PromptTemplate(
template=prompt_template, input_variables=["context", "question"]
)
# Use the vectorstore retriever to fetch the relevant documents for the question
retriever = vectorstore.as_retriever(
search_type="similarity", search_kwargs={"k": 5}
)
# Create the RetrievalQA instance
qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriever,
return_source_documents=True,
chain_type_kwargs={"prompt": PROMPT} # Pass the custom prompt template
)
# Retrieve relevant documents based on the question
context = retriever.get_relevant_documents(question)
# Use the qa object to get a response with the context and question
response = qa({"context": context, "question": question})
# Return the generated answer
return response['result']
i have tried many ways such as reformat inputs and also update the versions of libraries and ensure that all model api keys is correct but not getting response from retriever( from vector store) so please help me to resolve this issue.
Share Improve this question asked Mar 30 at 18:53 DIVYANSH TRIVEDIDIVYANSH TRIVEDI 11 bronze badge1 Answer
Reset to default 0In simple terms, it appears from the stacktrace that your input message is not formatted correctly.
Specifically, it's missing the messages
part of the request. Models may have different request formats so it's important to ensure you're matching the requested format of your chosen model.
You don't specify which foundation model you're using but you can view examples of the request message formats required per model here:- Bedrock Runtime Code Examples
本文标签:
版权声明:本文标题:langchain - Error raised by bedrock service: when calling the InvokeModel operation: Malformed input request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743977862a2570949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论