Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'list' object has no attribute 'get' #2337

Closed
eduOS opened this issue Jun 30, 2023 · 10 comments
Closed

AttributeError: 'list' object has no attribute 'get' #2337

eduOS opened this issue Jun 30, 2023 · 10 comments
Labels
api: vertex-ai Issues related to the googleapis/python-aiplatform API.

Comments

@eduOS
Copy link

eduOS commented Jun 30, 2023

Environment details

  • OS type and version: ubuntu
  • Python version: 3.10
  • pip version: pip 23.1.2 from /opt/conda/lib/python3.10/site-packages/pip (python 3.10)
  • google-cloud-aiplatform version: 1.26.1

Steps to reproduce

see the code below

Code example

import vertexai
from vertexai.preview.language_models import ChatModel, CodeChatModel
vertexai.init(project="golden-furnace-383906", location="us-central1")

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/.../golden-furnace-code.json"
googlegpt_parameters = {
    "temperature": 0.5,
    "max_output_tokens": 1024
}
# googlegpt_model = ChatModel.from_pretrained("chat-bison@001")
googlegpt_model = ChatModel.from_pretrained("chat-bison@001")
google_chat = googlegpt_model.start_chat()

prompt = 'what is the meaning of life?'
response = google_chat.send_message(prompt, **googlegpt_parameters)

Stack trace

File /opt/conda/lib/python3.10/site-packages/vertexai/language_models/_language_models.py:804, in _ChatSessionBase.send_message(self, message, max_output_tokens, temperature, top_k, top_p)
    797 prediction = prediction_response.predictions[0]
    798 safety_attributes = prediction["safetyAttributes"]
    799 response_obj = TextGenerationResponse(
    800     text=prediction["candidates"][0]["content"]
    801     if prediction.get("candidates")
    802     else None,
    803     _prediction_response=prediction_response,
--> 804     is_blocked=safety_attributes.get("blocked", False),
    805     safety_attributes=dict(
    806         zip(
    807             safety_attributes.get("categories", []),
    808             safety_attributes.get("scores", []),
    809         )
    810     ),
    811 )
    812 response_text = response_obj.text
    814 self._message_history.append(
    815     ChatMessage(content=message, author=self.USER_AUTHOR)
    816 )

AttributeError: 'list' object has no attribute 'get'
@product-auto-label product-auto-label bot added the api: vertex-ai Issues related to the googleapis/python-aiplatform API. label Jun 30, 2023
@ivanbelenky
Copy link

Prediction(
    predictions=[
        {
            'citationMetadata': [
                {'citations': []}
            ],
            'safetyAttributes': [
                {
                    'categories': [],
                    'blocked': False,
                    'scores': []
                }
            ],
            'candidates': [
                {
                    'author': '1',
                    'content': 'Hello, how can I help you today?'
                }
            ]
        }
    ],
    deployed_model_id='',
    model_version_id='',
    model_resource_name='',
    explanations=None
)

@PhucTranThanh
Copy link

I have the same problem. Downgrading to 1.25.0 works for me.

@ivanbelenky
Copy link

ivanbelenky commented Jun 30, 2023

It seems that someone fucked up at their end. The issue is plain simple. SafetyAttributes returned from the predictive model is expected to be a dict. If you are not using chat sessions, or heavy use of generative conversations, you can always use

from vertexai.preview.language_models import TextGenerationModel

text_model = TextGenerationModel.from_pretrained(model)
response = text_model.predict(prompt)

@amirsartipi13
Copy link

I have the same problem. I use LangChain to connect Vertex AI and I face this issue.

@cabljac
Copy link

cabljac commented Jun 30, 2023

hitting the same problem

@davidjt7
Copy link

I took a fork of the latest main and installed it in my container
pip install git+https://github.com/davidjt7/python-aiplatform.git

Desperate times, desperate measures

@velascoluis
Copy link

It seems fix on 1.27.0

@StefanSamba
Copy link

It seems fix on 1.27.0

Yep pip3 install google-cloud-aiplatform -U to version 1.27.0

@sasha-gitg
Copy link
Member

Thank you for raising this issue and confirming the fix!

@Ark-kun
Copy link
Contributor

Ark-kun commented Jul 5, 2023

For clarity: Only version 1.26.1 is affected. Both 1.26.0 and 1.27.0 are working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vertex-ai Issues related to the googleapis/python-aiplatform API.
Projects
None yet
Development

No branches or pull requests

10 participants