首頁 >科技週邊 >人工智慧 >介紹Google Gemini API:發現新的雙子座AI模型的力量

介紹Google Gemini API:發現新的雙子座AI模型的力量

Christopher Nolan
Christopher Nolan原創
2025-03-08 09:53:10117瀏覽

Google的雙子座AI:API

的綜合指南 Google的雙子座AI模型,尤其是Gemini Pro,有望在AI景觀中取得長足的進步,為Chatgpt等競爭對手提供了有力的替代方案。 本教程探討了雙子座API,使開發人員能夠將尖端的AI功能集成到其應用中。 我們將介紹文本和圖像輸入,模型選擇和高級功能。

了解雙子座AI

由Google Research和Google DeepMind開發的多模式AI模型

gemini AI處理各種數據類型,包括文本,代碼,音頻,圖像和視頻。 它以以人為本的方法建立,旨在使人類受益。 它的可伸縮性允許從數據中心到移動設備進行各種系統部署。 滿足特定需求的三個關鍵版本:

    gemini ultra:
  1. 最先進的模型,在復雜的任務中出色。
  2. gemini pro:
  3. 一個平衡的選項,具有強大的性能和可伸縮性。
  4. > gemini nano:
  5. 針對移動設備進行了優化,優先考慮效率。

Introducing Google Gemini API: Discover the Power of the New Gemini AI Models

圖像源

雙子座Ultra在幾個基准上均優於GPT-4,展示了其卓越的理解和解決問題的能力。 對於AI新移民,Google的AI基礎知識技能軌跡為關鍵概念提供了有益的介紹。

> API設置和配置

使用API​​之前,請從Google AI獲取API鍵:

>

單擊“獲取API鍵。”

    創建一個項目並生成密鑰。 >
  1. >設置“ gemini_api_key”環境變量(如果適用(如果適用),則使用Kaggle Secrets。
  2. 安裝雙子座python api:
  3. >
  4. 使用您的密鑰配置API:
  5. %pip install google-generativeai
  6. 用雙子座pro
  7. 生成響應
  8. >讓我們使用
模型生成文本:
import google.generativeai as genai
from kaggle_secrets import UserSecretsClient # If using Kaggle

user_secrets = UserSecretsClient()
gemini_key = user_secrets.get_secret("GEMINI_API_KEY")  # If using Kaggle

genai.configure(api_key=gemini_key)
>

免費的API提供了一個響應。 要訪問多個候選人,需要一個付費計劃。 請注意,輸出通常以降級格式;使用

進行適當的渲染。 生成python代碼同樣簡單:gemini-pro>

model = genai.GenerativeModel('gemini-pro')
response = model.generate_content("List the most influential people in the world.")
print(response.text)
利用流媒體以增強性能

> IPython.display.Markdown通過使用流媒體提高感知速度:

response = model.generate_content("Build a simple Python web application.")
Markdown(response.text)

微調響應

使用

自定義響應:
from IPython.display import display

model = genai.GenerativeModel("gemini-pro")
response = model.generate_content("How can I make authentic Italian pasta?", stream=True)

for chunk in response:
    display(Markdown(chunk.text))
    display(Markdown("_" * 80))

>利用雙子座的雙模式輸入

GenerationConfig> Gemini Pro Vision處理圖像輸入。 下載圖像(例如,使用

)後,使用枕頭加載並顯示它:
response = model.generate_content(
    'How to be productive during a burnout stage.',
    generation_config=genai.types.GenerationConfig(
        candidate_count=1,
        stop_sequences=['time'],
        max_output_tokens=1000,
        temperature=0.7)
)

Markdown(response.text)

然後,將圖像與模型一起使用:

import google.generativeai as genai
from kaggle_secrets import UserSecretsClient # If using Kaggle

user_secrets = UserSecretsClient()
gemini_key = user_secrets.get_secret("GEMINI_API_KEY")  # If using Kaggle

genai.configure(api_key=gemini_key)

>聊天對話和上下文保留

使用start_chat維護對話上下文:

model = genai.GenerativeModel('gemini-pro')
response = model.generate_content("List the most influential people in the world.")
print(response.text)

>使用嵌入式

生成用於語義分析的嵌入:

response = model.generate_content("Build a simple Python web application.")
Markdown(response.text)

高級功能和結論

探索高級功能,例如安全設置,低級API訪問以及擴展的多轉向對話,以增強應用程序開發。 雙子座API使開發人員能夠創建複雜的AI應用程序,利用其多模式功能和無縫的Python集成。 進一步的學習資源,包括課程和作弊表,可用於更深入的探索。

>

以上是介紹Google Gemini API:發現新的雙子座AI模型的力量的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn