Yuav siv Google Gemini API yuam sij li cas? AI piv txwv kev qhia, kev qhia thiab kev cob qhia suav nrog

Google Gemini API yuam sij, tsis muaj kev txhawj xeeb ntxiv! Ua kom tiav hauv ib feeb thiab hais lus zoo rau kev txhawj xeeb! ✌✌✌ ib

Cov lus qhia ntxaws ntxaws yuav qhia koj ib kauj ruam dhau los, thiab txawm tias tus tshiab tshiab tuaj yeem dhau los ua tus tswv hauv vib nas this!

Hais goodbye rau cumbersome cov kauj ruam thiab muaj nws yooj yimAICov khoom qub! Koom nrog kuv txhawm rau qhib lub ntiaj teb tshiab ntawm AI!

Yuav siv Google Gemini API yuam sij li cas? AI piv txwv kev qhia, kev qhia thiab kev cob qhia suav nrog

Tom qab qhov tshwm sim ntawm Google's Gemini AI, Google tso API nkag mus rau nws tus qauv Gemini. Tam sim no, Google muab API nkag rau Gemini Pro, suav nrog cov qauv ntawv nkaus xwb thiab cov qauv ntawv-plus-visual. Qhov no yog ib qho tseem ceeb tshaj tawm vim hais tias txog niaj hnub no, Google tsis tau ntxiv cov peev xwm pom rau Bard, uas khiav cov ntawv nyeem nkaus xwb. Nrog tus yuam sij API no, thaum kawg koj tuaj yeem sim Gemini's multimodal peev xwm ntawm koj lub computer hauv zos. Cia peb kawm txog kev nkag mus thiab siv Gemini API hauv phau ntawv qhia no.

Nco tseg:Tus yuam sij Google Gemini API tam sim no pub dawb rau cov ntawv nyeem thiab cov qauv pom. Nws yuav pub dawb kom txog rau thaum nws muaj feem ntau muaj nyob rau xyoo tom ntej. Yog li, koj tuaj yeem xa mus txog 60 qhov kev thov ib feeb yam tsis tau teeb tsa Google Cloud them nqi lossis ua rau muaj nqi.

Configure Python thiab Pip ntawm koj lub computer

Lub taub hau rau peb phau ntawv qhia ntawm PC lossis MacNruab Python thiab Pip. Koj xav tau Python 3.9 lossis siab dua nruab.

Yog koj siv Linux system, koj tuaj yeem ua raws li peb cov lus qhiaNruab Python thiab Pip ntawm Ubuntu lossis lwm yam kev faib tawm.

Koj tuaj yeem khiav cov lus txib hauv qab no hauv lub davhlau ya nyob twg rauPaub meej tias Python thiab Pip yog ntsia rau hauv koj lub computer. Nws rov qab tus lej version.

python -V
pip -V

Txheeb xyuas seb Python thiab Pip puas raug teeb tsa. Daim duab 2

Tom qab ua tiav kev teeb tsa, khiav cov lus txib hauv qab no los nruab Google's Generative AI dependencies.

pip install -q -U google-generativeai

Txhim kho Google's Generative AI Dependencies Part 3

Yuav ua li cas kom tau txais Gemini Pro API yuam sij?

Tom ntej no, mus saib makersuite.google.com/app/apikey thiab nkag rau hauv koj tus account Google.

Hauv API Keys, nyemTsim API tus yuam sij hauv qhov project tshiab"button.

Tau txais Gemini Pro API Key 4th

Luam tus yuam sij API thiab khaws cia rau hauv qhov chaw nyab xeeb. Tsis txhob ua lossis faib API yuam sij rau pej xeem.

Luam tus yuam sij API thiab txuag tus thib 5

Yuav siv Gemini Pro API Key (hom ntawv nyeem dawb) li cas?

Zoo ib yam li OpenAI, Google kuj tseem siv Gemini API cov yuam sij ncaj qha rau kev txhim kho thiab kuaj lub hom phiaj. Kuv tau sau cov cai yooj yim kom nws tuaj yeem sim tau yooj yim thiab siv los ntawm cov neeg siv niaj hnub. Hauv qhov piv txwv no, kuv yuav qhia yuav ua li cas siv API yuam sij nrog Gemini Pro cov qauv ntawv.

Ua ntej, tso tawm koj nyiam code editor. Yog tias koj tshiab, cia li nruab Notepad ++. Rau cov neeg siv siab heev, Visual Studio Code yog cov cuab yeej zoo.

Tom qab ntawd, luam thiab muab cov lej hauv qab no rau hauv tus lej editor.

