类 OpenAIBaseFormatter

所有已实现的接口:
Formatter<OpenAIMessage,OpenAIResponse,OpenAIRequest>
直接已知子类:
OpenAIChatFormatter

public abstract class OpenAIBaseFormatter extends AbstractBaseFormatter<OpenAIMessage,OpenAIResponse,OpenAIRequest>
Base formatter for OpenAI Chat Completion HTTP API. Provides common functionality for both single-agent and multi-agent formatters.

Subclasses must implement:

  • 字段详细资料

  • 构造器详细资料

    • OpenAIBaseFormatter

      protected OpenAIBaseFormatter()
  • 方法详细资料

    • parseResponse

      public ChatResponse parseResponse(OpenAIResponse response, Instant startTime)
      从接口复制的说明: Formatter
      Parse provider-specific response to AgentScope ChatResponse.
      参数:
      response - Provider-specific response object
      startTime - Request start time for calculating duration
      返回:
      AgentScope ChatResponse
    • applyOptions

      public abstract void applyOptions(OpenAIRequest request, GenerateOptions options, GenerateOptions defaultOptions)
      Apply generation options to the request. Subclasses implement provider-specific option handling.
      参数:
      request - OpenAI request DTO
      options - Generation options to apply
      defaultOptions - Default options to use if options parameter is null
    • applyTools

      public abstract void applyTools(OpenAIRequest request, List<ToolSchema> tools)
      Apply tool schemas to the request. Subclasses implement provider-specific tool handling.
      参数:
      request - OpenAI request DTO
      tools - List of tool schemas to apply (may be null or empty)
    • applyToolChoice

      public abstract void applyToolChoice(OpenAIRequest request, ToolChoice toolChoice)
      Apply tool choice configuration to the request. Subclasses implement provider-specific tool choice handling.
      参数:
      request - OpenAI request DTO
      toolChoice - Tool choice configuration (null means auto)
    • applyTools

      public void applyTools(OpenAIRequest request, List<ToolSchema> tools, String baseUrl, String modelName)
      Apply tool schemas with provider context. Default implementation delegates to applyTools(OpenAIRequest, List).
      参数:
      request - OpenAI request DTO
      tools - Tool schemas to apply
      baseUrl - API base URL (ignored by default)
      modelName - Model name (ignored by default)
    • applyToolChoice

      public void applyToolChoice(OpenAIRequest request, ToolChoice toolChoice, String baseUrl, String modelName)
      Apply tool choice with provider context. Default implementation delegates to applyToolChoice(OpenAIRequest, ToolChoice).
      参数:
      request - OpenAI request DTO
      toolChoice - Tool choice configuration
      baseUrl - API base URL (ignored by default)
      modelName - Model name (ignored by default)
    • buildRequest

      public OpenAIRequest buildRequest(String model, List<OpenAIMessage> messages, boolean stream)
      Build a basic OpenAIRequest.
      参数:
      model - Model name
      messages - Formatted OpenAI messages
      stream - Whether to enable streaming
      返回:
      Basic OpenAIRequest
    • buildRequest

      public OpenAIRequest buildRequest(String model, List<OpenAIMessage> messages, boolean stream, GenerateOptions options, GenerateOptions defaultOptions, List<ToolSchema> tools, ToolChoice toolChoice)
      Build a complete OpenAIRequest with full configuration. This method is provided for convenience but usage via the standard Formatter interface (instantiating request manually and calling apply methods) is preferred in generic code.
      参数:
      model - Model name
      messages - Formatted OpenAI messages
      stream - Whether to enable streaming
      options - Generation options
      defaultOptions - Default generation options
      tools - Tool schemas
      toolChoice - Tool choice configuration
      返回:
      Complete OpenAIRequest ready for API call
    • applyCacheControl

      public void applyCacheControl(List<OpenAIMessage> messages)
      Apply cache control to OpenAI messages.

      Adds cache_control: {"type": "ephemeral"} to all system messages and the last message in the list. Messages that already have cache_control set (e.g., via manual metadata marking) will not be overwritten.

      参数:
      messages - the list of formatted OpenAI messages