The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Bug Fix] UnicodeDecodeError: 'charmap' on Windows during litellm import (#10542)
Ishaan Jaff7c4fae477aa5
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex 95984e4e68e..9fb1aeaf4f5 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -2,6 +2,7 @@ version: 2.1orbs:codecov: codecov/[email protected]node: circleci/[email protected] # Add this line to declare the node orb+ win: circleci/[email protected] # Add Windows orbcommands:setup_google_dns:@@ -17,6 +18,31 @@ commands:echo "nameserver 8.8.4.4" | sudo tee -a /etc/resolv.confjobs:+ # 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: 2build_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-+diff --git a/litellm/utils.py b/litellm/utils.pyindex 90f7b141519..2403ded78c9 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -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(diff --git a/tests/windows_tests/test_litellm_on_windows.py b/tests/windows_tests/test_litellm_on_windows.pynew file mode 100644index 00000000000..6f1e2ad1cd9--- /dev/null+++ b/tests/windows_tests/test_litellm_on_windows.py@@ -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 [email protected] 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."+ )+