def get_trulens_bedrock():
import os
from trulens_eval import Bedrock
import boto3
region =
profile =
os.environ["AWS_PROFILE"] = profile
os.environ["AWS_REGION"] = region
session = boto3.Session(region_name=region)
boto3_bedrock = session.client(service_name="bedrock-runtime")
bedrock = Bedrock(credentials_profile_name=profile,
model_id="anthropic.claude-v2",
client=boto3_bedrock
)
return bedrock
from llama_index.indices.postprocessor import SentenceTransformerRerank
from llama_index.retrievers import AutoMergingRetriever
from llama_index.query_engine import RetrieverQueryEngine
automerging_retriever = automerging_index.as_retriever(
similarity_top_k=12,
)
retriever = AutoMergingRetriever(
automerging_retriever,
automerging_index.storage_context,
verbose=True,
)
rerank = SentenceTransformerRerank(top_n=6, model="BAAI/bge-reranker-base")
prompt_temp = """
Human: Use the following pieces of context to provide a concise answer to the question at the end. 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:"""
from llama_index.prompts import PromptTemplate
qa_template = PromptTemplate(prompt_temp, template_var_mappings={"query_str": "question", "context_str": "context"})
auto_merging_engine = RetrieverQueryEngine.from_args(
retriever=retriever, service_context=auto_merging_context, node_postprocessors=[rerank], text_qa_template=qa_template
)
The code that I'm sharing with you is not working with bedrock. Could you help me?
Next error is being returned:
bedrock request failed <class 'botocore.errorfactory.ValidationException'>=An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: 4 schema violations found, please reformat your input and try again.. Retries remaining=0.
....
RuntimeError: Evaluation of relevance failed on inputs: {'prompt': ...} API bedrock request failed 4 time(s)..