问题描述
在使用Gemini api批量访问时报错 IndexError: list index out of range
解决方法
经过查阅,是gemini内容过滤器将生成的内容过滤导致返回的内容为空,因此在安全设置中将过滤器禁止即可,在代码response请求时,添加 safety_settings
response = model.generate_content(
['Do these look store-bought or homemade?', img],
safety_settings={
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT:HarmBlockThreshold.BLOCK_NONE,
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT:HarmBlockThreshold.BLOCK_NONE
}
)