类 GenerateOptions.Builder

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

public static class GenerateOptions.Builder extends Object
  • 构造器详细资料

    • Builder

      public Builder()
  • 方法详细资料

    • apiKey

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

      public GenerateOptions.Builder baseUrl(String baseUrl)
      Sets the base URL for the API endpoint.
      参数:
      baseUrl - the base URL
      返回:
      this builder instance
    • endpointPath

      public GenerateOptions.Builder endpointPath(String endpointPath)
      Sets the 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
    • modelName

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

      public GenerateOptions.Builder stream(Boolean stream)
      Sets whether streaming mode is enabled.
      参数:
      stream - true for streaming, false for non-streaming
      返回:
      this builder instance
    • temperature

      public GenerateOptions.Builder temperature(Double temperature)
      Sets the temperature for text generation.

      Higher values (e.g., 0.8) make output more random, while lower values (e.g., 0.2) make it more focused and deterministic.

      参数:
      temperature - the temperature value between 0 and 2
      返回:
      this builder instance
    • topP

      public GenerateOptions.Builder topP(Double topP)
      Sets the top-p (nucleus sampling) parameter.

      Controls diversity via nucleus sampling: considers the smallest set of tokens whose cumulative probability exceeds the top_p value.

      参数:
      topP - the top-p value between 0 and 1
      返回:
      this builder instance
    • maxTokens

      public GenerateOptions.Builder maxTokens(Integer maxTokens)
      Sets the maximum number of tokens to generate.
      参数:
      maxTokens - the maximum tokens limit
      返回:
      this builder instance
    • maxCompletionTokens

      public GenerateOptions.Builder maxCompletionTokens(Integer maxCompletionTokens)
      Sets the maximum number of completion tokens to generate.

      This is an alternative to maxTokens(Integer) for OpenAI-compatible APIs that support max_completion_tokens. This builder does not enforce exclusivity with maxTokens; both may be set and will be forwarded as-is by formatters that support both fields.

      参数:
      maxCompletionTokens - the maximum completion tokens limit
      返回:
      this builder instance
    • frequencyPenalty

      public GenerateOptions.Builder frequencyPenalty(Double frequencyPenalty)
      Sets the frequency penalty.

      Reduces repetition by penalizing tokens based on their frequency in the text so far. Higher values decrease repetition more strongly.

      参数:
      frequencyPenalty - the frequency penalty between -2 and 2
      返回:
      this builder instance
    • presencePenalty

      public GenerateOptions.Builder presencePenalty(Double presencePenalty)
      Sets the presence penalty.

      Reduces repetition by penalizing tokens that have already appeared in the text. Higher values decrease repetition more strongly.

      参数:
      presencePenalty - the presence penalty between -2 and 2
      返回:
      this builder instance
    • thinkingBudget

      public GenerateOptions.Builder thinkingBudget(Integer thinkingBudget)
      Sets the thinking budget (maximum tokens for reasoning/thinking content).

      This parameter is specific to models that support thinking mode. When set, the model will show its reasoning process before generating the final answer. Setting this parameter may automatically enable thinking mode in some models.

      参数:
      thinkingBudget - the maximum tokens for thinking content
      返回:
      this builder
    • reasoningEffort

      public GenerateOptions.Builder reasoningEffort(String reasoningEffort)
      Sets the reasoning effort level for o1 models.

      This parameter controls how much effort the model spends on reasoning. Valid values are "low", "medium", and "high".

      参数:
      reasoningEffort - the reasoning effort level
      返回:
      this builder
    • executionConfig

      public GenerateOptions.Builder executionConfig(ExecutionConfig executionConfig)
      Sets the execution configuration for timeout and retry behavior.

      When configured, model API calls will apply timeout and retry logic according to the execution config (timeout duration, max attempts, backoff, error filtering).

      参数:
      executionConfig - the execution configuration, or null to disable
      返回:
      this builder instance
    • toolChoice

      public GenerateOptions.Builder toolChoice(ToolChoice toolChoice)
      Sets the tool choice configuration for controlling how the model uses tools.

      This setting controls whether the model can call tools, must call tools, or must call a specific tool:

      参数:
      toolChoice - the tool choice configuration, or null for default (auto)
      返回:
      this builder instance
      另请参阅:
    • topK

      public GenerateOptions.Builder topK(Integer topK)
      Sets the top-k sampling parameter.

      Limits the model to only consider the top K most probable tokens at each step. Lower values make output more focused, higher values allow more diversity.

      参数:
      topK - the top-k value
      返回:
      this builder instance
    • seed

      public GenerateOptions.Builder seed(Long seed)
      Sets the random seed for deterministic generation.

      When set, the model will attempt to generate the same output for the same input and seed value, enabling reproducible results.

      参数:
      seed - the seed value
      返回:
      this builder instance
    • cacheControl

      public GenerateOptions.Builder cacheControl(Boolean cacheControl)
      Sets whether cache control is enabled for prompt caching.

      When true, the formatter will automatically add cache_control: {"type": "ephemeral"} to system messages and the last message in the request.

      参数:
      cacheControl - true to enable cache control, false to disable
      返回:
      this builder instance
    • additionalHeader

      public GenerateOptions.Builder additionalHeader(String key, String value)
      Adds an additional HTTP header to include in API requests.
      参数:
      key - the header name
      value - the header value
      返回:
      this builder instance
    • additionalHeaders

      public GenerateOptions.Builder additionalHeaders(Map<String,String> headers)
      Sets all additional HTTP headers to include in API requests.
      参数:
      headers - the headers map
      返回:
      this builder instance
    • additionalBodyParam

      public GenerateOptions.Builder additionalBodyParam(String key, Object value)
      Adds an additional parameter to include in the request body.
      参数:
      key - the parameter name
      value - the parameter value
      返回:
      this builder instance
    • additionalBodyParams

      public GenerateOptions.Builder additionalBodyParams(Map<String,Object> params)
      Sets all additional parameters to include in the request body.
      参数:
      params - the parameters map
      返回:
      this builder instance
    • additionalQueryParam

      public GenerateOptions.Builder additionalQueryParam(String key, String value)
      Adds an additional query parameter to include in API requests.
      参数:
      key - the parameter name
      value - the parameter value
      返回:
      this builder instance
    • additionalQueryParams

      public GenerateOptions.Builder additionalQueryParams(Map<String,String> params)
      Sets all additional query parameters to include in API requests.
      参数:
      params - the parameters map
      返回:
      this builder instance
    • build

      public GenerateOptions build()
      Builds a new GenerateOptions instance with the set values.
      返回:
      a new GenerateOptions instance