类名称:CodeExecutionUtils
java.lang.Object
com.google.adk.codeexecutors.CodeExecutionUtils
用于代码执行的实用函数。
-
嵌套类概述
Nested ClassesModifier and TypeClassDescriptionstatic class一个用于存储代码执行所需输入数据的结构。static class一个用于存储代码执行结果的结构。static class一个结构体,其中包含文件名及其内容。 -
方法概述
Modifier and TypeMethodDescriptionstatic com.google.genai.types.Partstatic com.google.genai.types.Partstatic com.google.genai.types.ContentconvertCodeExecutionParts(com.google.genai.types.Content content, List<String> codeBlockDelimiters, List<String> executionResultDelimiters) 将代码执行部分转换为内容中的文本部分。extractCodeAndTruncateContent(com.google.genai.types.Content.Builder contentBuilder, List<? extends List<String>> codeBlockDelimiters) 从内容中提取第一个代码块,并删除该代码块之后的所有内容。
-
方法详细信息(Method Details)
-
buildCodeExecutionResultPart
public static com.google.genai.types.Part buildCodeExecutionResultPart(CodeExecutionUtils.CodeExecutionResult result) -
buildExecutableCodePart
-
convertCodeExecutionParts
public static com.google.genai.types.Content convertCodeExecutionParts(com.google.genai.types.Content content, List<String> codeBlockDelimiters, List<String> executionResultDelimiters) 将代码执行部分转换为内容中的文本部分。- Parameters:
content- The content to convert.codeBlockDelimiters- The delimiters to format the code block.executionResultDelimiters- The delimiters to format the code execution result.- Returns:
- The updated content.
-
extractCodeAndTruncateContent
public static Optional<String> extractCodeAndTruncateContent(com.google.genai.types.Content.Builder contentBuilder, List<? extends List<String>> codeBlockDelimiters) 从内容中提取第一个代码块,并删除该代码块之后的所有内容。- Parameters:
contentBuilder- The content builder to extract the code from and modify.codeBlockDelimiters- The list of the enclosing delimiters to identify the code blocks.- Returns:
- The extracted code if found.
-