Class GeminiChatModel.Builder
- Enclosing class:
- GeminiChatModel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the API key (for Gemini API).Sets the custom base URL (for Gemini API).build()clientOptions(com.google.genai.types.ClientOptions clientOptions) Sets the client options.contextWindowSize(int contextWindowSize) Builds the GeminiChatModel instance.credentials(com.google.auth.oauth2.GoogleCredentials credentials) Sets the Google credentials (for Vertex AI).defaultOptions(io.agentscope.core.model.GenerateOptions defaultOptions) Sets the default generation options.formatter(io.agentscope.core.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(io.agentscope.core.model.transport.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.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
apiKey
Sets the API key (for Gemini API).- Parameters:
apiKey- the Gemini API key- Returns:
- this builder
-
baseUrl
Sets the custom base URL (for Gemini API).- Parameters:
baseUrl- the custom Gemini API base URL- Returns:
- this builder
-
modelName
Sets the model name.- Parameters:
modelName- the model name (default: "gemini-2.5-flash")- Returns:
- this builder
-
streamEnabled
Sets whether streaming is enabled.- Parameters:
streamEnabled- true to enable streaming (default: false)- Returns:
- this builder
-
project
Sets the Google Cloud project ID (for Vertex AI).- Parameters:
project- the project ID- Returns:
- this builder
-
location
Sets the Google Cloud location (for Vertex AI).- Parameters:
location- the location (e.g., "us-central1")- Returns:
- this builder
-
vertexAI
Sets whether to use Vertex AI APIs.- Parameters:
vertexAI- true to use Vertex AI, false for Gemini API- Returns:
- this builder
-
httpOptions
Sets the HTTP options for the client.- Parameters:
httpOptions- the HTTP options- Returns:
- this builder
-
credentials
Sets the Google credentials (for Vertex AI).- Parameters:
credentials- the Google credentials- Returns:
- this builder
-
clientOptions
Sets the client options.- Parameters:
clientOptions- the client options- Returns:
- this builder
-
defaultOptions
public GeminiChatModel.Builder defaultOptions(io.agentscope.core.model.GenerateOptions defaultOptions) Sets the default generation options.- Parameters:
defaultOptions- the default options- Returns:
- this builder
-
formatter
public GeminiChatModel.Builder formatter(io.agentscope.core.formatter.Formatter<com.google.genai.types.Content, com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder> formatter) Sets the formatter.- Parameters:
formatter- the formatter to use- Returns:
- 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.- Parameters:
proxyConfig- the proxy configuration (seeProxyConfig)- Returns:
- this builder
- If only
-
contextWindowSize
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.- Returns:
- a new GeminiChatModel
-
build
-