Merge branch 'main' into lg-agent-repository

This commit is contained in:
Lucas Gomide
2025-05-12 16:33:40 -03:00
committed by GitHub

View File

@@ -5,8 +5,7 @@ import sys
import threading import threading
import warnings import warnings
from collections import defaultdict from collections import defaultdict
from contextlib import contextmanager from contextlib import contextmanager, redirect_stderr, redirect_stdout
from types import SimpleNamespace
from typing import ( from typing import (
Any, Any,
DefaultDict, DefaultDict,
@@ -31,7 +30,6 @@ from crewai.utilities.events.llm_events import (
LLMCallType, LLMCallType,
LLMStreamChunkEvent, LLMStreamChunkEvent,
) )
from crewai.utilities.events.tool_usage_events import ToolExecutionErrorEvent
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning) warnings.simplefilter("ignore", UserWarning)
@@ -45,6 +43,9 @@ with warnings.catch_warnings():
from litellm.utils import supports_response_schema from litellm.utils import supports_response_schema
import io
from typing import TextIO
from crewai.llms.base_llm import BaseLLM from crewai.llms.base_llm import BaseLLM
from crewai.utilities.events import crewai_event_bus from crewai.utilities.events import crewai_event_bus
from crewai.utilities.exceptions.context_window_exceeding_exception import ( from crewai.utilities.exceptions.context_window_exceeding_exception import (
@@ -54,12 +55,17 @@ from crewai.utilities.exceptions.context_window_exceeding_exception import (
load_dotenv() load_dotenv()
class FilteredStream: class FilteredStream(io.TextIOBase):
def __init__(self, original_stream): _lock = None
def __init__(self, original_stream: TextIO):
self._original_stream = original_stream self._original_stream = original_stream
self._lock = threading.Lock() self._lock = threading.Lock()
def write(self, s) -> int: def write(self, s: str) -> int:
if not self._lock:
self._lock = threading.Lock()
with self._lock: with self._lock:
# Filter out extraneous messages from LiteLLM # Filter out extraneous messages from LiteLLM
if ( if (
@@ -214,15 +220,11 @@ def suppress_warnings():
) )
# Redirect stdout and stderr # Redirect stdout and stderr
old_stdout = sys.stdout with (
old_stderr = sys.stderr redirect_stdout(FilteredStream(sys.stdout)),
sys.stdout = FilteredStream(old_stdout) redirect_stderr(FilteredStream(sys.stderr)),
sys.stderr = FilteredStream(old_stderr) ):
try:
yield yield
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr
class Delta(TypedDict): class Delta(TypedDict):