使用谷歌语言模型GEMINI实现简单的聊天/图片识别功能(python google generativeai)
文章目录

获取API KEY
通过下面地址生成调用API所需的KEY。
代码实现
import google.generativeai as genai
genai.configure(api_key="GOOGLE_API_KEY")
def chat_gemini(input):
model = genai.GenerativeModel('gemini-pro')
chat = model.start_chat(history=[])
response = chat.send_message(input, stream=True)
try:
for chunk in response:
print(chunk.text)
except Exception as e:
print(e)使用
chat_gemini('What is the meaning of life?')
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论