Gemini AI 错误 - “AttributeError:模块‘google.generativeai’没有属性‘GenerativeModel’”

问题描述 投票:0回答:1

我正在尝试在

Jupyter
中创建一个脚本来测试 Google Gemini AI 模型

import google.generativeai as genai
import os

# genai.configure(api_key="API Key")

model = genai.GenerativeModel('gemini-pro')
response = model.generate_content('Please summarise this document: ...')

print(response.text)

我收到此错误:

AttributeError
Traceback (most recent call last)
Input In [2], in <cell line: 6>()
      2 import os
      4 # genai.configure(api_key=os.environ['API_KEY'])
----> 6 model = genai.GenerativeModel('gemini-pro')
      7 response = model.generate_content('Please summarise this document: ...')
      9 print(response.text)

AttributeError: module 'google.generativeai' has no attribute 'GenerativeModel'

我尝试过:

  • 重新安装软件包 -
    python3.11 -m pip install google-generativeai
  • 检查了我安装的包源代码中是否存在名为
    GenerativeModel
    的类,但没有帮助。

Python 和包版本:

  • 蟒蛇:3.11.7
  • 谷歌生成ai=0.5.1
python artificial-intelligence google-gemini
1个回答
0
投票

我遇到了和你一样的问题,你可能会或可能无法实施的修复是将你的 python 版本降级回 3.10,其中 Gemini 似乎可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.