当前位置:   article > 正文

Gemini API:Python 快速入门 文档

Gemini API:Python 快速入门 文档

1、安装Python SDK

pip install -q -U google-generativeai

2、设置您的 API 密钥

apikey 提取链接:https://makersuite.google.com/app/apikey

  1. import google.generativeai as genai
  2. GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')
  3. genai.configure(api_key=GOOGLE_API_KEY)

3、示例对话代码

  1. import google.generativeai as genai
  2. genai.configure(api_key=apikey)
  3. model = genai.GenerativeModel('gemini-pro')
  4. response = model.generate_content('介绍一下你自己')
  5. result_content = response.text
  6. print(result_content)

在简单的情况下,response.text您只需要访问器即可。要显示格式化的 Markdown 文本,请使用以下to_markdown函数:

to_markdown(response.text)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/135626
推荐阅读
相关标签
  

闽ICP备14008679号