类 ResponseFormat

java.lang.Object
io.agentscope.core.formatter.ResponseFormat

public class ResponseFormat extends Object
Response format configuration for OpenAI API.

This class supports three response format types:

  • text: Plain text response (default)
  • json_object: Valid JSON object response
  • json_schema: Response conforming to a specific JSON Schema

Example usage:


 // Plain text
 ResponseFormat format = ResponseFormat.text();

 // JSON object
 ResponseFormat format = ResponseFormat.jsonObject();

 // JSON Schema with strict validation
 JsonSchema schema = JsonSchema.builder()
     .name("MathResponse")
     .schema(Map.of("type", "object", ...))
     .strict(true)
     .build();
 ResponseFormat format = ResponseFormat.jsonSchema(schema);
 
  • 构造器详细资料

    • ResponseFormat

      public ResponseFormat()
  • 方法详细资料

    • text

      public static ResponseFormat text()
      Create a plain text response format.
      返回:
      ResponseFormat configured for plain text
    • jsonObject

      public static ResponseFormat jsonObject()
      Create a JSON object response format.

      The model will return a valid JSON object, but without a specific schema validation.

      返回:
      ResponseFormat configured for JSON object
    • jsonSchema

      public static ResponseFormat jsonSchema(JsonSchema schema)
      Create a JSON Schema response format with structured output validation.

      The model will return a response that conforms to the provided JSON Schema. When strict mode is enabled, the response will be validated against the schema.

      参数:
      schema - The JSON Schema defining the expected structure
      返回:
      ResponseFormat configured for JSON Schema validation
    • getType

      public String getType()
    • setType

      public void setType(String type)
    • getJsonSchema

      public JsonSchema getJsonSchema()
    • setJsonSchema

      public void setJsonSchema(JsonSchema jsonSchema)
    • builder

      public static ResponseFormat.Builder builder()