Files
coze-studio/py_package/browser_agent/utils.py
liuyunchao.0510 ee46dd8417 browser_use_plugin
name change

name change

name change

name change

name change

name change

暂存

暂存

暂存

版本更新

版本更新

版本更新

和网关协议对齐

和网关协议对齐

和网关协议对齐

再升级下

再升

再完善下

升级

final resp

修复

修复

修复

再测试下

再测试下

包顺序

包顺序

包顺序

包顺序

修改为answer

更新下

更新版本

使用logger

使用logger

使用

滚滚滚

更新版本

screen opmot

test

use context

有问题

gogogo

agent browser

agent browser

screen

resume

gogo

gogo

file upload to debug

file upload base64

screen

screen

修复

修复
2025-10-13 21:21:20 +08:00

87 lines
2.8 KiB
Python

# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# Licensed under the 【火山方舟】原型应用软件自用许可协议
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.volcengine.com/docs/82379/1433703
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from typing import Any, Dict, List
from langchain_core.callbacks import BaseCallbackHandler
from langchain_core.messages import BaseMessage
from langchain_core.outputs import LLMResult
root_logger = logging.getLogger()
for handler in root_logger.handlers:
formatter = logging.Formatter(
'%(asctime)s - %(levelname)s - %(message)s',
'%Y-%m-%d %H:%M:%S'
)
handler.setFormatter(formatter)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
def enforce_log_format():
root_logger = logging.getLogger()
for handler in root_logger.handlers:
formatter = logging.Formatter(
'%(asctime)s - %(levelname)s - %(message)s',
'%Y-%m-%d %H:%M:%S'
)
handler.setFormatter(formatter)
class ModelLoggingCallback(BaseCallbackHandler):
def on_chat_model_start(
self, serialized: Dict[str, Any], messages: List[List[BaseMessage]], **kwargs
) -> None:
logging.info(
f"[Model] Chat model started\n")
def on_llm_end(self, response: LLMResult, **kwargs) -> None:
logging.info(
f"[Model] Chat model ended, response: {response}")
def on_llm_error(self, error: BaseException, **kwargs) -> Any:
logging.info(
f"[Model] Chat model error, response: {error}")
def on_chain_start(
self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs
) -> None:
logging.info(
f"[Model] Chain {serialized.get('name')} started")
def on_chain_end(self, outputs: Dict[str, Any], **kwargs) -> None:
logging.info(f"[Model] Chain ended, outputs: {outputs}")
# class that wraps another class and logs all function calls being executed
class Wrapper:
def __init__(self, wrapped_class):
self.wrapped_class = wrapped_class
def __getattr__(self, attr):
original_func = getattr(self.wrapped_class, attr)
def wrapper(*args, **kwargs):
print(f"Calling function: {attr}")
print(f"Arguments: {args}, {kwargs}")
result = original_func(*args, **kwargs)
print(f"Response: {result}")
return result
return wrapper