Skip to content

Commit 8244c6a

Browse files
committed
#153: Attempt a more general fix for this since I think single threaded runtimes might be why this happens
1 parent 11a53a1 commit 8244c6a

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

aider/llm.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import asyncio
2+
import contextlib
13
import importlib
24
import os
35
import warnings
6+
from collections.abc import Coroutine
47

58
from aider.dump import dump # noqa: F401
69

@@ -44,11 +47,50 @@ def _load_litellm(self):
4447
return
4548

4649
self._lazy_module = importlib.import_module("litellm")
50+
self._lazy_module.disable_streaming_logging = True
4751
self._lazy_module.suppress_debug_info = True
4852
self._lazy_module.set_verbose = False
4953
self._lazy_module.drop_params = True
5054
self._lazy_module._logging._disable_debugging()
5155

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+
5294

5395
litellm = LazyLiteLLM()
5496

0 commit comments

Comments
 (0)