Google的雙子座AI:API
的綜合指南 Google的雙子座AI模型,尤其是Gemini Pro,有望在AI景觀中取得長足的進步,為Chatgpt等競爭對手提供了有力的替代方案。 本教程探討了雙子座API,使開發人員能夠將尖端的AI功能集成到其應用中。 我們將介紹文本和圖像輸入,模型選擇和高級功能。了解雙子座AI
由Google Research和Google DeepMind開發的多模式AI模型
雙子座Ultra在幾個基准上均優於GPT-4,展示了其卓越的理解和解決問題的能力。 對於AI新移民,Google的AI基礎知識技能軌跡為關鍵概念提供了有益的介紹。
> API設置和配置使用API之前,請從Google AI獲取API鍵:
單擊“獲取API鍵。”
%pip install google-generativeai
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)>
進行適當的渲染。 生成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中文網其他相關文章!