generative-ai-python: ValueError: The `response.text` quick accessor only works for simple (single-`Part`) text responses. This response is not simple text.Use the `result.parts` accessor or the full `result.candidates[index].content.parts` lookup instead.
Description of the bug:
Can someone help me check this error? I still ran successfully yesterday with the same code
File ~/cluster-env/trident_env/lib/python3.10/site-packages/pandas/core/series.py:4630, in Series.apply(self, func, convert_dtype, args, **kwargs) 4520 def apply( 4521 self, 4522 func: AggFuncType, (…) 4525 **kwargs, 4526 ) -> DataFrame | Series: 4527 “”" 4528 Invoke function on values of Series. 4529 (…) 4628 dtype: float64 4629 “”" -> 4630 return SeriesApply(self, func, convert_dtype, args, kwargs).apply()
File ~/cluster-env/trident_env/lib/python3.10/site-packages/pandas/core/apply.py:1025, in SeriesApply.apply(self) 1022 return self.apply_str() 1024 # self.f is Callable -> 1025 return self.apply_standard()
File ~/cluster-env/trident_env/lib/python3.10/site-packages/pandas/core/apply.py:1076, in SeriesApply.apply_standard(self) 1074 else: 1075 values = obj.astype(object)._values -> 1076 mapped = lib.map_infer( 1077 values, 1078 f, 1079 convert=self.convert_dtype, 1080 ) 1082 if len(mapped) and isinstance(mapped[0], ABCSeries): 1083 # GH#43986 Need to do list(mapped) in order to get treated as nested 1084 # See also GH#25959 regarding EA support 1085 return obj._constructor_expanddim(list(mapped), index=obj.index)
File ~/cluster-env/trident_env/lib/python3.10/site-packages/pandas/_libs/lib.pyx:2834, in pandas._libs.lib.map_infer()
Cell In[116], line 82, in extract_absa_with_few_shot_gemini(text) 80 response.resolve() 81 time.sleep(1) —> 82 return list_of_dict_to_string(string_to_list_dict(response.text.lower()))
File ~/cluster-env/trident_env/lib/python3.10/site-packages/google/generativeai/types/generation_types.py:328, in BaseGenerateContentResponse.text(self)
326 parts = self.parts
327 if len(parts) != 1 or “text” not in parts[0]:
–> 328 raise ValueError(
329 "The response.text
quick accessor only works for "
330 “simple (single-Part
) text responses. This response is not simple text.”
331 "Use the result.parts
accessor or the full "
332 "result.candidates[index].content.parts
lookup "
333 “instead.”
334 )
335 return parts[0].text
ValueError: The response.text
quick accessor only works for simple (single-Part
) text responses. This response is not simple text.Use the result.parts
accessor or the full result.candidates[index].content.parts
lookup instead.
Actual vs expected behavior:
No response
Any other information you’d like to share?
No response
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Reactions: 6
- Comments: 17
You could try to delete
max_output_tokens
generation_config in the model if you use thatHi @Ki-Zhang ,
When you set up your model, the generation_config is in it. Try ignoring it like this.
@Ki-Zhang As of January 2024, the entire list of Harm Categories can be found here. The implementation for
gemini-pro
orgemini-pro-vision
can be carried out as follows in Python:values for each category can be found here
These settings can be applied as:
Additionally, make sure the image does not contain content related to
openAI
orchatgpt
. Otherwise, it may result in an error. Screenshots taken through the defaultSnipping Tool
on Windows might also lead to such errors.I think the main reason is the model doesn’t return any text in sometimes, based on the explanation of @MarkDaoust in https://github.com/google/generative-ai-python/issues/196#issuecomment-1930503073
I still get this error with my code even when I delete generation_config.
But when I set up
instead of
response.text
This error does not appear anymore.
Thanks for provding this! However, the safety settings does not work for me, instead, changing temperature from 0 to 0.7 works. The generated contents may be blocked since I found my input question is about black people (from MMLU dataset).
So this is caused because content was blocked on the server-side? If so, the thrown exception text is terrible.
Thank you for your answer @HienBM But I just used
model = genai.GenerativeModel('gemini-pro-vision')
to simply set up the genimi-pro-vision model. And I encountered the same problem.I don’t know how to solve this problem. But this problem does not occur when I use other image examples to input the model.