我想使用 Gemini AI 模型,但不断收到此消息 - AttributeError: module 'google.generativeai' has no attribute 'GenerativeModel'

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

我正在尝试在 jupyter 中创建一个脚本来测试 google GEMINI AI 模型,参考下面的链接https://ai.google.dev/api/python/google/generativeai


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”的类,但没有帮助。

期望:我希望 GEMINI 返回正确的回复。

配置:
python-3.11.7
谷歌生成ai-0.5.1

python artificial-intelligence google-gemini
1个回答
0
投票

我使用 pip install google-generativeai

使用以下代码:

import google.generativeai as genai
import os


genai.configure(api_key="[redacted]")
model = genai.GenerativeModel('gemini-1.5-pro-latest')
response = model.generate_content("What is the meaning of life in two sentences")
print(response.text)

您似乎注释掉了配置并且没有传递您的 api 密钥。

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