类 GeminiChatModel.Builder

java.lang.Object
io.agentscope.core.model.GeminiChatModel.Builder
封闭类:
GeminiChatModel

public static class GeminiChatModel.Builder extends Object
Builder for creating GeminiChatModel instances.
  • 构造器详细资料

    • Builder

      public Builder()
  • 方法详细资料

    • apiKey

      public GeminiChatModel.Builder apiKey(String apiKey)
      Sets the API key (for Gemini API).
      参数:
      apiKey - the Gemini API key
      返回:
      this builder
    • baseUrl

      public GeminiChatModel.Builder baseUrl(String baseUrl)
      Sets the custom base URL (for Gemini API).
      参数:
      baseUrl - the custom Gemini API base URL
      返回:
      this builder
    • modelName

      public GeminiChatModel.Builder modelName(String modelName)
      Sets the model name.
      参数:
      modelName - the model name (default: "gemini-2.5-flash")
      返回:
      this builder
    • streamEnabled

      public GeminiChatModel.Builder streamEnabled(boolean streamEnabled)
      Sets whether streaming is enabled.
      参数:
      streamEnabled - true to enable streaming (default: false)
      返回:
      this builder
    • project

      public GeminiChatModel.Builder project(String project)
      Sets the Google Cloud project ID (for Vertex AI).
      参数:
      project - the project ID
      返回:
      this builder
    • location

      public GeminiChatModel.Builder location(String location)
      Sets the Google Cloud location (for Vertex AI).
      参数:
      location - the location (e.g., "us-central1")
      返回:
      this builder
    • vertexAI

      public GeminiChatModel.Builder vertexAI(boolean vertexAI)
      Sets whether to use Vertex AI APIs.
      参数:
      vertexAI - true to use Vertex AI, false for Gemini API
      返回:
      this builder
    • httpOptions

      public GeminiChatModel.Builder httpOptions(com.google.genai.types.HttpOptions httpOptions)
      Sets the HTTP options for the client.
      参数:
      httpOptions - the HTTP options
      返回:
      this builder
    • credentials

      public GeminiChatModel.Builder credentials(com.google.auth.oauth2.GoogleCredentials credentials)
      Sets the Google credentials (for Vertex AI).
      参数:
      credentials - the Google credentials
      返回:
      this builder
    • clientOptions

      public GeminiChatModel.Builder clientOptions(com.google.genai.types.ClientOptions clientOptions)
      Sets the client options.
      参数:
      clientOptions - the client options
      返回:
      this builder
    • defaultOptions

      public GeminiChatModel.Builder defaultOptions(GenerateOptions 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

      public GeminiChatModel.Builder proxy(ProxyConfig proxyConfig)
      Sets the proxy configuration for HTTP traffic.

      Interaction with clientOptions(ClientOptions): This method performs a smart merge rather than simple overwriting. The final ClientOptions passed to the Google SDK client is determined as follows:

      • If only proxy() is called: a new ClientOptions is 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 ClientOptions does not already contain proxy settings (clientOptions.getProxyOptions().isEmpty()), the proxy from proxy() is merged into the existing options (preserving connection pool, etc.).
        • If the provided ClientOptions already contains proxy settings, those take precedence. A warning is logged, and the proxy() setting is silently ignored to avoid conflicting configurations.
      • If neither is called: no proxy configuration is applied.

      Note: The nonProxyHosts field from ProxyConfig is not supported by the Google GenAI SDK. When converting, this field will be lost. If host exclusion is required, consider setting http.nonProxyHosts as a JVM system property.

      参数:
      proxyConfig - the proxy configuration (see ProxyConfig)
      返回:
      this builder
    • build

      public GeminiChatModel build()
      Builds the GeminiChatModel instance.

      Proxy smart merge: If both proxy(ProxyConfig) and clientOptions(ClientOptions) are set, this method performs a smart merge: if the provided ClientOptions does not already contain proxy settings, the proxy from proxy() is merged into it (preserving connection pool, etc.). If ClientOptions already has proxy configured, it takes precedence and a warning is logged.

      返回:
      a new GeminiChatModel