类 GeminiChatModel.Builder
- 封闭类:
GeminiChatModel
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明Sets the API key (for Gemini API).Sets the custom base URL (for Gemini API).build()Builds the GeminiChatModel instance.clientOptions(com.google.genai.types.ClientOptions clientOptions) Sets the client options.credentials(com.google.auth.oauth2.GoogleCredentials credentials) Sets the Google credentials (for Vertex AI).defaultOptions(GenerateOptions defaultOptions) Sets the default generation options.formatter(Formatter<com.google.genai.types.Content, com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder> formatter) Sets the formatter.httpOptions(com.google.genai.types.HttpOptions httpOptions) Sets the HTTP options for the client.Sets the Google Cloud location (for Vertex AI).Sets the model name.Sets the Google Cloud project ID (for Vertex AI).proxy(ProxyConfig proxyConfig) Sets the proxy configuration for HTTP traffic.streamEnabled(boolean streamEnabled) Sets whether streaming is enabled.vertexAI(boolean vertexAI) Sets whether to use Vertex AI APIs.
-
构造器详细资料
-
Builder
public Builder()
-
-
方法详细资料
-
apiKey
Sets the API key (for Gemini API).- 参数:
apiKey- the Gemini API key- 返回:
- this builder
-
baseUrl
Sets the custom base URL (for Gemini API).- 参数:
baseUrl- the custom Gemini API base URL- 返回:
- this builder
-
modelName
Sets the model name.- 参数:
modelName- the model name (default: "gemini-2.5-flash")- 返回:
- this builder
-
streamEnabled
Sets whether streaming is enabled.- 参数:
streamEnabled- true to enable streaming (default: false)- 返回:
- this builder
-
project
Sets the Google Cloud project ID (for Vertex AI).- 参数:
project- the project ID- 返回:
- this builder
-
location
Sets the Google Cloud location (for Vertex AI).- 参数:
location- the location (e.g., "us-central1")- 返回:
- this builder
-
vertexAI
Sets whether to use Vertex AI APIs.- 参数:
vertexAI- true to use Vertex AI, false for Gemini API- 返回:
- this builder
-
httpOptions
Sets the HTTP options for the client.- 参数:
httpOptions- the HTTP options- 返回:
- this builder
-
credentials
Sets the Google credentials (for Vertex AI).- 参数:
credentials- the Google credentials- 返回:
- this builder
-
clientOptions
Sets the client options.- 参数:
clientOptions- the client options- 返回:
- this builder
-
defaultOptions
Sets the default generation options.- 参数:
defaultOptions- the default options- 返回:
- this builder
-
formatter
public GeminiChatModel.Builder formatter(Formatter<com.google.genai.types.Content, com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder> formatter) Sets the formatter.- 参数:
formatter- the formatter to use- 返回:
- this builder
-
proxy
Sets the proxy configuration for HTTP traffic.Interaction with
clientOptions(ClientOptions): This method performs a smart merge rather than simple overwriting. The finalClientOptionspassed to the Google SDK client is determined as follows:- If only
proxy()is called: a newClientOptionsis created containing only the proxy settings. - If only
clientOptions()is called: the provided options are used as-is. - If both are called:
- If the provided
ClientOptionsdoes not already contain proxy settings (clientOptions.getProxyOptions().isEmpty()), the proxy fromproxy()is merged into the existing options (preserving connection pool, etc.). - If the provided
ClientOptionsalready contains proxy settings, those take precedence. A warning is logged, and theproxy()setting is silently ignored to avoid conflicting configurations.
- If the provided
- If neither is called: no proxy configuration is applied.
Note: The
nonProxyHostsfield fromProxyConfigis not supported by the Google GenAI SDK. When converting, this field will be lost. If host exclusion is required, consider settinghttp.nonProxyHostsas a JVM system property.- 参数:
proxyConfig- the proxy configuration (seeProxyConfig)- 返回:
- this builder
- If only
-
build
Builds the GeminiChatModel instance.Proxy smart merge: If both
proxy(ProxyConfig)andclientOptions(ClientOptions)are set, this method performs a smart merge: if the providedClientOptionsdoes not already contain proxy settings, the proxy fromproxy()is merged into it (preserving connection pool, etc.). IfClientOptionsalready has proxy configured, it takes precedence and a warning is logged.- 返回:
- a new GeminiChatModel
-