|
24 | 24 | ) |
25 | 25 | from pydantic import BaseModel |
26 | 26 |
|
| 27 | +from camel.logger import get_logger as camel_get_logger |
27 | 28 | from camel.messages import OpenAIMessage |
28 | 29 | from camel.types import ( |
29 | 30 | ChatCompletion, |
|
34 | 35 | ) |
35 | 36 | from camel.utils import BaseTokenCounter |
36 | 37 |
|
| 38 | +if os.environ.get("TRACEROOT_ENABLED", "False").lower() == "true": |
| 39 | + try: |
| 40 | + from traceroot import get_logger # type: ignore[import] |
| 41 | + from traceroot import trace as observe # type: ignore[import] |
| 42 | + |
| 43 | + logger = get_logger('base_model') |
| 44 | + except ImportError: |
| 45 | + from camel.utils import observe |
| 46 | + |
| 47 | + logger = camel_get_logger('base_model') |
| 48 | +else: |
| 49 | + from camel.utils import observe |
| 50 | + |
| 51 | + logger = camel_get_logger('base_model') |
| 52 | + |
37 | 53 |
|
38 | 54 | class ModelBackendMeta(abc.ABCMeta): |
39 | 55 | r"""Metaclass that automatically preprocesses messages in run method. |
@@ -364,6 +380,7 @@ async def _arun( |
364 | 380 | """ |
365 | 381 | pass |
366 | 382 |
|
| 383 | + @observe() |
367 | 384 | def run( |
368 | 385 | self, |
369 | 386 | messages: List[OpenAIMessage], |
@@ -403,14 +420,21 @@ def run( |
403 | 420 | elif not tools: |
404 | 421 | tools = None |
405 | 422 |
|
| 423 | + logger.info("Running model: %s", self.model_type) |
| 424 | + logger.info("Messages: %s", messages) |
| 425 | + logger.info("Response format: %s", response_format) |
| 426 | + logger.info("Tools: %s", tools) |
| 427 | + |
406 | 428 | result = self._run(messages, response_format, tools) |
| 429 | + logger.info("Result: %s", result) |
407 | 430 |
|
408 | 431 | # Log the response if logging is enabled |
409 | 432 | if log_path: |
410 | 433 | self._log_response(log_path, result) |
411 | 434 |
|
412 | 435 | return result |
413 | 436 |
|
| 437 | + @observe() |
414 | 438 | async def arun( |
415 | 439 | self, |
416 | 440 | messages: List[OpenAIMessage], |
@@ -448,7 +472,13 @@ async def arun( |
448 | 472 | elif not tools: |
449 | 473 | tools = None |
450 | 474 |
|
| 475 | + logger.info("Running model: %s", self.model_type) |
| 476 | + logger.info("Messages: %s", messages) |
| 477 | + logger.info("Response format: %s", response_format) |
| 478 | + logger.info("Tools: %s", tools) |
| 479 | + |
451 | 480 | result = await self._arun(messages, response_format, tools) |
| 481 | + logger.info("Result: %s", result) |
452 | 482 |
|
453 | 483 | # Log the response if logging is enabled |
454 | 484 | if log_path: |
|
0 commit comments