# Python with Gemini 1. python 版本確認 在 終端機(terminal)打 ```= python --version ``` 或 ```= python3 --version ``` 確認版本在 3.9 以上 2. 註冊 Gemini API https://aistudio.google.com/app/prompts/new_chat 取得 API key 3. 建一個 ```.py``` 檔,如 ```gemini.py```,用VScode開啟 輸入以下 code ```python= """ Install the Google AI Python SDK $ pip install google-generativeai """ import os import google.generativeai as genai genai.configure(api_key="輸入你的 api-key") # Create the model generation_config = { "temperature": 1, "top_p": 0.95, "top_k": 64, "max_output_tokens": 8192, "response_mime_type": "text/plain", } model = genai.GenerativeModel( model_name="gemini-1.5-flash", generation_config=generation_config, # safety_settings = Adjust safety settings # See https://ai.google.dev/gemini-api/docs/safety-settings ) chat_session = model.start_chat( history=[ ] ) response = chat_session.send_message("輸入你的問題==") print(response.text) ``` 4. 在終端機執行 ```= pip install -q google-generativeai ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up