[Bug Fix] UnicodeDecodeError: 'charmap' on Windows during litellm import (#10542)

* test using litellm on windows

* fix using litellm on windows

* test using litellm on windows

* fix change on ci/cd

* fix test on ci/cd
This commit is contained in:
Ishaan Jaff
2025-05-03 21:31:05 -07:00
committed by GitHub
parent 8aa57ff0c0
commit 7c4fae477a
3 changed files with 69 additions and 2 deletions
+33 -1
View File
@@ -2,6 +2,7 @@ version: 2.1
orbs:
codecov: codecov/codecov@4.0.1
node: circleci/node@5.1.0 # Add this line to declare the node orb
win: circleci/windows@5.0 # Add Windows orb
commands:
setup_google_dns:
@@ -17,6 +18,31 @@ commands:
echo "nameserver 8.8.4.4" | sudo tee -a /etc/resolv.conf
jobs:
# Add Windows testing job
using_litellm_on_windows:
executor:
name: win/default
shell: powershell.exe
working_directory: ~/project
steps:
- checkout
- run:
name: Install Python
command: |
choco install python --version=3.11.0 -y
refreshenv
python --version
- run:
name: Install Dependencies
command: |
python -m pip install --upgrade pip
pip install pytest
pip install .
- run:
name: Run Windows-specific test
command: |
python -m pytest tests/windows_tests/test_litellm_on_windows.py -v
local_testing:
docker:
- image: cimg/python:3.11
@@ -2680,6 +2706,12 @@ workflows:
version: 2
build_and_test:
jobs:
- using_litellm_on_windows:
filters:
branches:
only:
- main
- /litellm_.*/
- local_testing:
filters:
branches:
@@ -2937,4 +2969,4 @@ workflows:
- proxy_pass_through_endpoint_tests
- check_code_and_doc_quality
- publish_proxy_extras
+1 -1
View File
@@ -183,7 +183,7 @@ try:
# Python 3.9+
with resources.files("litellm.litellm_core_utils.tokenizers").joinpath(
"anthropic_tokenizer.json"
).open("r") as f:
).open("r", encoding="utf-8") as f:
json_data = json.load(f)
except (ImportError, AttributeError, TypeError):
with resources.open_text(
@@ -0,0 +1,35 @@
import asyncio
import os
import subprocess
import sys
import time
import traceback
import platform
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
def test_using_litellm_on_windows():
"""Test that LiteLLM can be imported on Windows systems."""
try:
import litellm
print(f"litellm imported successfully on Windows ({platform.system()} {platform.release()})")
response = litellm.completion(
model="gpt-4o",
messages=[
{"role": "user", "content": "This should never fail. Email ishaan@berri.ai if this test ever fails."}
],
mock_response="Hello, how are you?"
)
print(response)
except Exception as e:
pytest.fail(
f"Error occurred on Windows: {e}. Installing litellm on Windows failed."
)