mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 09:08:31 +00:00
Fix UnicodeDecodeError in litellm when loading JSON files on Windows
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
0
tests/litellm_tests/__init__.py
Normal file
0
tests/litellm_tests/__init__.py
Normal file
27
tests/litellm_tests/test_encoding.py
Normal file
27
tests/litellm_tests/test_encoding.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import patch, mock_open
|
||||
|
||||
import pytest
|
||||
|
||||
from crewai.llm import LLM
|
||||
|
||||
|
||||
class TestLitellmEncoding(unittest.TestCase):
|
||||
"""Test that the litellm encoding patch works correctly."""
|
||||
|
||||
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'], '日本語テキスト')
|
||||
Reference in New Issue
Block a user