类名:SchemaUtils
java.lang.Object
com.google.adk.SchemaUtils
这是一个用于读取 JSON 数据并根据相关规范验证数据值的实用类(utility class)。
-
方法概述
Modifier and TypeMethodDescriptionstatic booleandescribesObject(com.google.genai.types.Schema schema) 返回一个布尔值,表示是否……schema这是一个对象(object);其类型为“typed”。OBJECT或者类型未知; 除非该对象具有某种已知的类型。items两者都不是。propertiesnorrequired.findMismatch(@Nullable Object value, com.google.genai.types.Schema schema) 返回原因(即为什么会发生某种情况)。value不匹配。schema如果该值不存在,则返回空字符串;如果该值存在,则返回其实际值。static @Nullable ObjectparseModelOutput(String output, com.google.genai.types.Schema schema) 根据……解析模型文本。schema该函数可以将数据作为 JSON 值返回;如果返回 JSON 值失败(且数据格式符合指定的规范),则会直接返回文本本身(前提是该规范允许使用字符串类型的数据)。static voidvalidateMapOnSchema(Map<String, Object> args, com.google.genai.types.Schema schema, Boolean isInput) 根据指定的模式验证一个映射(map)的结构是否合法。static @Nullable ObjectvalidateOutput(String output, com.google.genai.types.Schema schema) 解析(数据)output然后根据某些标准对其进行验证(即检查其是否符合要求)。schema.validateOutputSchema(String output, com.google.genai.types.Schema schema) 根据指定的模式验证输出字符串的有效性。
-
方法详细信息(Method Details)
-
validateMapOnSchema
public static void validateMapOnSchema(Map<String, Object> args, com.google.genai.types.Schema schema, Boolean isInput) 根据指定的模式验证一个映射(map)的结构是否合法。- Parameters:
args- The map to validate.schema- The schema to validate against.isInput- Whether the map is an input or output.- Throws:
IllegalArgumentException- If the map does not match the schema.
-
parseModelOutput
public static @Nullable Object parseModelOutput(String output, com.google.genai.types.Schema schema) 根据……解析模型文本。schema该函数应该以 JSON 值的形式返回数据;如果返回数据失败(即无法满足数据结构的要求),且数据结构允许字符串类型作为输入,则应直接返回该字符串本身。数据结构同时允许空字符串(即 “”)和 JSON 中的 `null` 值。null.此方法仅适用于代理开发工具包(Agent Development Kit)。
- Throws:
IllegalArgumentException- if the text does not match the schema
-
findMismatch
-
describesObject
public static boolean describesObject(com.google.genai.types.Schema schema) 返回一个布尔值,表示是否……schema这是一个对象(object);其类型为“typed”。OBJECT或者类型未知; 除非该对象具有某种已知的类型。items两者都不是。propertiesnorrequired.此方法仅适用于代理开发工具包(Agent Development Kit)。
-
validateOutput
public static @Nullable Object validateOutput(String output, com.google.genai.types.Schema schema) throws com.fasterxml.jackson.core.JsonProcessingException 解析(数据)output然后根据某些标准对其进行验证(即检查其是否符合要求)。schema一个对象模式(object schema)需要经过一定的处理或转换过程才能被使用。validateOutputSchema(String, Schema)对于数组或基本数据类型的结构(schema),该方法会返回解析后的值(例如一个列表),该值可能为 `null`。此方法仅适用于代理开发工具包(Agent Development Kit)。
- Throws:
IllegalArgumentException- If the output does not match the schema.com.fasterxml.jackson.core.JsonProcessingException- If the output cannot be parsed.
-
validateOutputSchema
public static Map<String,Object> validateOutputSchema(String output, com.google.genai.types.Schema schema) throws com.fasterxml.jackson.core.JsonProcessingException 根据指定的模式验证输出字符串的有效性。- Parameters:
output- The output string to validate.schema- The schema to validate against.- Returns:
- The output map.
- Throws:
IllegalArgumentException- If the output string does not match the schema.com.fasterxml.jackson.core.JsonProcessingException- If the output string cannot be parsed.
-