import google.generativeai as genai
genai.configure(api_key='PASTE YOUR API KEY HERE')
model = genai.GenerativeModel('gemini-pro')
response = model.generate_content("What is the meaning of life?")
print(response.text)

Hauv cov code editor, muab tshuaj txhuam koj tus yuam sij Gemini API. Raws li koj tuaj yeem pom, peb txhais cov qauv "gemini-pro", uas yog cov qauv ntawv dawb. Tsis tas li ntawd, peb tau ntxiv cov lus nug uas koj tuaj yeem nug cov lus nug.

"gemini-pro" qauv duab 6

Tam sim no, txuag tus lej thiab muab cov ntaub ntawv npe. Nco ntsoov ntxiv thaum kawg .py. Kuv npe cov ntaub ntawv gemini.py, thiab txuag nws ntawm lub desktop.

Lub npe cov ntaub ntawv gemini.py Daim duab 7

Tom ntej no, qhib lub davhlau ya nyob twg thiab khiav cov lus txib nram qab no kom txav mus rau lub desktop.

cd Desktop

Ib zaug hauv lub davhlau ya nyob twg desktop, tsuas yog khiav cov lus txib hauv qab no kom ua tiav siv Python gemini.py ntaub ntawv.

python gemini.py

Siv Python los tua cov ntaub ntawv gemini.py Daim duab 8

Tam sim no nws yuav teb koj cov lus nug gemini.py Teeb meem teeb tsa hauv cov ntaub ntawv.

Teb cov lus nug uas koj teev nyob rau hauv cov ntaub ntawv gemini.py Daim duab 9

Koj tuaj yeem hloov cov lus nug hauv code editor, txuag nws thiab khiav nws dua gemini.py file kom tau txais cov lus teb tshiab hauv lub davhlau ya nyob twg. Nov yog qhov koj siv Google Gemini API tus yuam sij kom nkag mus rau cov ntawv nyeem nkaus xwb Gemini Pro qauv.

Siv Google Gemini API tus yuam sij kom nkag mus rau cov ntawv dawb Gemini Pro qauv No. 10

Yuav siv Gemini Pro API yuam sij li cas (cov ntawv nyeem thiab pom cov qauv)

Hauv qhov piv txwv no, kuv yuav ua kom pom kev cuam tshuam nrog Gemini Pro multimodal qauv. Nws tseem tsis tau nyob hauv Google Bard, tab sis dhau ntawm API, koj tuaj yeem nkag tau tam sim ntawd. Thankfully, cov txheej txheem kuj yog heev yooj yim thiab seamless.

Qhib cov ntaub ntawv tshiab hauv cov code editor thiab muab tshuaj txhuam cov cai hauv qab no.

import google.generativeai as genai
import PIL.Image
img = PIL.Image.open('image.jpg')
genai.configure(api_key='PASTE YOUR API KEY HERE')
model = genai.GenerativeModel('gemini-pro-vision')
response = model.generate_content(["what is the total calorie count?", img])
print(response.text)

Nco ntsoov muab tshuaj txhuam koj tus yuam sij Gemini API. Ntawm no peb siv gemini-pro-vision qauv, uas yog cov ntawv nyeem thiab pom cov qauv.

gemini-pro-vision qauv duab 11

Tam sim no, txuag cov ntaub ntawv ntawm koj lub desktop thiab ntxiv tom qab lub npe cov ntaub ntawv .py. Kuv mam li npe rau ntawm no geminiv.py .

Npe nws geminiv.py Daim duab 12

Hauv kab thib peb ntawm txoj cai, raws li koj tuaj yeem pom, Kuv taw tes rau AI rau lub image.jpg cov ntaub ntawv, cov npe cov ntaub ntawv yog tib yam. Txawm li cas los xij uas koj ua haujlwm nrog, xyuas kom nws tau txais kev cawmdim nrog geminiv.py Cov ntaub ntawv nyob rau tib qhov chaw thiab muaj tib lub npe cov ntaub ntawv nrog rau qhov tseeb extension. Koj tuaj yeem hla hauv zos JPG thiab PNG cov ntaub ntawv txog li 4MB.

taw tes rau AI rau cov duab.jpg cov ntaub ntawv khaws tseg ntawm kuv lub desktop. Duab 13

Hauv kab thib rau ntawm txoj cai, koj tuaj yeem nug cov lus nug ntsig txog daim duab. Txij li thaum kuv tau nkag mus rau cov duab ntsig txog zaub mov, kuv nug Gemini Pro kom suav cov calories tag nrho.

Tam sim no nws yog lub sijhawm los khiav cov cai hauv lub davhlau ya nyob twg. Tsuas yog txav mus rau lub desktop (hauv kuv rooj plaub) thiab khiav cov lus txib hauv qab no ib los ntawm ib qho. Yog tias koj hloov pauv, nco ntsoov khaws cov ntaub ntawv.

