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

'Google' object has no attribute 'co' and 'AttributeError' object has no attribute 'message' #462

Closed
aparnajore opened this issue Feb 26, 2024 · 9 comments

Comments

@aparnajore
Copy link

aparnajore commented Feb 26, 2024

After resolving the issue #417, I tried to use Google LM but facing some new issues like
AttributeError: 'Google' object has no attribute 'co'
AttributeError: 'AttributeError' object has no attribute 'message'


AttributeError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/backoff/_sync.py in retry(*args, **kwargs)
104 try:
--> 105 ret = target(*args, **kwargs)
106 except exception as e:

8 frames
/usr/local/lib/python3.10/dist-packages/dsp/modules/google.py in request(self, prompt, **kwargs)
94 """Handles retrieval of completions from Google whilst handling API errors"""
---> 95 return self.basic_request(prompt, **kwargs)
96

/usr/local/lib/python3.10/dist-packages/dsp/modules/google.py in basic_request(self, prompt, **kwargs)
73 }
---> 74 response = self.co.generate(**kwargs)
75

AttributeError: 'Google' object has no attribute 'co'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
in <cell line: 18>()
16 # Call the predictor on a particular input.
17 question='What is the color of the sky?'
---> 18 pred = generate_answer(question=question)
19
20 print(f"Question: {question}")

/usr/local/lib/python3.10/dist-packages/dspy/predict/predict.py in call(self, **kwargs)
47
48 def call(self, **kwargs):
---> 49 return self.forward(**kwargs)
50
51 def forward(self, **kwargs):

/usr/local/lib/python3.10/dist-packages/dspy/predict/predict.py in forward(self, **kwargs)
88
89 if self.lm is None:
---> 90 x, C = dsp.generate(template, **config)(x, stage=self.stage)
91 else:
92 # Note: query_only=True means the instructions and examples are not included.

/usr/local/lib/python3.10/dist-packages/dsp/primitives/predict.py in do_generate(example, stage, max_depth, original_example)
76 # Generate and extract the fields.
77 prompt = template(example)
---> 78 completions: list[dict[str, Any]] = generator(prompt, **kwargs)
79 completions: list[Example] = [template.extract(example, p) for p in completions]
80

/usr/local/lib/python3.10/dist-packages/dsp/modules/google.py in call(self, prompt, only_completed, return_sorted, **kwargs)
102 **kwargs,
103 ):
--> 104 return self.request(prompt, **kwargs)

/usr/local/lib/python3.10/dist-packages/backoff/_sync.py in retry(*args, **kwargs)
109 elapsed >= max_time_value)
110
--> 111 if giveup(e) or max_tries_exceeded or max_time_exceeded:
112 _call_handlers(on_giveup, **details, exception=e)
113 if raise_on_giveup:

/usr/local/lib/python3.10/dist-packages/dsp/modules/google.py in giveup_hdlr(details)
23 def giveup_hdlr(details):
24 """wrapper function that decides when to give up on retry"""
---> 25 if "rate limits" in details.message:
26 return False
27 return True

AttributeError: 'AttributeError' object has no attribute 'message'

@aparnajore
Copy link
Author

I tried to resolve above issues and generate a response but getting only single character in the output and the completions gets omitted after that. But when tried with GPT3, I am getting complete response. Could you please help me for getting complete response using Google LM?

@arnavsinghvi11
Copy link
Collaborator

tagging @CShorten here. I think self.co is supposed to be self.google right? :)

That might fix up the error since I don't believe there's a generation yet.

@markgunnels
Copy link

I'm getting this error as well. I don't think genai.configure returns anything. I think self.google should maybe be set to genai.GenerativeModel with the model passed as an argument after genai.configure is called?

I'm a Python newbie. YMMV.

CShorten added a commit that referenced this issue Feb 27, 2024
- Solves issue #462 

- Re issue #463 I'm not sure if the vertex API will be more reliable than google.generativeai, so I think it makes sense to rename this one to `googlegenerativeai` rather than just `google`.

- The google.generativeai API has changed significantly since last week. There is a new conv.send_message syntax. I have tested that this works.
@CShorten
Copy link
Collaborator

Hey @markgunnels, nice to see you here!

Thanks for tagging @arnavsinghvi11 and for finding this @aparnajore! This PR will fix it -- please note the google.generativeai changed significantly from last week, and I think it makes sense to change the naming a bit as well with GoogleVertex and GoogleGenerativeAI.

#472

@CShorten
Copy link
Collaborator

This is a better version -- #461. Just tested, worked for me!

@aparnajore
Copy link
Author

aparnajore commented Feb 27, 2024

Hello @CShorten, thanks for the updates. Could you please let me know when it will be reflected in main code?

@aparnajore
Copy link
Author

I tried with #461 but getting InternalServerError
InternalServerError: 500 POST http://localhost:39955/v1beta/models/gemini-1.0-pro:generateContent?%24alt=json%3Benum-encoding%3Dint: TypeError: Failed to fetch.

@nbqu
Copy link
Contributor

nbqu commented Feb 27, 2024

Google API sometimes raises 500 errors, so you need to handle these failures by specifying max_tries in backoff decorator.

Hope you can resolve this problem!

@aparnajore
Copy link
Author

Thanks @CShorten and @nbqu, now its working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants