1"use strict";(self.webpackChunkspring_ai_alibaba_website=self.webpackChunkspring_ai_alibaba_website||[]).push([[4763],{28453:(e,n,i)=>{i.d(n,{R:()=>s,x:()=>t});var o=i(96540);const l={},r=o.createContext(l);function s(e){const n=o.useContext(r);return o.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function t(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:s(e.components),o.createElement(r.Provider,{value:n},e.children)}},38940:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>a,contentTitle:()=>t,default:()=>h,frontMatter:()=>s,metadata:()=>o,toc:()=>d});const o=JSON.parse('{"id":"chatmodels/more/google-genai-chat","title":"Google GenAI Chat","description":"Google GenAI API \u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u901a\u8fc7 Gemini Developer API \u6216 Vertex AI \u4f7f\u7528 Google \u7684 Gemini \u6a21\u578b\u6784\u5efa\u751f\u6210\u5f0f AI \u5e94\u7528\u7a0b\u5e8f\u3002","source":"@site/integration/chatmodels/more/google-genai-chat.md","sourceDirName":"chatmodels/more","slug":"/chatmodels/more/google-genai-chat","permalink":"/integration/chatmodels/more/google-genai-chat","draft":false,"unlisted":false,"editUrl":"https://github.com/spring-ai-alibaba/website/tree/main/integration/chatmodels/more/google-genai-chat.md","tags":[],"version":"current","lastUpdatedBy":"Ken Liu","lastUpdatedAt":1768271906000,"frontMatter":{},"sidebar":"integrationSidebar","previous":{"title":"Docker Model Runner Chat","permalink":"/integration/chatmodels/more/dmr-chat"},"next":{"title":"Google VertexAI API","permalink":"/integration/chatmodels/more/google-vertexai"}}');var l=i(74848),r=i(28453);const s={},t="Google GenAI Chat",a={},d=[{value:"Prerequisites",id:"prerequisites",level:2},{value:"Option 1: Gemini Developer API (API Key)",id:"option-1-gemini-developer-api-api-key",level:3},{value:"Option 2: Vertex AI (Google Cloud)",id:"option-2-vertex-ai-google-cloud",level:3},{value:"Auto-configuration",id:"auto-configuration",level:2},{value:"Chat Properties",id:"chat-properties",level:3},{value:"Connection Properties",id:"connection-properties",level:4},{value:"Chat Model Properties",id:"chat-model-properties",level:4},{value:"Runtime options [[chat-options]]",id:"runtime-options-chat-options",level:2},{value:"Tool Calling",id:"tool-calling",level:2},{value:"Multimodal",id:"multimodal",level:2},{value:"Image, Audio, Video",id:"image-audio-video",level:3},{value:"PDF",id:"pdf",level:3},{value:"Sample Controller",id:"sample-controller",level:2},{value:"Using Gemini Developer API (API Key)",id:"using-gemini-developer-api-api-key",level:3},{value:"Using Vertex AI",id:"using-vertex-ai",level:3},{value:"Manual Configuration",id:"manual-configuration",level:2},{value:"Using API Key",id:"using-api-key",level:3},{value:"Using Vertex AI",id:"using-vertex-ai-1",level:3},{value:"Migration from Vertex AI Gemini",id:"migration-from-vertex-ai-gemini",level:2},{value:"Key Differences",id:"key-differences",level:3},{value:"When to Use Google GenAI vs Vertex AI Gemini",id:"when-to-use-google-genai-vs-vertex-ai-gemini",level:3},{value:"Low-level Java Client [[low-level-api]]",id:"low-level-java-client-low-level-api",level:2}];function c(e){const n={a:"a",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,r.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(n.header,{children:(0,l.jsx)(n.h1,{id:"google-genai-chat",children:"Google GenAI Chat"})}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.a,{href:"https://ai.google.dev/gemini-api/docs",children:"Google GenAI API"})," \u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u901a\u8fc7 Gemini Developer API \u6216 Vertex AI \u4f7f\u7528 Google \u7684 Gemini \u6a21\u578b\u6784\u5efa\u751f\u6210\u5f0f AI \u5e94\u7528\u7a0b\u5e8f\u3002\nGoogle GenAI API \u652f\u6301 multimodal prompts \u4f5c\u4e3a\u8f93\u5165\uff0c\u8f93\u51fa text \u6216 code\u3002\nmultimodal model \u80fd\u591f\u5904\u7406\u6765\u81ea\u591a\u79cd\u6a21\u6001\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u56fe\u50cf\u3001\u89c6\u9891\u548c\u6587\u672c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5411\u6a21\u578b\u53d1\u9001\u4e00\u76d8\u997c\u5e72\u7684\u7167\u7247\uff0c\u5e76\u8981\u6c42\u5b83\u4e3a\u60a8\u63d0\u4f9b\u8fd9\u4e9b\u997c\u5e72\u7684\u914d\u65b9\u3002"]}
1),"\n",(0,l.jsxs)(n.p,{children:["Gemini \u662f\u7531 Google DeepMind \u5f00\u53d1\u7684\u751f\u6210\u5f0f AI \u6a21\u578b\u7cfb\u5217\uff0c\u4e13\u4e3a multimodal \u7528\u4f8b\u8bbe\u8ba1\u3002Gemini API \u8ba9\u60a8\u53ef\u4ee5\u8bbf\u95ee ",(0,l.jsx)(n.a,{href:"https://ai.google.dev/gemini-api/docs/models#gemini-2.0-flash",children:"Gemini 2.0 Flash"}),"\u3001",(0,l.jsx)(n.a,{href:"https://ai.google.dev/gemini-api/docs/models#gemini-2.0-flash-lite",children:"Gemini 2.0 Flash-Lite"})," \u548c ",(0,l.jsx)(n.a,{href:"https://ai.google.dev/gemini-api/docs/models",children:"Gemini Pro"})," \u6a21\u578b\u3002"]}),"\n",(0,l.jsx)(n.p,{children:"\u6b64\u5b9e\u73b0\u63d0\u4f9b\u4e24\u79cd\u8eab\u4efd\u9a8c\u8bc1\u6a21\u5f0f\uff1a"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:"Gemini Developer API"}),": \u4f7f\u7528 API key \u8fdb\u884c\u5feb\u901f\u539f\u578b\u8bbe\u8ba1\u548c\u5f00\u53d1"]}),"\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:"Vertex AI"}),": \u4f7f\u7528 Google Cloud credentials \u8fdb\u884c\u5177\u6709\u4f01\u4e1a\u529f\u80fd\u7684\u751f\u4ea7\u90e8\u7f72"]}),"\n"]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.a,{href:"https://ai.google.dev/api",children:"Gemini API Reference"})}),"\n",(0,l.jsx)(n.h2,{id:"prerequisites",children:"Prerequisites"}),"\n",(0,l.jsx)(n.p,{children:"\u9009\u62e9\u4ee5\u4e0b\u8eab\u4efd\u9a8c\u8bc1\u65b9\u6cd5\u4e4b\u4e00\uff1a"}),"\n",(0,l.jsx)(n.h3,{id:"option-1-gemini-developer-api-api-key",children:"Option 1: Gemini Developer API (API Key)"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:["\u4ece ",(0,l.jsx)(n.a,{href:"https://aistudio.google.com/app/apikey",children:"Google AI Studio"})," \u83b7\u53d6 API key"]}),"\n",(0,l.jsx)(n.li,{children:"\u5c06 API key \u8bbe\u7f6e\u4e3a\u73af\u5883\u53d8\u91cf\u6216\u5728\u5e94\u7528\u7a0b\u5e8f\u5c5e\u6027\u4e2d\u8bbe\u7f6e"}),"\n"]}),"\n",(0,l.jsx)(n.h3,{id:"option-2-vertex-ai-google-cloud",children:"Option 2: Vertex AI (Google Cloud)"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:["\u5b89\u88c5\u9002\u5408\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684 ",(0,l.jsx)(n.a,{href:"https://cloud.google.com/sdk/docs/install",children:"gcloud"})," CLI\u3002"]}),"\n",(0,l.jsxs)(n.li,{children:["\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3002\n\u5c06 ",(0,l.jsx)(n.code,{children:"PROJECT_ID"})," \u66ff\u6362\u4e3a\u60a8\u7684 Google Cloud project ID\uff0c\u5c06 ",(0,l.jsx)(n.code,{children:"ACCOUNT"})," \u66ff\u6362\u4e3a\u60a8\u7684 Google Cloud \u7528\u6237\u540d\u3002"]}),"\n"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{children:"gcloud config set project <PROJECT_ID> &&\ngcloud auth application-default login <ACCOUNT>\n"})}),"\n",(0,l.jsx)(n.h2,{id:"auto-configuration",children:"Auto-configuration"}),"\n",(0,l.jsxs)(n.blockquote,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"\u6ce8\u610f\uff1a"}),"\nSpring AI auto-configuration\u3001starter modules \u7684 artifact \u540d\u79f0\u53d1\u751f\u4e86\u91cd\u5927\u53d8\u5316\u3002\n\u8bf7\u53c2\u9605 ",(0,l.jsx)(n.a,{href:"https://docs.spring.io/spring-ai/reference/upgrade-notes.html",children:"upgrade notes"})," \u4e86\u89e3\u66f4\u591a\u4fe1\u606f\u3002"]}),"\n"]}),"\n",(0,l.jsxs)(n.p,{children:["Spring AI \u4e3a Google GenAI Chat Client \u63d0\u4f9b Spring Boot auto-configuration\u3002\n\u8981\u542f\u7528\u5b83\uff0c\u8bf7\u5c06\u4ee5\u4e0b\u4f9d\u8d56\u9879\u6dfb\u52a0\u5230\u9879\u76ee\u7684 Maven ",(0,l.jsx)(n.code,{children:"pom.xml"})," \u6216 Gradle ",(0,l.jsx)(n.code,{children:"build.gradle"})," \u6784\u5efa\u6587\u4ef6\u4e2d\uff1a"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-xml",children:"<dependency>\n <groupId>org.springframework.ai</groupId>\n <artifactId>spring-ai-starter-model-google-genai</artifactId>\n</dependency>\n"})}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-groovy",children:"dependencies {\n implementation 'org.springframework.ai:spring-ai-starter-model-google-genai'\n}\n"})}),"\n",(0,l.jsxs)(n.blockquote,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"\u63d0\u793a\uff1a"})," \u8bf7\u53c2\u9605 ",(0,l.jsx)(n.a,{href:"https://docs.spring.io/spring-ai/reference/getting-started.html#dependency-management",children:"Dependency Management"})," \u90e8\u5206\uff0c\u5c06 Spring AI BOM \u6dfb\u52a0\u5230\u60a8\u7684\u6784\u5efa\u6587\u4ef6\u4e2d\u3002"]}),"\n"]}),"\n",(0,l.jsx)(n.h3,{id:"chat-properties",children:"Chat Properties"}),"\n",(0,l.jsxs)(n.blockquote,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"\u6ce8\u610f\uff1a"}
1),"\n\u73b0\u5728\u901a\u8fc7\u524d\u7f00\u4e3a ",(0,l.jsx)(n.code,{children:"spring.ai.model.chat"})," \u7684\u9876\u7ea7\u5c5e\u6027\u6765\u914d\u7f6e chat auto-configurations \u7684\u542f\u7528\u548c\u7981\u7528\u3002"]}),"\n",(0,l.jsx)(n.p,{children:"\u8981\u542f\u7528\uff0cspring.ai.model.chat=google-genai\uff08\u9ed8\u8ba4\u542f\u7528\uff09"}),"\n",(0,l.jsx)(n.p,{children:"\u8981\u7981\u7528\uff0cspring.ai.model.chat=none\uff08\u6216\u4efb\u4f55\u4e0e google-genai \u4e0d\u5339\u914d\u7684\u503c\uff09"}),"\n",(0,l.jsx)(n.p,{children:"\u6b64\u66f4\u6539\u662f\u4e3a\u4e86\u5141\u8bb8\u914d\u7f6e\u591a\u4e2a\u6a21\u578b\u3002"}),"\n"]}),"\n",(0,l.jsx)(n.h4,{id:"connection-properties",children:"Connection Properties"}),"\n",(0,l.jsxs)(n.p,{children:["\u524d\u7f00 ",(0,l.jsx)(n.code,{children:"spring.ai.google.genai"})," \u662f\u7528\u4e8e\u8fde\u63a5\u5230 Google GenAI \u7684\u5c5e\u6027\u524d\u7f00\u3002"]}),"\n",(0,l.jsxs)(n.table,{children:[(0,l.jsx)(n.thead,{children:(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.th,{children:"Property"}),(0,l.jsx)(n.th,{children:"Description"}),(0,l.jsx)(n.th,{children:"Default"})]})}),(0,l.jsxs)(n.tbody,{children:[(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.model.chat"}),(0,l.jsx)(n.td,{children:"\u542f\u7528 Chat Model \u5ba2\u6237\u7aef"}),(0,l.jsx)(n.td,{children:"google-genai"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.api-key"}),(0,l.jsx)(n.td,{children:"Gemini Developer API \u7684 API key\u3002\u63d0\u4f9b\u65f6\uff0c\u5ba2\u6237\u7aef\u4f7f\u7528 Gemini Developer API \u800c\u4e0d\u662f Vertex AI\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.project-id"}),(0,l.jsx)(n.td,{children:"Google Cloud Platform project ID\uff08Vertex AI \u6a21\u5f0f\u5fc5\u9700\uff09"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.location"}),(0,l.jsx)(n.td,{children:"Google Cloud \u533a\u57df\uff08Vertex AI \u6a21\u5f0f\u5fc5\u9700\uff09"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.credentials-uri"}),(0,l.jsxs)(n.td,{children:["Google Cloud credentials \u7684 URI\u3002\u63d0\u4f9b\u65f6\uff0c\u5b83\u7528\u4e8e\u521b\u5efa ",(0,l.jsx)(n.code,{children:"GoogleCredentials"})," \u5b9e\u4f8b\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3002"]}),(0,l.jsx)(n.td,{children:"-"})]})]})]}),"\n",(0,l.jsx)(n.h4,{id:"chat-model-properties",children:"Chat Model Properties"}),"\n",(0,l.jsxs)(n.p,{children:["\u524d\u7f00 ",(0,l.jsx)(n.code,{children:"spring.ai.google.genai.chat"})," \u662f\u7528\u4e8e\u914d\u7f6e Google GenAI Chat \u7684 chat model \u5b9e\u73b0\u7684\u5c5e\u6027\u524d\u7f00\u3002"]}),"\n",(0,l.jsxs)(n.table,{children:[(0,l.jsx)(n.thead,{children:(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.th,{children:"Property"}),(0,l.jsx)(n.th,{children:"Description"}),(0,l.jsx)(n.th,{children:"Default"})]})}),(0,l.jsxs)(n.tbody,{children:[(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.model"}),(0,l.jsxs)(n.td,{children:["\u652f\u6301\u7684 ",(0,l.jsx)(n.a,{href:"https://ai.google.dev/gemini-api/docs/models",children:"Google GenAI Chat models"})," \u5305\u62ec ",(0,l.jsx)(n.code,{children:"gemini-2.0-flash"}),"\u3001",(0,l.jsx)(n.code,{children:"gemini-2.0-flash-lite"}),"\u3001",(0,l.jsx)(n.code,{children:"gemini-pro"})," \u548c ",(0,l.jsx)(n.code,{children:"gemini-1.5-flash"}),"\u3002"]}),(0,l.jsx)(n.td,{children:"gemini-2.0-flash"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.response-mime-type"}),(0,l.jsx)(n.td,{children:"\u751f\u6210\u7684\u5019\u9009\u6587\u672c\u7684\u8f93\u51fa\u54cd\u5e94 mimetype\u3002"}),(0,l.jsxs)(n.td,{children:[(0,l.jsx)(n.code,{children:"text/plain"}),":\uff08\u9ed8\u8ba4\uff09\u6587\u672c\u8f93\u51fa\u6216 ",(0,l.jsx)(n.code,{children:"application/json"}),": JSON \u54cd\u5e94\u3002"]})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.google-search-retrieval"}),(0,l.jsx)(n.td,{children:"\u4f7f\u7528 Google search Grounding \u529f\u80fd"}),(0,l.jsxs)(n.td,{children:[(0,l.jsx)(n.code,{children:"true"})," \u6216 ",(0,l.jsx)(n.code,{children:"false"}),"\uff0c\u9ed8\u8ba4 ",(0,l.jsx)(n.code,{children:"false"}),"\u3002"]})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.temperature"}),(0,l.jsx)(n.td,{children:"\u63a7\u5236\u8f93\u51fa\u7684\u968f\u673a\u6027\u3002\u503c\u53ef\u4ee5\u5728 [0.0,1.0] \u8303\u56f4\u5185\uff08\u5305\u542b\uff09\u3002\u63a5\u8fd1 1.0 \u7684\u503c\u5c06\u4ea7\u751f\u66f4\u591a\u6837\u5316\u7684\u54cd\u5e94\uff0c\u800c\u63a5\u8fd1 0.0 \u7684\u503c\u901a\u5e38\u4f1a\u5bfc\u81f4\u751f\u6210\u5668\u7684\u54cd\u5e94\u4e0d\u90a3\u4e48\u4ee4\u4eba\u60ca\u8bb6\u3002"}),(0,l.jsx)(n.td,{children:"0.7"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.top-k"}),(0,l.jsx)(n.td,{children:"\u91c7\u6837\u65f6\u8981\u8003\u8651\u7684\u6700\u5927 tokens \u6570\u3002\u751f\u6210\u5668\u4f7f\u7528\u7ec4\u5408\u7684 Top-k \u548c nucleus sampling\u3002Top-k sampling \u8003\u8651 topK \u6700\u53ef\u80fd\u7684 tokens \u96c6\u5408\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.top-p"}),(0,l.jsx)(n.td,{children:"\u91c7\u6837\u65f6\u8981\u8003\u8651\u7684\u6700\u5927\u7d2f\u79ef\u6982\u7387\u3002\u751f\u6210\u5668\u4f7f\u7528\u7ec4\u5408\u7684 Top-k \u548c nucleus sampling\u3002Nucleus sampling \u8003\u8651\u6982\u7387\u603b\u548c\u81f3\u5c11\u4e3a topP \u7684\u6700\u5c0f tokens \u96c6\u5408\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.candidate-count"}),(0,l.jsx)(n.td,{children:"\u8981\u8fd4\u56de\u7684\u751f\u6210\u54cd\u5e94\u6d88\u606f\u6570\u3002\u6b64\u503c\u5fc5\u987b\u5728 [1, 8] \u8303\u56f4\u5185\uff08\u5305\u542b\uff09\u3002\u9ed8\u8ba4\u4e3a 1\u3002"}),(0,l.jsx)(n.td,{children:"1"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.max-output-tokens"}),(0,l.jsx)(n.td,{children:"\u8981\u751f\u6210\u7684\u6700\u5927 tokens \u6570\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.frequency-penalty"}),(0,l.jsx)(n.td,{children:"\u7528\u4e8e\u51cf\u5c11\u91cd\u590d\u7684\u9891\u7387\u60e9\u7f5a\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.presence-penalty"}),(0,l.jsx)(n.td,{children:"\u7528\u4e8e\u51cf\u5c11\u91cd\u590d\u7684\u5b58\u5728\u60e9\u7f5a\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.thinking-budget"}),(0,l.jsx)(n.td,{children:"\u601d\u8003\u8fc7\u7a0b\u7684\u601d\u8003\u9884\u7b97\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.tool-names"}),(0,l.jsx)(n.td,{children:"\u6309\u540d\u79f0\u6807\u8bc6\u7684\u5de5\u5177\u5217\u8868\uff0c\u7528\u4e8e\u5728\u5355\u4e2a prompt \u8bf7\u6c42\u4e2d\u542f\u7528 function calling\u3002\u5177\u6709\u8fd9\u4e9b\u540d\u79f0\u7684\u5de5\u5177\u5fc5\u987b\u5b58\u5728\u4e8e ToolCallback \u6ce8\u518c\u8868\u4e2d\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.tool-callbacks"}),(0,l.jsx)(n.td,{children:"\u8981\u6ce8\u518c\u5230 ChatModel \u7684 Tool Callbacks\u3002"}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.internal-tool-execution-enabled"}),(0,l.jsxs)(n.td,{children:["\u5982\u679c\u4e3a true\uff0c\u5e94\u6267\u884c tool execution\uff0c\u5426\u5219\u5c06\u6a21\u578b\u7684\u54cd\u5e94\u8fd4\u56de\u7ed9\u7528\u6237\u3002\u9ed8\u8ba4\u4e3a null\uff0c\u4f46\u5982\u679c\u4e3a null\uff0c\u5c06\u8003\u8651 ",(0,l.jsx)(n.code,{children:"ToolCallingChatOptions.DEFAULT_TOOL_EXECUTION_ENABLED"}),"\uff08\u4e3a true\uff09"]}),(0,l.jsx)(n.td,{children:"-"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:"spring.ai.google.genai.chat.options.safety-settings"}),(0,l.jsxs)(n.td,{children:["\u7528\u4e8e\u63a7\u5236\u5b89\u5168\u8fc7\u6ee4\u5668\u7684\u5b89\u5168\u8bbe\u7f6e\u5217\u8868\uff0c\u5982 ",(0,l.jsx)(n.a,{href:"https://ai.google.dev/gemini-api/docs/safety-settings",children:"Google GenAI Safety Settings"})," \u6240\u5b9a\u4e49\u3002\u6bcf\u4e2a\u5b89\u5168\u8bbe\u7f6e\u53ef\u4ee5\u6709\u4e00\u4e2a method\u3001threshold \u548c category\u3002"]}),(0,l.jsx)(n.td,{children:"-"})]})]})]}),"\n",(0,l.jsxs)(n.blockquote,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"\u63d0\u793a\uff1a"})," \u6240\u6709\u524d\u7f00\u4e3a ",(0,l.jsx)(n.code,{children:"spring.ai.google.genai.chat.options"})," \u7684\u5c5e\u6027\u90fd\u53ef\u4ee5\u901a\u8fc7\u5728 ",(0,l.jsx)(n.code,{children:"Prompt"})," \u8c03\u7528\u4e2d\u6dfb\u52a0\u8bf7\u6c42\u7279\u5b9a\u7684 ",(0,l.jsx)(n.code,{children:"chat-options"})," \u5728\u8fd0\u884c\u65f6\u8986\u76d6\u3002"]}),"\n"]}),"\n",(0,l.jsx)(n.h2,{id:"runtime-options-chat-options",children:"Runtime options [[chat-options]]"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.a,{href:"https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/GoogleGenAiChatOptions.java",children:"GoogleGenAiChatOptions.java"})," \u63d0\u4f9b\u6a21\u578b\u914d\u7f6e\uff0c\u4f8b\u5982 temperature\u3001topK \u7b49\u3002"]}
1),"\n",(0,l.jsxs)(n.p,{children:["\u5728\u542f\u52a8\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 ",(0,l.jsx)(n.code,{children:"GoogleGenAiChatModel(client, options)"})," \u6784\u9020\u51fd\u6570\u6216 ",(0,l.jsx)(n.code,{children:"spring.ai.google.genai.chat.options.*"})," \u5c5e\u6027\u6765\u914d\u7f6e\u9ed8\u8ba4\u9009\u9879\u3002"]}),"\n",(0,l.jsxs)(n.p,{children:["\u5728\u8fd0\u884c\u65f6\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5411 ",(0,l.jsx)(n.code,{children:"Prompt"})," \u8c03\u7528\u6dfb\u52a0\u65b0\u7684\u3001\u8bf7\u6c42\u7279\u5b9a\u7684\u9009\u9879\u6765\u8986\u76d6\u9ed8\u8ba4\u9009\u9879\u3002\n\u4f8b\u5982\uff0c\u8981\u8986\u76d6\u7279\u5b9a\u8bf7\u6c42\u7684\u9ed8\u8ba4 temperature\uff1a"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-java",children:'ChatResponse response = chatModel.call(\n new Prompt(\n "Generate the names of 5 famous pirates.",\n GoogleGenAiChatOptions.builder()\n .temperature(0.4)\n .build()\n ));\n'})}),"\n",(0,l.jsxs)(n.blockquote,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"\u63d0\u793a\uff1a"})," \u9664\u4e86\u6a21\u578b\u7279\u5b9a\u7684 ",(0,l.jsx)(n.code,{children:"GoogleGenAiChatOptions"})," \u4e4b\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u53ef\u79fb\u690d\u7684 ",(0,l.jsx)(n.a,{href:"https://github.com/spring-projects/spring-ai/blob/main/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/ChatOptions.java",children:"ChatOptions"})," \u5b9e\u4f8b\uff0c\u8be5\u5b9e\u4f8b\u4f7f\u7528 ",(0,l.jsx)(n.a,{href:"https://github.com/spring-projects/spring-ai/blob/main/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/DefaultChatOptionsBuilder.java",children:"ChatOptions#builder()"})," \u521b\u5efa\u3002"]}),"\n"]}),"\n",(0,l.jsx)(n.h2,{id:"tool-calling",children:"Tool Calling"}),"\n",(0,l.jsxs)(n.p,{children:["Google GenAI \u6a21\u578b\u652f\u6301 tool calling\uff08function calling\uff09\u529f\u80fd\uff0c\u5141\u8bb8\u6a21\u578b\u5728\u5bf9\u8bdd\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u5de5\u5177\u3002\n\u4ee5\u4e0b\u662f\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\u57fa\u4e8e ",(0,l.jsx)(n.code,{children:"@Tool"})," \u7684\u5de5\u5177\u7684\u793a\u4f8b\uff1a"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-java",children:'\npublic class WeatherService {\n\n @Tool(description = "Get the weather in location")\n public String weatherByLocation(@ToolParam(description= "City or state name") String location) {\n ...\n }\n}\n\nString response = ChatClient.create(this.chatModel)\n .prompt("What\'s the weather like in Boston?")\n .tools(new WeatherService())\n .call()\n .content();\n'})}),"\n",(0,l.jsx)(n.p,{children:"\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528 java.util.function beans \u4f5c\u4e3a\u5de5\u5177\uff1a"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-java",children:'@Bean\n@Description("Get the weather in location. Return temperature in 36\xb0F or 36\xb0C format.")\npublic Function<Request, Response> weatherFunction() {\n return new MockWeatherService();\n}\n\nString response = ChatClient.create(this.chatModel)\n .prompt("What\'s the weather like in Boston?")\n .toolNames("weatherFunction")\n .inputType(Request.class)\n .call()\n .content();\n'})}),"\n",(0,l.jsxs)(n.p,{children:["\u5728 ",(0,l.jsx)(n.a,{href:"../../toolcalls/tool-calls",children:"Tools"})," \u6587\u6863\u4e2d\u67e5\u627e\u66f4\u591a\u4fe1\u606f\u3002"]}),"\n",(0,l.jsx)(n.h2,{id:"multimodal",children:"Multimodal"}),"\n",(0,l.jsxs)(n.p,{children:["Multimodality \u662f\u6307\u6a21\u578b\u540c\u65f6\u7406\u89e3\u548c\u5904\u7406\u6765\u81ea\u5404\u79cd\uff08\u8f93\u5165\uff09\u6765\u6e90\u7684\u4fe1\u606f\u7684\u80fd\u529b\uff0c\u5305\u62ec ",(0,l.jsx)(n.code,{children:"text"}),"\u3001",(0,l.jsx)(n.code,{children:"pdf"}),"\u3001",(0,l.jsx)(n.code,{children:"images"}),"\u3001",(0,l.jsx)(n.code,{children:"audio"})," \u548c\u5176\u4ed6\u6570\u636e\u683c\u5f0f\u3002"]}),"\n",(0,l.jsx)(n.h3,{id:"image-audio-video",children:"Image, Audio, Video"}),"\n",(0,l.jsxs)(n.p,{children:["Google \u7684 Gemini AI \u6a21\u578b\u901a\u8fc7\u7406\u89e3\u548c\u96c6\u62
110\u6587\u672c\u3001\u4ee3\u7801\u3001\u97f3\u9891\u3001\u56fe\u50cf\u548c\u89c6\u9891\u6765\u652f\u6301\u6b64\u529f\u80fd\u3002\n\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u535a\u5ba2\u6587\u7ae0 ",(0,l.jsx)(n.a,{href:"https://blog.google/technology/ai/google-gemini-ai/#introducing-gemini",children:"Introducing Gemini"}),"\u3002"]}),"\n",(0,l.jsxs)(n.p,{children:["Spring AI \u7684 ",(0,l.jsx)(n.code,{children:"Message"})," \u63a5\u53e3\u901a\u8fc7\u5f15\u5165 Media \u7c7b\u578b\u6765\u652f\u6301 multimodal AI \u6a21\u578b\u3002\n\u6b64\u7c7b\u578b\u5305\u542b\u6d88\u606f\u4e2d\u5a92\u4f53\u9644\u4ef6\u7684\u6570\u636e\u548c\u4fe1\u606f\uff0c\u4f7f\u7528 Spring \u7684 ",(0,l.jsx)(n.code,{children:"org.springframework.util.MimeType"})," \u548c ",(0,l.jsx)(n.code,{children:"java.lang.Object"})," \u6765\u5b58\u50a8\u539f\u59cb\u5a92\u4f53\u6570\u636e\u3002"]}),"\n",(0,l.jsxs)(n.p,{children:["\u4ee5\u4e0b\u662f\u4ece ",(0,l.jsx)(n.a,{href:"https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-google-genai/src/test/java/org/springframework/ai/google/genai/GoogleGenAiChatModelIT.java",children:"GoogleGenAiChatModelIT.java"})," \u4e2d\u63d0\u53d6\u7684\u7b80\u5355\u4ee3\u7801\u793a\u4f8b\uff0c\u6f14\u793a\u4e86\u7528\u6237\u6587\u672c\u4e0e\u56fe\u50cf\u7684\u7ec4\u5408\u3002"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-java",children:'byte[] data = new ClassPathResource("/vertex-test.png").getContentAsByteArray();\n\nvar userMessage = UserMessage.builder()\n\t\t\t.text("Explain what do you see o this picture?")\n\t\t\t.media(List.of(new Media(MimeTypeUtils.IMAGE_PNG, data)))\n\t\t\t.build();\n\nChatResponse response = chatModel.call(new Prompt(List.of(this.userMessage)));\n'})}),"\n",(0,l.jsx)(n.h3,{id:"pdf",children:"PDF"}),"\n",(0,l.jsxs)(n.p,{children:["Google GenAI \u63d0\u4f9b\u5bf9 PDF \u8f93\u5165\u7c7b\u578b\u7684\u652f\u6301\u3002\n\u4f7f\u7528 ",(0,l.jsx)(n.code,{children:"application/pdf"})," \u5a92\u4f53\u7c7b\u578b\u5c06 PDF \u6587\u4ef6\u9644\u52a0\u5230\u6d88\u606f\uff1a"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-java",children:'var pdfData = new ClassPathResource("/spring-ai-reference-overview.pdf");\n\nvar userMessage = UserMessage.builder()\n\t\t\t.text("You are a very professional document summarization specialist. Please summarize the given document.")\n\t\t\t.media(List.of(new Media(new MimeType("application", "pdf"), pdfData)))\n\t\t\t.build();\n\nvar response = this.chatModel.call(new Prompt(List.of(userMessage)));\n'})}),"\n",(0,l.jsx)(n.h2,{id:"sample-controller",children:"Sample Controller"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.a,{href:"https://start.spring.io/",children:"Create"})," \u4e00\u4e2a\u65b0\u7684 Spring Boot \u9879\u76ee\uff0c\u5e76\u5c06 ",(0,l.jsx)(n.code,{children:"spring-ai-starter-model-google-genai"})," \u6dfb\u52a0\u5230\u60a8\u7684 pom\uff08\u6216 gradle\uff09\u4f9d\u8d56\u9879\u4e2d\u3002"]}),"\n",(0,l.jsxs)(n.p,{children:["\u5728 ",(0,l.jsx)(n.code,{children:"src/main/resources"})," \u76ee\u5f55\u4e0b\u6dfb\u52a0\u4e00\u4e2a ",(0,l.jsx)(n.code,{children:"application.properties"})," \u6587\u4ef6\uff0c\u4ee5\u542f\u7528\u548c\u914d\u7f6e Google GenAI chat model\uff1a"]}),"\n",(0,l.jsx)(n.h3,{id:"using-gemini-developer-api-api-key",children:"Using Gemini Developer API (API Key)"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-properties",children:"spring.ai.google.genai.api-key=YOUR_API_KEY\nspring.ai.google.genai.chat.options.model=gemini-2.0-flash\nspring.ai.google.genai.chat.options.temperature=0.5\n"})}),"\n",(0,l.jsx)(n.h3,{id:"using-vertex-ai",children:"Using Vertex AI"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-properties",children:"spring.ai.google.genai.project-id=PROJECT_ID\nspring.ai.google.genai.location=LOCATION\nspring.ai.google.genai.chat.options.model=gemini-2.0-flash\nspring.ai.google.genai.chat.options.temperature=0.5\n"})}),"\n",(0,l.jsxs)(n.blockquote,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"\u63d0\u793a\uff1a"})," \u5c06 ",(0,l.jsx)(n.code,{children:"project-id"})," \u66ff\u6362\u4e3a\u60a8\u7684 Google Cloud Project ID\uff0c",(0,l.jsx)(n.code,{children:"location"})," \u662f Google Cloud Region\uff0c\u5982 ",(0,l.jsx)(n.code,{children:"us-central1"}),"\u3001",(0,l.jsx)(n.code,{children:"europe-west1"})," \u7b49..."]}),"\n"]}),"\n",(0,l.jsxs)(n.blockquote,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"\u6ce8\u610f\uff1a"}),"\n\u6bcf\u4e2a\u6a21\u578b\u90fd\u6709\u81ea\u5df1\u652f\u6301\u7684\u533a\u57df\u96c6\uff0c\u60a8\u53ef\u4ee5\u5728\u6a21\u578b\u9875\u9762\u627e\u5230\u652f\u6301\u7684\u533a\u57df\u5217\u8868\u3002\n\u4f8b\u5982\uff0cmodel=",(0,l.jsx)(n.code,{children:"gemini-2.5-flash"})," \u76ee\u524d\u4ec5\u5728 ",(0,l.jsx)(n.code,{children:"us-central1"})," \u533a\u57df\u53ef\u7528\uff0c\u60a8\u5fc5\u987b\u8bbe\u7f6e location=",(0,l.jsx)(n.code,{children:"us-central1"}),"\uff0c\u9075\u5faa\u6a21\u578b\u9875\u9762 ",(0,l.jsx)(n.a,{href:"https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini/2-5-flash",children:"Gemini 2.5 Flash - Supported Regions"}),"\u3002"]}),"\n"]}),"\n",(0,l.jsxs)(n.p,{children:["\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a ",(0,l.jsx)(n.code,{children:"GoogleGenAiChatModel"})," \u5b9e\u73b0\uff0c\u60a8\u53ef\u4ee5\u5c06\u5176\u6ce8\u5165\u5230\u60a8\u7684\u7c7b\u4e2d\u3002\n\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 ",(0,l.jsx)(n.code,{children:"@Controller"})," \u7c7b\u7684\u793a\u4f8b\uff0c\u5b83\u4f7f\u7528 chat model \u8fdb\u884c\u6587\u672c\u751f\u6210\u3002"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-java",children:'@RestController\npublic class ChatController {\n\n private final GoogleGenAiChatModel chatModel;\n\n @Autowired\n public ChatController(GoogleGenAiChatModel chatModel) {\n this.chatModel = chatModel;\n }\n\n @GetMapping("/ai/generate")\n public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {\n return Map.of("generation", this.chatModel.call(message));\n }\n\n @GetMapping("/ai/generateStream")\n\tpublic Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {\n Prompt prompt = new Prompt(new UserMessage(message));\n return this.chatModel.stream(prompt);\n }\n}\n'})}),"\n",(0,l.jsx)(n.h2,{id:"manual-configuration",children:"Manual Configuration"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.a,{href:"https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/GoogleGenAiChatModel.java",children:"GoogleGenAiChatModel"})," \u5b9e\u73b0\u4e86 ",(0,l.jsx)(n.code,{children:"ChatModel"})," \u5e76\u4f7f\u7528 ",(0,l.jsx)(n.code,{children:"com.google.genai.Client"}
1)," \u8fde\u63a5\u5230 Google GenAI \u670d\u52a1\u3002"]}),"\n",(0,l.jsxs)(n.p,{children:["\u5c06 ",(0,l.jsx)(n.code,{children:"spring-ai-google-genai"})," \u4f9d\u8d56\u9879\u6dfb\u52a0\u5230\u9879\u76ee\u7684 Maven ",(0,l.jsx)(n.code,{children:"pom.xml"})," \u6587\u4ef6\u4e2d\uff1a"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-xml",children:"<dependency>\n <groupId>org.springframework.ai</groupId>\n <artifactId>spring-ai-google-genai</artifactId>\n</dependency>\n"})}),"\n",(0,l.jsxs)(n.p,{children:["\u6216\u6dfb\u52a0\u5230\u60a8\u7684 Gradle ",(0,l.jsx)(n.code,{children:"build.gradle"})," \u6784\u5efa\u6587\u4ef6\u4e2d\u3002"]}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-groovy",children:"dependencies {\n implementation 'org.springframework.ai:spring-ai-google-genai'\n}\n"})}),"\n",(0,l.jsxs)(n.blockquote,{children:["\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"\u63d0\u793a\uff1a"})," \u8bf7\u53c2\u9605 ",(0,l.jsx)(n.a,{href:"https://docs.spring.io/spring-ai/reference/getting-started.html#dependency-management",children:"Dependency Management"})," \u90e8\u5206\uff0c\u5c06 Spring AI BOM \u6dfb\u52a0\u5230\u60a8\u7684\u6784\u5efa\u6587\u4ef6\u4e2d\u3002"]}),"\n"]}),"\n",(0,l.jsxs)(n.p,{children:["\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a ",(0,l.jsx)(n.code,{children:"GoogleGenAiChatModel"})," \u5e76\u5c06\u5176\u7528\u4e8e\u6587\u672c\u751f\u6210\uff1a"]}),"\n",(0,l.jsx)(n.h3,{id:"using-api-key",children:"Using API Key"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-java",children:'Client genAiClient = Client.builder()\n .apiKey(System.getenv("GOOGLE_API_KEY"))\n .build();\n\nvar chatModel = new GoogleGenAiChatModel(genAiClient,\n GoogleGenAiChatOptions.builder()\n .model(ChatModel.GEMINI_2_0_FLASH)\n .temperature(0.4)\n .build());\n\nChatResponse response = this.chatModel.call(\n new Prompt("Generate the names of 5 famous pirates."));\n'})}),"\n",(0,l.jsx)(n.h3,{id:"using-vertex-ai-1",children:"Using Vertex AI"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-java",children:'Client genAiClient = Client.builder()\n .project(System.getenv("GOOGLE_CLOUD_PROJECT"))\n .location(System.getenv("GOOGLE_CLOUD_LOCATION"))\n .vertexAI(true)\n .build();\n\nvar chatModel = new GoogleGenAiChatModel(genAiClient,\n GoogleGenAiChatOptions.builder()\n .model(ChatModel.GEMINI_2_0_FLASH)\n .temperature(0.4)\n .build());\n\nChatResponse response = this.chatModel.call(\n new Prompt("Generate the names of 5 famous pirates."));\n'})}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"GoogleGenAiChatOptions"})," \u63d0\u4f9b chat \u8bf7\u6c42\u7684\u914d\u7f6e\u4fe1\u606f\u3002\n",(0,l.jsx)(n.code,{children:"GoogleGenAiChatOptions.Builder"})," \u662f\u4e00\u4e2a\u6d41\u7545\u7684\u9009\u9879\u6784\u5efa\u5668\u3002"]}),"\n",(0,l.jsx)(n.h2,{id:"migration-from-vertex-ai-gemini",children:"Migration from Vertex AI Gemini"}),"\n",(0,l.jsxs)(n.p,{children:["\u5982\u679c\u60a8\u5f53\u524d\u4f7f\u7528 Vertex AI Gemini \u5b9e\u73b0\uff08",(0,l.jsx)(n.code,{children:"spring-ai-vertex-ai-gemini"}),"\uff09\uff0c\u60a8\u53ef\u4ee5\u4ee5\u6700\u5c11\u7684\u66f4\u6539\u8fc1\u79fb\u5230 Google GenAI\uff1a"]}),"\n",(0,l.jsx)(n.h3,{id:"key-differences",children:"Key Differences"}),"\n",(0,l.jsxs)(n.ol,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:"SDK"}),": Google GenAI \u4f7f\u7528\u65b0\u7684 ",(0,l.jsx)(n.code,{children:"com.google.genai.Client"})," \u800c\u4e0d\u662f ",(0,l.jsx)(n.code,{children:"com.google.cloud.vertexai.VertexAI"})]}),"\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:"Authentication"}),": \u652f\u6301 API key \u548c Google Cloud credentials"]}),"\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:"Package Names"}),": \u7c7b\u5728 ",(0,l.jsx)(n.code,{children:"org.springframework.ai.google.genai"})," \u4e2d\uff0c\u800c\u4e0d\u662f ",(0,l.jsx)(n.code,{children:"org.springframework.ai.vertexai.gemini"})]}),"\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:"Property Prefix"}),": \u4f7f\u7528 ",(0,l.jsx)(n.code,{children:"spring.ai.google.genai"})," \u800c\u4e0d\u662f ",(0,l.jsx)(n.code,{children:"spring.ai.vertex.ai.gemini"})]}),"\n"]}),"\n",(0,l.jsx)(n.h3,{id:"when-to-use-google-genai-vs-vertex-ai-gemini",children:"When to Use Google GenAI vs Vertex AI Gemini"}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u4f7f\u7528 Google GenAI\uff1a"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:"\u60a8\u60f3\u4f7f\u7528 API keys \u8fdb\u884c\u5feb\u901f\u539f\u578b\u8bbe\u8ba1"}),"\n",(0,l.jsx)(n.li,{children:"\u60a8\u9700\u8981\u6765\u81ea Developer API \u7684\u6700\u65b0 Gemini \u529f\u80fd"}),"\n",(0,l.jsx)(n.li,{children:"\u60a8\u5e0c\u671b\u5728 API key \u548c Vertex AI \u6a21\u5f0f\u4e4b\u95f4\u7075\u6d3b\u5207\u6362"}),"\n"]}),"\n",(0,l.jsx)(n.p,{children:(0,l.jsx)(n.strong,{children:"\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u4f7f\u7528 Vertex AI Gemini\uff1a"})}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:"\u60a8\u6709\u73b0\u6709\u7684 Vertex AI \u57fa\u7840\u8bbe\u65bd"}),"\n",(0,l.jsx)(n.li,{children:"\u60a8\u9700\u8981\u7279\u5b9a\u7684 Vertex AI \u4f01\u4e1a\u529f\u80fd"}),"\n",(0,l.jsx)(n.li,{children:"\u60a8\u7684\u7ec4\u7ec7\u8981\u6c42\u4ec5 Google Cloud \u90e8\u7f72"}),"\n"]}),"\n",(0,l.jsx)(n.h2,{id:"low-level-java-client-low-level-api",children:"Low-level Java Client [[low-level-api]]"}),"\n",(0,l.jsx)(n.p,{children:"Google GenAI \u5b9e\u73b0\u57fa\u4e8e\u65b0\u7684 Google GenAI Java SDK \u6784\u5efa\uff0c\u8be5 SDK \u63d0\u4f9b\u4e86\u7528\u4e8e\u8bbf\u95ee Gemini \u
16a21\u578b\u7684\u73b0\u4ee3\u3001\u7b80\u5316\u7684 API\u3002"})]})}function h(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,l.jsx)(n,{...e,children:(0,l.jsx)(c,{...e})}):c(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.