mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-07 07:08:31 +00:00
Compare commits
5 Commits
devin/1745
...
lg-downgra
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9689b8878 | ||
|
|
25c8155609 | ||
|
|
73b15b5d32 | ||
|
|
55b07506c2 | ||
|
|
4efa935c1a |
@@ -11,7 +11,7 @@ dependencies = [
|
||||
# Core Dependencies
|
||||
"pydantic>=2.4.2",
|
||||
"openai>=1.13.3",
|
||||
"litellm==1.67.2",
|
||||
"litellm==1.67.1",
|
||||
"instructor>=1.3.3",
|
||||
# Text Processing
|
||||
"pdfplumber>=0.11.4",
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import warnings
|
||||
|
||||
from crewai.patches.litellm_patch import apply_patches
|
||||
apply_patches()
|
||||
|
||||
from crewai.agent import Agent
|
||||
from crewai.crew import Crew
|
||||
from crewai.crews.crew_output import CrewOutput
|
||||
|
||||
1
src/crewai/agents/agent_adapters/langgraph/__init__.py
Normal file
1
src/crewai/agents/agent_adapters/langgraph/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""LangGraph adapter for crewAI."""
|
||||
@@ -0,0 +1 @@
|
||||
"""OpenAI agent adapters for crewAI."""
|
||||
@@ -0,0 +1 @@
|
||||
"""Poem crew template."""
|
||||
1
src/crewai/knowledge/utils/__init__.py
Normal file
1
src/crewai/knowledge/utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Knowledge utilities for crewAI."""
|
||||
1
src/crewai/llms/__init__.py
Normal file
1
src/crewai/llms/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""LLM implementations for crewAI."""
|
||||
1
src/crewai/llms/third_party/__init__.py
vendored
Normal file
1
src/crewai/llms/third_party/__init__.py
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"""Third-party LLM implementations for crewAI."""
|
||||
1
src/crewai/memory/storage/__init__.py
Normal file
1
src/crewai/memory/storage/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Memory storage implementations for crewAI."""
|
||||
@@ -1 +0,0 @@
|
||||
# This file is intentionally left empty to make the directory a package
|
||||
@@ -1,73 +0,0 @@
|
||||
"""
|
||||
Patch for litellm to fix UnicodeDecodeError on Windows systems.
|
||||
|
||||
This patch ensures that all file open operations in litellm use UTF-8 encoding,
|
||||
which prevents UnicodeDecodeError when loading JSON files on Windows systems
|
||||
where the default encoding is cp1252 or cp1254.
|
||||
|
||||
WARNING: This patch monkey-patches the built-in open() function globally on Windows.
|
||||
It forces UTF-8 encoding on all text-mode file opens, which could affect third-party
|
||||
libraries expecting default platform encodings. Apply with caution and test comprehensively.
|
||||
"""
|
||||
|
||||
import builtins
|
||||
import functools
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from importlib import resources
|
||||
from typing import Any, Optional, Union
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def apply_patches():
|
||||
"""
|
||||
Apply patches to fix litellm encoding issues on Windows systems.
|
||||
|
||||
This function only applies the patch on Windows platforms where the issue occurs.
|
||||
It stores the original open function for proper restoration later.
|
||||
"""
|
||||
# Only apply patch on Windows systems
|
||||
if sys.platform != "win32":
|
||||
logger.debug("Skipping litellm encoding patches on non-Windows platform")
|
||||
return
|
||||
|
||||
if hasattr(builtins, '_original_open'):
|
||||
logger.debug("Litellm encoding patches already applied")
|
||||
return
|
||||
|
||||
logger.debug("Applying litellm encoding patches on Windows")
|
||||
|
||||
builtins._original_open = builtins.open
|
||||
|
||||
@functools.wraps(builtins._original_open)
|
||||
def patched_open(
|
||||
file, mode='r', buffering=-1, encoding=None,
|
||||
errors=None, newline=None, closefd=True, opener=None
|
||||
):
|
||||
if 'r' in mode and encoding is None and 'b' not in mode:
|
||||
encoding = 'utf-8'
|
||||
|
||||
return builtins._original_open(
|
||||
file, mode, buffering, encoding,
|
||||
errors, newline, closefd, opener
|
||||
)
|
||||
|
||||
builtins.open = patched_open
|
||||
|
||||
logger.debug("Successfully applied litellm encoding patches")
|
||||
|
||||
|
||||
def remove_patches():
|
||||
"""
|
||||
Remove all patches (for testing purposes).
|
||||
|
||||
This function properly restores the original open function if it was patched.
|
||||
"""
|
||||
if hasattr(builtins, '_original_open'):
|
||||
builtins.open = builtins._original_open
|
||||
delattr(builtins, '_original_open')
|
||||
logger.debug("Removed litellm encoding patches")
|
||||
@@ -8,8 +8,6 @@ from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
|
||||
T = TypeVar("T", bound=type)
|
||||
|
||||
"""Base decorator for creating crew classes with configuration and function management."""
|
||||
|
||||
1
src/crewai/tools/agent_tools/__init__.py
Normal file
1
src/crewai/tools/agent_tools/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Agent tools for crewAI."""
|
||||
1
src/crewai/utilities/evaluators/__init__.py
Normal file
1
src/crewai/utilities/evaluators/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Evaluators for crewAI."""
|
||||
1
src/crewai/utilities/events/utils/__init__.py
Normal file
1
src/crewai/utilities/events/utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Event utilities for crewAI."""
|
||||
1
src/crewai/utilities/exceptions/__init__.py
Normal file
1
src/crewai/utilities/exceptions/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Exceptions for crewAI."""
|
||||
1
tests/agents/agent_adapters/__init__.py
Normal file
1
tests/agents/agent_adapters/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for agent adapters."""
|
||||
1
tests/agents/agent_builder/__init__.py
Normal file
1
tests/agents/agent_builder/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for agent builder."""
|
||||
1
tests/cli/deploy/__init__.py
Normal file
1
tests/cli/deploy/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for CLI deploy."""
|
||||
@@ -1,51 +0,0 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import mock_open, patch
|
||||
|
||||
from crewai.llm import LLM
|
||||
from crewai.patches.litellm_patch import apply_patches, remove_patches
|
||||
|
||||
|
||||
class TestLitellmEncoding(unittest.TestCase):
|
||||
"""Test that the litellm encoding patch works correctly."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up the test environment by applying the patch."""
|
||||
apply_patches()
|
||||
|
||||
def tearDown(self):
|
||||
"""Clean up the test environment by removing the patch."""
|
||||
remove_patches()
|
||||
|
||||
def test_json_load_with_utf8_encoding(self):
|
||||
"""Test that json.load is called with UTF-8 encoding."""
|
||||
|
||||
mock_content = '{"test": "日本語テキスト"}' # Japanese text that would fail with cp1252
|
||||
|
||||
with patch('builtins.open', mock_open(read_data=mock_content)):
|
||||
import litellm
|
||||
|
||||
self.assertTrue(hasattr(litellm.utils, 'json_data'))
|
||||
|
||||
with open('test.json', 'r') as f:
|
||||
data = json.load(f)
|
||||
self.assertEqual(data['test'], '日本語テキスト')
|
||||
|
||||
def test_without_patch(self):
|
||||
"""Test that demonstrates the issue without the patch."""
|
||||
remove_patches()
|
||||
|
||||
mock_content = '{"test": "日本語テキスト"}' # Japanese text that would fail with cp1252
|
||||
|
||||
with patch('sys.platform', 'win32'):
|
||||
mock_open_without_encoding = mock_open(read_data=mock_content)
|
||||
mock_open_without_encoding.side_effect = UnicodeDecodeError('cp1252', b'\x81', 0, 1, 'invalid start byte')
|
||||
|
||||
with patch('builtins.open', mock_open_without_encoding):
|
||||
with self.assertRaises(UnicodeDecodeError):
|
||||
with open('test.json', 'r') as f:
|
||||
json.load(f)
|
||||
|
||||
apply_patches()
|
||||
1
tests/memory/__init__.py
Normal file
1
tests/memory/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for memory."""
|
||||
1
tests/storage/__init__.py
Normal file
1
tests/storage/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for storage."""
|
||||
1
tests/tools/__init__.py
Normal file
1
tests/tools/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for tools."""
|
||||
1
tests/utilities/__init__.py
Normal file
1
tests/utilities/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for utilities."""
|
||||
1
tests/utilities/evaluators/__init__.py
Normal file
1
tests/utilities/evaluators/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for evaluators."""
|
||||
1
tests/utilities/events/__init__.py
Normal file
1
tests/utilities/events/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for events."""
|
||||
Reference in New Issue
Block a user