aws-samples / amazon-bedrock-workshop

This is a workshop designed for Amazon Bedrock a foundational model service.
https://catalog.us-east-1.prod.workshops.aws/workshops/a4bdb007-5600-4368-81c5-ff5b4154f518/en-US/20-intro
MIT No Attribution
1.39k stars 595 forks source link

Exception `Bedrock` object has no attribute `invoke_model` #91

Closed jbatra-umeey closed 11 months ago

jbatra-umeey commented 11 months ago

Hello Team,

I am trying to run https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/03_QuestionAnswering/01_qa_w_rag_claude.ipynb but its throwing a null exception with the following stacktrace

Traceback (most recent call last):
  File "/Users/dev/.pyenv/versions/3.9.16/lib/python3.9/site-packages/langchain/embeddings/bedrock.py", line 121, in _embedding_func
    response = self.client.invoke_model(
AttributeError: 'Bedrock' object has no attribute 'invoke_model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/dev/spe_genai_enablers/AWS-Squad/Unit-Test-Generation/Playground/RAG.py", line 155, in <module>
    vectorstore_faiss = FAISS.from_documents(
  File "/Users/dev/.pyenv/versions/3.9.16/lib/python3.9/site-packages/langchain/schema/vectorstore.py", line 422, in from_documents
    return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs)
  File "/Users/dev/.pyenv/versions/3.9.16/lib/python3.9/site-packages/langchain/vectorstores/faiss.py", line 602, in from_texts
    embeddings = embedding.embed_documents(texts)
  File "/Users/dev/.pyenv/versions/3.9.16/lib/python3.9/site-packages/langchain/embeddings/bedrock.py", line 143, in embed_documents
    response = self._embedding_func(text)
  File "/Users/dev/.pyenv/versions/3.9.16/lib/python3.9/site-packages/langchain/embeddings/bedrock.py", line 130, in _embedding_func
    raise ValueError(f"Error raised by inference endpoint: {e}")
ValueError: Error raised by inference endpoint: 'Bedrock' object has no attribute 'invoke_model'

External dependencies from Requirements.txt

aws==0.2.5
awscli==1.29.62
boto==2.49.0
boto3==1.28.62
botocore==1.31.62
langchain==0.0.309

Request you to please suggest suitable changes

kamojiro commented 11 months ago

If you just want to run this jupyter notebook, you can do so by download and installing Python packages based on old commits like the following. https://github.com/aws-samples/amazon-bedrock-workshop/tree/1bed952ae51fa559a7325207c8cc3c525211ea4b

A brief description of the procedure is also provided.

git clone https://github.com/aws-samples/amazon-bedrock-workshop.git
cd amazon-bedrock-workshop/
git checkout 1bed952ae51fa559a7325207c8cc3c525211ea4b
bash ./download-dependencies.sh
pip install --no-build-isolation --force-reinstall \
    dependencies/awscli-*-py3-none-any.whl \
    dependencies/boto3-*-py3-none-any.whl \
    dependencies/botocore-*-py3-none-any.whl
lauerarnaud commented 11 months ago

Please retest with latest version of repo and latest SDK now that Amazon Bedrock is Generally Available. The dependencies are no longer required and SDK has now two clients, bedrock and bedrock-runtime. Workshop has been updated accordingly.