|
| 1 | +import asyncio |
| 2 | +import contextlib |
1 | 3 | import importlib |
2 | 4 | import os |
3 | 5 | import warnings |
| 6 | +from collections.abc import Coroutine |
4 | 7 |
|
5 | 8 | from aider.dump import dump # noqa: F401 |
6 | 9 |
|
@@ -44,11 +47,50 @@ def _load_litellm(self): |
44 | 47 | return |
45 | 48 |
|
46 | 49 | self._lazy_module = importlib.import_module("litellm") |
| 50 | + self._lazy_module.disable_streaming_logging = True |
47 | 51 | self._lazy_module.suppress_debug_info = True |
48 | 52 | self._lazy_module.set_verbose = False |
49 | 53 | self._lazy_module.drop_params = True |
50 | 54 | self._lazy_module._logging._disable_debugging() |
51 | 55 |
|
| 56 | + # Patch GLOBAL_LOGGING_WORKER to avoid event loop binding issues |
| 57 | + # See: https://github.com/BerriAI/litellm/issues/16518 |
| 58 | + # See: https://github.com/BerriAI/litellm/issues/14521 |
| 59 | + try: |
| 60 | + from litellm.litellm_core_utils import logging_worker |
| 61 | + except ImportError: |
| 62 | + # Module didn't exist before litellm 1.76.0 |
| 63 | + # https://github.com/BerriAI/litellm/pull/13905 |
| 64 | + pass |
| 65 | + else: |
| 66 | + |
| 67 | + class NoOpLoggingWorker: |
| 68 | + """No-op worker that executes callbacks immediately without queuing.""" |
| 69 | + |
| 70 | + def start(self) -> None: |
| 71 | + pass |
| 72 | + |
| 73 | + def enqueue(self, coroutine: Coroutine) -> None: |
| 74 | + # Execute immediately in current loop instead of queueing, |
| 75 | + # and do nothing if there's no current loop |
| 76 | + with contextlib.suppress(RuntimeError): |
| 77 | + # This logging task is fire-and-forget |
| 78 | + asyncio.create_task(coroutine) |
| 79 | + |
| 80 | + def ensure_initialized_and_enqueue(self, async_coroutine: Coroutine) -> None: |
| 81 | + self.enqueue(async_coroutine) |
| 82 | + |
| 83 | + async def stop(self) -> None: |
| 84 | + pass |
| 85 | + |
| 86 | + async def flush(self) -> None: |
| 87 | + pass |
| 88 | + |
| 89 | + async def clear_queue(self) -> None: |
| 90 | + pass |
| 91 | + |
| 92 | + logging_worker.GLOBAL_LOGGING_WORKER = NoOpLoggingWorker() |
| 93 | + |
52 | 94 |
|
53 | 95 | litellm = LazyLiteLLM() |
54 | 96 |
|
|
0 commit comments