chore: replace print with logger.info

PiperOrigin-RevId: 767732597
This commit is contained in:
Xiang (Sean) Zhou
2025-06-05 13:09:07 -07:00
committed by Copybara-Service
parent 4b1c218cbe
commit 078ac842d7
5 changed files with 32 additions and 14 deletions
@@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import annotations
import atexit import atexit
import logging
import os import os
from typing import Optional 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 CodeExecutionInput
from .code_execution_utils import CodeExecutionResult from .code_execution_utils import CodeExecutionResult
logger = logging.getLogger('google_adk.' + __name__)
DEFAULT_IMAGE_TAG = 'adk-code-executor:latest' DEFAULT_IMAGE_TAG = 'adk-code-executor:latest'
@@ -151,13 +155,13 @@ class ContainerCodeExecutor(BaseCodeExecutor):
if not os.path.exists(self.docker_path): if not os.path.exists(self.docker_path):
raise FileNotFoundError(f'Invalid Docker path: {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( self._client.images.build(
path=self.docker_path, path=self.docker_path,
tag=self.image, tag=self.image,
rm=True, rm=True,
) )
print(f'Docker image: {self.image} built.') logger.info('Docker image: %s built.', self.image)
def _verify_python_installation(self): def _verify_python_installation(self):
"""Verifies the container has python3 installed.""" """Verifies the container has python3 installed."""
@@ -173,13 +177,13 @@ class ContainerCodeExecutor(BaseCodeExecutor):
if self.docker_path: if self.docker_path:
self._build_docker_image() self._build_docker_image()
print('Starting container for ContainerCodeExecutor...') logger.info('Starting container for ContainerCodeExecutor...')
self._container = self._client.containers.run( self._container = self._client.containers.run(
image=self.image, image=self.image,
detach=True, detach=True,
tty=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. # Verify the container is able to run python3.
self._verify_python_installation() self._verify_python_installation()
@@ -189,7 +193,7 @@ class ContainerCodeExecutor(BaseCodeExecutor):
if not self._container: if not self._container:
return return
print('[Cleanup] Stopping the container...') logger.info('[Cleanup] Stopping the container...')
self._container.stop() self._container.stop()
self._container.remove() self._container.remove()
print(f'Container {self._container.id} stopped and removed.') logger.info('Container %s stopped and removed.', self._container.id)
@@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import datetime from __future__ import annotations
import logging
import mimetypes import mimetypes
import os import os
from typing import Any 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 CodeExecutionResult
from .code_execution_utils import File from .code_execution_utils import File
logger = logging.getLogger('google_adk.' + __name__)
_SUPPORTED_IMAGE_TYPES = ['png', 'jpg', 'jpeg'] _SUPPORTED_IMAGE_TYPES = ['png', 'jpg', 'jpeg']
_SUPPORTED_DATA_FILE_TYPES = ['csv'] _SUPPORTED_DATA_FILE_TYPES = ['csv']
@@ -89,7 +93,9 @@ def _get_code_interpreter_extension(resource_name: str = None):
if resource_name: if resource_name:
new_code_interpreter = Extension(resource_name) new_code_interpreter = Extension(resource_name)
else: 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') new_code_interpreter = Extension.from_hub('code_interpreter')
os.environ['CODE_INTERPRETER_EXTENSION_NAME'] = ( os.environ['CODE_INTERPRETER_EXTENSION_NAME'] = (
new_code_interpreter.gca_resource.name new_code_interpreter.gca_resource.name
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import annotations
import argparse import argparse
import json import json
import logging import logging
@@ -505,11 +507,12 @@ def main():
converter = GoogleApiToOpenApiConverter(args.api_name, args.api_version) converter = GoogleApiToOpenApiConverter(args.api_name, args.api_version)
converter.convert() converter.convert()
converter.save_openapi_spec(args.output) converter.save_openapi_spec(args.output)
print( logger.info(
f"Successfully converted {args.api_name} {args.api_version} to" "Successfully converted %s %s to OpenAPI v3",
" 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: except Exception as e:
logger.error("Conversion failed: %s", e) logger.error("Conversion failed: %s", e)
return 1 return 1
@@ -48,7 +48,6 @@ class GoogleSearchTool(BaseTool):
llm_request.config.tools = llm_request.config.tools or [] llm_request.config.tools = llm_request.config.tools or []
if llm_request.model and 'gemini-1' in llm_request.model: if llm_request.model and 'gemini-1' in llm_request.model:
if llm_request.config.tools: if llm_request.config.tools:
print(llm_request.config.tools)
raise ValueError( raise ValueError(
'Google search tool can not be used with other tools in Gemini 1.x.' 'Google search tool can not be used with other tools in Gemini 1.x.'
) )
@@ -14,11 +14,17 @@
"""Provides data for the agent.""" """Provides data for the agent."""
from __future__ import annotations
import logging
from llama_index.core import SimpleDirectoryReader from llama_index.core import SimpleDirectoryReader
from llama_index.core import VectorStoreIndex from llama_index.core import VectorStoreIndex
from .llama_index_retrieval import LlamaIndexRetrieval from .llama_index_retrieval import LlamaIndexRetrieval
logger = logging.getLogger("google_adk." + __name__)
class FilesRetrieval(LlamaIndexRetrieval): class FilesRetrieval(LlamaIndexRetrieval):
@@ -26,7 +32,7 @@ class FilesRetrieval(LlamaIndexRetrieval):
self.input_dir = input_dir self.input_dir = input_dir
print(f'Loading data from {input_dir}') logger.info("Loading data from %s", input_dir)
retriever = VectorStoreIndex.from_documents( retriever = VectorStoreIndex.from_documents(
SimpleDirectoryReader(input_dir).load_data() SimpleDirectoryReader(input_dir).load_data()
).as_retriever() ).as_retriever()