|
20 | 20 | import static com.google.adk.testing.TestUtils.createTestAgentBuilder; |
21 | 21 | import static com.google.adk.testing.TestUtils.createTestLlm; |
22 | 22 | import static com.google.common.truth.Truth.assertThat; |
| 23 | +import static java.nio.charset.StandardCharsets.UTF_8; |
23 | 24 | import static org.mockito.ArgumentMatchers.any; |
24 | 25 | import static org.mockito.ArgumentMatchers.anyString; |
25 | 26 | import static org.mockito.Mockito.verify; |
|
32 | 33 | import com.google.adk.codeexecutors.CodeExecutionUtils.CodeExecutionInput; |
33 | 34 | import com.google.adk.codeexecutors.CodeExecutionUtils.CodeExecutionResult; |
34 | 35 | import com.google.adk.events.Event; |
| 36 | +import com.google.adk.flows.llmflows.RequestProcessor.RequestProcessingResult; |
| 37 | +import com.google.adk.models.LlmRequest; |
35 | 38 | import com.google.adk.models.LlmResponse; |
36 | 39 | import com.google.adk.sessions.InMemorySessionService; |
37 | 40 | import com.google.adk.sessions.Session; |
38 | 41 | import com.google.adk.testing.TestLlm; |
39 | 42 | import com.google.common.collect.ImmutableList; |
| 43 | +import com.google.genai.types.Blob; |
40 | 44 | import com.google.genai.types.Content; |
41 | 45 | import com.google.genai.types.Part; |
42 | 46 | import io.reactivex.rxjava3.core.Single; |
| 47 | +import io.reactivex.rxjava3.observers.TestObserver; |
| 48 | +import java.util.ArrayList; |
43 | 49 | import org.junit.Before; |
44 | 50 | import org.junit.Rule; |
45 | 51 | import org.junit.Test; |
@@ -115,4 +121,38 @@ public void testResponseProcessor_withCode_executesCode() { |
115 | 121 | assertThat(executionResultPart.codeExecutionResult().get().output()) |
116 | 122 | .hasValue("Code execution result:\nhello\n\n"); |
117 | 123 | } |
| 124 | + |
| 125 | + @Test |
| 126 | + public void testRequestProcessor_withCode_hasNoErrors() throws Exception { |
| 127 | + // arrange |
| 128 | + LlmRequest.Builder llmReqBuilder = LlmRequest.builder(); |
| 129 | + when(mockCodeExecutor.codeBlockDelimiters()) |
| 130 | + .thenReturn(ImmutableList.of(ImmutableList.of("```tool_code", "\n```"))); |
| 131 | + when(mockCodeExecutor.optimizeDataFile()).thenReturn(true); |
| 132 | + when(mockCodeExecutor.errorRetryAttempts()).thenReturn(2); |
| 133 | + CodeExecutionResult executionResult = CodeExecutionResult.builder().stdout("hello\n").build(); |
| 134 | + when(mockCodeExecutor.executeCode(any(), any())).thenReturn(executionResult); |
| 135 | + llmReqBuilder.contents( |
| 136 | + new ArrayList<>( |
| 137 | + ImmutableList.of( |
| 138 | + Content.builder() |
| 139 | + .role("user") |
| 140 | + .parts( |
| 141 | + ImmutableList.of( |
| 142 | + Part.builder() |
| 143 | + .inlineData( |
| 144 | + Blob.builder() |
| 145 | + .mimeType("text/csv") |
| 146 | + .data("1,2,3\n".getBytes(UTF_8))) |
| 147 | + .build())) |
| 148 | + .build()))); |
| 149 | + |
| 150 | + // act |
| 151 | + Single<RequestProcessingResult> result = |
| 152 | + CodeExecution.requestProcessor.processRequest(invocationContext, llmReqBuilder.build()); |
| 153 | + TestObserver<RequestProcessingResult> testObserver = result.test(); |
| 154 | + |
| 155 | + // assert |
| 156 | + testObserver.assertNoErrors(); |
| 157 | + } |
118 | 158 | } |
0 commit comments