diff --git a/src/google/adk/code_executors/container_code_executor.py b/src/google/adk/code_executors/container_code_executor.py index fee02ee6..d12fee13 100644 --- a/src/google/adk/code_executors/container_code_executor.py +++ b/src/google/adk/code_executors/container_code_executor.py @@ -12,7 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import atexit +import logging import os from typing import Optional @@ -27,6 +30,7 @@ from .base_code_executor import BaseCodeExecutor from .code_execution_utils import CodeExecutionInput from .code_execution_utils import CodeExecutionResult +logger = logging.getLogger('google_adk.' + __name__) DEFAULT_IMAGE_TAG = 'adk-code-executor:latest' @@ -151,13 +155,13 @@ class ContainerCodeExecutor(BaseCodeExecutor): if not os.path.exists(self.docker_path): raise FileNotFoundError(f'Invalid Docker path: {self.docker_path}') - print('Building Docker image...') + logger.info('Building Docker image...') self._client.images.build( path=self.docker_path, tag=self.image, rm=True, ) - print(f'Docker image: {self.image} built.') + logger.info('Docker image: %s built.', self.image) def _verify_python_installation(self): """Verifies the container has python3 installed.""" @@ -173,13 +177,13 @@ class ContainerCodeExecutor(BaseCodeExecutor): if self.docker_path: self._build_docker_image() - print('Starting container for ContainerCodeExecutor...') + logger.info('Starting container for ContainerCodeExecutor...') self._container = self._client.containers.run( image=self.image, detach=True, tty=True, ) - print(f'Container {self._container.id} started.') + logger.info('Container %s started.', self._container.id) # Verify the container is able to run python3. self._verify_python_installation() @@ -189,7 +193,7 @@ class ContainerCodeExecutor(BaseCodeExecutor): if not self._container: return - print('[Cleanup] Stopping the container...') + logger.info('[Cleanup] Stopping the container...') self._container.stop() self._container.remove() - print(f'Container {self._container.id} stopped and removed.') + logger.info('Container %s stopped and removed.', self._container.id) diff --git a/src/google/adk/code_executors/vertex_ai_code_executor.py b/src/google/adk/code_executors/vertex_ai_code_executor.py index bc4d7311..b1dd58ce 100644 --- a/src/google/adk/code_executors/vertex_ai_code_executor.py +++ b/src/google/adk/code_executors/vertex_ai_code_executor.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import datetime +from __future__ import annotations + +import logging import mimetypes import os from typing import Any @@ -27,6 +29,8 @@ from .code_execution_utils import CodeExecutionInput from .code_execution_utils import CodeExecutionResult from .code_execution_utils import File +logger = logging.getLogger('google_adk.' + __name__) + _SUPPORTED_IMAGE_TYPES = ['png', 'jpg', 'jpeg'] _SUPPORTED_DATA_FILE_TYPES = ['csv'] @@ -89,7 +93,9 @@ def _get_code_interpreter_extension(resource_name: str = None): if resource_name: new_code_interpreter = Extension(resource_name) else: - print('No CODE_INTERPRETER_ID found in the environment. Create a new one.') + logger.info( + 'No CODE_INTERPRETER_ID found in the environment. Create a new one.' + ) new_code_interpreter = Extension.from_hub('code_interpreter') os.environ['CODE_INTERPRETER_EXTENSION_NAME'] = ( new_code_interpreter.gca_resource.name diff --git a/src/google/adk/tools/google_api_tool/googleapi_to_openapi_converter.py b/src/google/adk/tools/google_api_tool/googleapi_to_openapi_converter.py index ba74d81b..893f1f9f 100644 --- a/src/google/adk/tools/google_api_tool/googleapi_to_openapi_converter.py +++ b/src/google/adk/tools/google_api_tool/googleapi_to_openapi_converter.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import argparse import json import logging @@ -505,11 +507,12 @@ def main(): converter = GoogleApiToOpenApiConverter(args.api_name, args.api_version) converter.convert() converter.save_openapi_spec(args.output) - print( - f"Successfully converted {args.api_name} {args.api_version} to" - " OpenAPI v3" + logger.info( + "Successfully converted %s %s to OpenAPI v3", + args.api_name, + args.api_version, ) - print(f"Output saved to {args.output}") + logger.info("Output saved to %s", args.output) except Exception as e: logger.error("Conversion failed: %s", e) return 1 diff --git a/src/google/adk/tools/google_search_tool.py b/src/google/adk/tools/google_search_tool.py index 164229b1..d116e4b6 100644 --- a/src/google/adk/tools/google_search_tool.py +++ b/src/google/adk/tools/google_search_tool.py @@ -48,7 +48,6 @@ class GoogleSearchTool(BaseTool): llm_request.config.tools = llm_request.config.tools or [] if llm_request.model and 'gemini-1' in llm_request.model: if llm_request.config.tools: - print(llm_request.config.tools) raise ValueError( 'Google search tool can not be used with other tools in Gemini 1.x.' ) diff --git a/src/google/adk/tools/retrieval/files_retrieval.py b/src/google/adk/tools/retrieval/files_retrieval.py index d65a709b..00142667 100644 --- a/src/google/adk/tools/retrieval/files_retrieval.py +++ b/src/google/adk/tools/retrieval/files_retrieval.py @@ -14,11 +14,17 @@ """Provides data for the agent.""" +from __future__ import annotations + +import logging + from llama_index.core import SimpleDirectoryReader from llama_index.core import VectorStoreIndex from .llama_index_retrieval import LlamaIndexRetrieval +logger = logging.getLogger("google_adk." + __name__) + class FilesRetrieval(LlamaIndexRetrieval): @@ -26,7 +32,7 @@ class FilesRetrieval(LlamaIndexRetrieval): self.input_dir = input_dir - print(f'Loading data from {input_dir}') + logger.info("Loading data from %s", input_dir) retriever = VectorStoreIndex.from_documents( SimpleDirectoryReader(input_dir).load_data() ).as_retriever()