|
8 | 8 | "\n",
|
9 | 9 | "The model clients included in AutoGen emit structured events that can be used to track the usage of the model. This notebook demonstrates how to use the logger to track the usage of the model.\n",
|
10 | 10 | "\n",
|
11 |
| - "These events are logged to the logger with the name: :py:attr:`autogen_core.application.logging.EVENT_LOGGER_NAME`." |
| 11 | + "These events are logged to the logger with the name: :py:attr:`autogen_core.EVENT_LOGGER_NAME`." |
12 | 12 | ]
|
13 | 13 | },
|
14 | 14 | {
|
15 | 15 | "cell_type": "code",
|
16 |
| - "execution_count": 1, |
| 16 | + "execution_count": null, |
17 | 17 | "metadata": {},
|
18 | 18 | "outputs": [],
|
19 | 19 | "source": [
|
20 | 20 | "import logging\n",
|
21 | 21 | "\n",
|
22 |
| - "from autogen_core.application.logging.events import LLMCallEvent\n", |
| 22 | + "from autogen_core.logging import LLMCallEvent\n", |
23 | 23 | "\n",
|
24 | 24 | "\n",
|
25 | 25 | "class LLMUsageTracker(logging.Handler):\n",
|
26 | 26 | " def __init__(self) -> None:\n",
|
27 |
| - " \"\"\"Logging handler that tracks the number of tokens used in the prompt and completion.\n", |
28 |
| - "\n", |
29 |
| - " Example:\n", |
30 |
| - "\n", |
31 |
| - " .. code-block:: python\n", |
32 |
| - "\n", |
33 |
| - " from autogen_core.application.logging import LLMUsageTracker, EVENT_LOGGER_NAME\n", |
34 |
| - "\n", |
35 |
| - " # Set up the logging configuration to use the custom handler\n", |
36 |
| - " logger = logging.getLogger(EVENT_LOGGER_NAME)\n", |
37 |
| - " logger.setLevel(logging.INFO)\n", |
38 |
| - " llm_usage = LLMUsageTracker()\n", |
39 |
| - " logger.handlers = [llm_usage]\n", |
40 |
| - "\n", |
41 |
| - " # ...\n", |
42 |
| - "\n", |
43 |
| - " print(llm_usage.prompt_tokens)\n", |
44 |
| - " print(llm_usage.completion_tokens)\n", |
45 |
| - "\n", |
46 |
| - " \"\"\"\n", |
| 27 | + " \"\"\"Logging handler that tracks the number of tokens used in the prompt and completion.\"\"\"\n", |
47 | 28 | " super().__init__()\n",
|
48 | 29 | " self._prompt_tokens = 0\n",
|
49 | 30 | " self._completion_tokens = 0\n",
|
|
89 | 70 | "metadata": {},
|
90 | 71 | "outputs": [],
|
91 | 72 | "source": [
|
92 |
| - "from autogen_core.application.logging import EVENT_LOGGER_NAME\n", |
| 73 | + "from autogen_core import EVENT_LOGGER_NAME\n", |
93 | 74 | "\n",
|
94 | 75 | "# Set up the logging configuration to use the custom handler\n",
|
95 | 76 | "logger = logging.getLogger(EVENT_LOGGER_NAME)\n",
|
|
120 | 101 | "name": "python",
|
121 | 102 | "nbconvert_exporter": "python",
|
122 | 103 | "pygments_lexer": "ipython3",
|
123 |
| - "version": "3.12.5" |
| 104 | + "version": "3.11.5" |
124 | 105 | }
|
125 | 106 | },
|
126 | 107 | "nbformat": 4,
|
|
0 commit comments