cd Desktop
python geminiv.py
geminiv.py No. 14

Gemini Pro pom cov qauv teb cov lus nug ncaj qha. Koj tuaj yeem nug cov lus nug ntxiv thiab nug AI los piav qhia vim li cas.

Gemini Pro pom qauv yuav ncaj qha teb nqe lus nug 15

Koj tuaj yeem nkag mus rau cov duab sib txawv, tab sis nco ntsoov tias nws phim cov duab cov ntaub ntawv npe, hloov cov lus nug hauv cov cai, thiab rov ua dua. geminiv.py ua ntaub ntawv thov kom tau txais cov lus teb tshiab.

Yuav siv Gemini Pro API yuam sij li cas hauv kev sib tham?

Ua tsaug rau unconv's concise code, koj tuaj yeem tham nrog Gemini Pro qauv siv Gemini AI API tus yuam sij hauv lub qhov rais davhlau ya nyob twg. Txoj kev no, koj tsis tas yuav hloov qhov teeb meem hauv koj cov cai lossis rov ua cov ntaub ntawv Python kom tau txais cov zis tshiab. Koj tuaj yeem txuas ntxiv sib tham hauv lub qhov rais davhlau ya nyob twg.

Qhov zoo tshaj plaws, Google siv kev sib tham keeb kwm ib txwm muaj, yog li koj tsis tas yuav manually ntxiv cov lus teb lossis tswj hwm keeb kwm sib tham hauv arrays lossis cov npe. Nrog kev ua haujlwm yooj yim, Google tuaj yeem khaws txhua qhov kev sib tham keeb kwm hauv kev sib tham. Cov haujlwm tshwj xeeb yog raws li hauv qab no:

Qhib cov code editor thiab paste cov cai hauv qab no.

import google.generativeai as genai
genai.configure(api_key='PASTE YOUR API KEY HERE')
model = genai.GenerativeModel('gemini-pro')
chat = model.start_chat()
while True:
message = input("You: ")
response = chat.send_message(message)
print("Gemini: " + response.text)

Raws li niaj zaus, luam tawm thiab muab tso rau qhov tseem ceeb zoo ib yam li API saum toj no.

Tham nrog Gemini Pro API Ntsiab Duab 16

Ntawm no, txuag cov ntaub ntawv rau koj lub desktop lossis lwm qhov chaw. Nco ntsoov ntxiv thaum kawg .py. kuv npe ib geminichat.py ntaub ntawv.

Cov ntaub ntawv npe geminichat.py No. 17

Tam sim no, qhib lub davhlau ya nyob twg thiab txav mus rau lub desktop. Tom ntej no, khiav geminichat.py ntaub ntawv.

cd Desktop
python geminichat.py

Khiav geminichat.py daim duab 18

Tam sim no koj tuaj yeem yooj yim txuas ntxiv kev sib tham thiab nws yuav nco ntsoov koj cov keeb kwm sib tham. Yog li muaj lwm txoj hauv kev zoo los siv Google Gemini API yuam sij.

gemini pro api teb hauv davhlau ya nyob twg tham duab 19

Nov yog qee qhov piv txwv ntawm qhov koj tuaj yeem ua nrog Google Gemini los ntawm API. Kuv zoo siab tias Google tau ua nws lub zeem muag qauv muaj rau cov neeg nyiam thiab cov tsim tawm, thiab ua ke nrog OpenAI's DALL-E 3 thiab Sib tham GPT Sib piv. Txawm hais tias Gemini Pro pom qauv tsis zoo li GPT-4V qauv, nws tseem zoo heev. Peb tab tom nrhiav rau pem hauv ntej rau kev tshaj tawm Gemini Ultra, uas yuav muab piv rau GPT-4 qauv.

Ntxiv rau qhov ntawd, Gemini Pro API teb txawv rau Google Bard, uas tseem yog siv los ntawm tweaked version ntawm Gemini Pro. Bard cov lus teb zoo li tsis meej pem, tab sis Gemini Pro cov lus teb API tau muaj zog dua thiab txawv.

Peb yuav ua tib zoo saib xyuas txhua qhov kev hloov pauv hauv cheeb tsam no, yog li nyob twj ywm rau ntau ntxiv ntawm Gemini AI. Nyob rau lub sijhawm no, thov tshawb xyuas Google Gemini API koj tus kheej.

评论 评论

Koj email chaw nyob yuav tsis raug luam tawm. Yuav tsum tau siv cov liaj teb * Ntaus Cim

Scroll rau saum