类 OpenAIChatModel.Builder

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

public static class OpenAIChatModel.Builder extends Object
Builder for OpenAIChatModel.

The built model internally wraps the configuration so that calls without explicit options use the builder-provided values.

  • 构造器详细资料

    • Builder

      public Builder()
  • 方法详细资料

    • apiKey

      public OpenAIChatModel.Builder apiKey(String apiKey)
      Sets the API key for OpenAI authentication.
      参数:
      apiKey - the API key
      返回:
      this builder instance
    • modelName

      public OpenAIChatModel.Builder modelName(String modelName)
      Sets the model name to use.
      参数:
      modelName - the model name (e.g., "gpt-4", "gpt-3.5-turbo")
      返回:
      this builder instance
    • stream

      public OpenAIChatModel.Builder stream(boolean stream)
      Sets whether streaming should be enabled.
      参数:
      stream - true to enable streaming, false for non-streaming
      返回:
      this builder instance
    • generateOptions

      public OpenAIChatModel.Builder generateOptions(GenerateOptions options)
      Sets the default generation options.
      参数:
      options - the default options to use (null for defaults)
      返回:
      this builder instance
    • baseUrl

      public OpenAIChatModel.Builder baseUrl(String baseUrl)
      Sets a custom base URL for OpenAI API.
      参数:
      baseUrl - the base URL (null for default)
      返回:
      this builder instance
    • endpointPath

      public OpenAIChatModel.Builder endpointPath(String endpointPath)
      Sets a custom endpoint path for the API request.

      This allows customization for OpenAI-compatible APIs that use different endpoint paths than the standard OpenAI API (e.g., "/v4/chat/completions", "/api/v1/llm/chat", etc.). When null, the default endpoint path will be used.

      参数:
      endpointPath - the endpoint path (e.g., "/v1/chat/completions")
      返回:
      this builder instance
    • formatter

      Sets the message formatter to use.

      Use provider-specific formatters for different providers:

      参数:
      formatter - the formatter (null for default OpenAI formatter)
      返回:
      this builder instance
    • httpTransport

      public OpenAIChatModel.Builder httpTransport(HttpTransport httpTransport)
      Sets the HTTP transport to use.

      Note on proxy configuration: Because httpTransport is a fully-constructed HTTP client instance, its configuration (including proxy) cannot be modified after creation. If you need to configure a proxy, either:

      • Use proxy(ProxyConfig) without calling httpTransport(), for simple proxy-only customization.
      • Configure the proxy directly within the transport's HttpTransportConfig when building the transport instance.

      If both httpTransport() and proxy() are called, httpTransport() takes full precedence and proxy() is ignored (a warning is logged at build time).

      参数:
      httpTransport - the HTTP transport (null for default from factory)
      返回:
      this builder instance
    • proxy

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

      Interaction with httpTransport(HttpTransport): Because httpTransport is a fully-constructed HTTP client instance, its configuration cannot be modified after creation. The final transport is determined as follows:

      • If only proxy() is called: the default OkHttpTransport is used with the specified proxy configuration applied.
      • If only httpTransport() is called: the provided transport is used as-is (proxy must be configured within the transport's own HttpTransportConfig).
      • If both are called: httpTransport() takes full precedence. The proxy() setting is ignored and a warning is logged. To configure proxy with a custom transport, set it within the transport's HttpTransportConfig directly.
      • If neither is called: the default transport from HttpTransportFactory is used (no proxy).
      参数:
      proxyConfig - the proxy configuration (see ProxyConfig)
      返回:
      this builder instance
    • build

      public OpenAIChatModel build()
      Builds the OpenAIChatModel instance.
      返回:
      configured OpenAIChatModel instance
      抛出:
      IllegalArgumentException - if modelName is not set