dspy icon indicating copy to clipboard operation
dspy copied to clipboard

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

Open aparnajore opened this issue 11 months ago • 9 comments

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 avatar Feb 26 '24 07:02 aparnajore

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?

aparnajore avatar Feb 26 '24 07:02 aparnajore

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.

arnavsinghvi11 avatar Feb 26 '24 21:02 arnavsinghvi11

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.

markgunnels avatar Feb 27 '24 01:02 markgunnels

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.

https://github.com/stanfordnlp/dspy/pull/472

CShorten avatar Feb 27 '24 02:02 CShorten

This is a better version -- https://github.com/stanfordnlp/dspy/pull/461. Just tested, worked for me!

CShorten avatar Feb 27 '24 02:02 CShorten

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

aparnajore avatar Feb 27 '24 05:02 aparnajore

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.

aparnajore avatar Feb 27 '24 13:02 aparnajore

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!

nbqu avatar Feb 27 '24 23:02 nbqu

Thanks @CShorten and @nbqu, now its working.

aparnajore avatar Feb 28 '24 07:02 aparnajore