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
[LLM Translation] Change System prompts to assistant prompts as a workaround for GH Copilot (#12742)
Jugal D. Bhattc3c6255689f2
diff --git a/docs/my-website/docs/proxy/config_settings.md b/docs/my-website/docs/proxy/config_settings.mdindex 6bf425581dd..b1dfac9ac29 100644--- a/docs/my-website/docs/proxy/config_settings.md+++ b/docs/my-website/docs/proxy/config_settings.md@@ -76,6 +76,7 @@ litellm_settings:# /chat/completions, /completions, /embeddings, /audio/transcriptionsmode: default_off # if default_off, you need to opt in to caching on a per call basisttl: 600 # ttl for caching+ disable_copilot_system_to_assistant: False # If false (default), converts all 'system' role messages to 'assistant' for GitHub Copilot compatibility. Set to true to disable this behavior.callback_settings:@@ -142,6 +143,7 @@ general_settings:| disable_add_transform_inline_image_block | boolean | For Fireworks AI models - if true, turns off the auto-add of `#transform=inline` to the url of the image_url, if the model is not a vision model. || disable_hf_tokenizer_download | boolean | If true, it defaults to using the openai tokenizer for all models (including huggingface models). || enable_json_schema_validation | boolean | If true, enables json schema validation for all requests. |+| disable_copilot_system_to_assistant | boolean | If false (default), converts all 'system' role messages to 'assistant' for GitHub Copilot compatibility. Set to true to disable this behavior. Useful for tools (like Claude Code) that send system messages, which Copilot does not support. |### general_settings - Referencediff --git a/litellm/__init__.py b/litellm/__init__.pyindex 2e29deb45c9..6c851ab8b73 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -328,6 +328,9 @@ prometheus_metrics_config: Optional[List] = Nonedisable_add_prefix_to_prompt: bool = (False # used by anthropic, to disable adding prefix to prompt)+disable_copilot_system_to_assistant: bool = (+ False # If false (default), converts all 'system' role messages to 'assistant' for GitHub Copilot compatibility. Set to true to disable this behavior.+)public_model_groups: Optional[List[str]] = Nonepublic_model_groups_links: Dict[str, str] = {}#### REQUEST PRIORITIZATION #####diff --git a/litellm/llms/github_copilot/chat/transformation.py b/litellm/llms/github_copilot/chat/transformation.pyindex b104749e1ce..b0aaaf9a513 100644--- a/litellm/llms/github_copilot/chat/transformation.py+++ b/litellm/llms/github_copilot/chat/transformation.py@@ -35,3 +35,16 @@ class GithubCopilotConfig(OpenAIConfig):message=str(e),)return api_base, dynamic_api_key, custom_llm_provider++ def _transform_messages(+ self,+ messages,+ model: str,+ ):+ import litellm+ disable_copilot_system_to_assistant = litellm.disable_copilot_system_to_assistant+ if not disable_copilot_system_to_assistant:+ for message in messages:+ if "role" in message and message["role"] == "system":+ message["role"] = "assistant"+ return messagesdiff --git a/litellm/utils.py b/litellm/utils.pyindex c9c03ab2713..d37c4d741ea 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -6731,6 +6731,8 @@ class ProviderConfigManager:return litellm.EmpowerChatConfig()elif litellm.LlmProviders.GITHUB == provider:return litellm.GithubChatConfig()+ elif litellm.LlmProviders.GITHUB_COPILOT == provider:+ return litellm.GithubCopilotConfig()elif (litellm.LlmProviders.CUSTOM == provideror litellm.LlmProviders.CUSTOM_OPENAI == providerdiff --git a/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py b/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.pyindex 7f61248c09d..9672f045df6 100644--- a/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py+++ b/tests/test_litellm/llms/github_copilot/test_github_copilot_transformation.py@@ -126,3 +126,38 @@ def test_completion_github_copilot_mock_response(mock_completion, mock_get_api_kassert kwargs.get("messages") == messages+def test_transform_messages_disable_copilot_system_to_assistant(monkeypatch):+ """Test that system messages are converted to assistant unless disable_copilot_system_to_assistant is True."""+ from litellm.llms.github_copilot.chat.transformation import GithubCopilotConfig+ import litellm++ # Save original value+ original_flag = litellm.disable_copilot_system_to_assistant+ try:+ # Case 1: Flag is False (default, conversion happens)+ litellm.disable_copilot_system_to_assistant = False+ config = GithubCopilotConfig()+ messages = [+ {"role": "system", "content": "System message."},+ {"role": "user", "content": "User message."},+ ]+ out = config._transform_messages([m.copy() for m in messages], model="github_copilot/gpt-4")+ assert out[0]["role"] == "assistant"+ assert out[1]["role"] == "user"++ # Case 2: Flag is True (conversion does not happen)+ litellm.disable_copilot_system_to_assistant = True+ out = config._transform_messages([m.copy() for m in messages], model="github_copilot/gpt-4")+ assert out[0]["role"] == "system"+ assert out[1]["role"] == "user"++ # Case 3: Flag is False again (conversion happens)+ litellm.disable_copilot_system_to_assistant = False+ out = config._transform_messages([m.copy() for m in messages], model="github_copilot/gpt-4")+ assert out[0]["role"] == "assistant"+ assert out[1]["role"] == "user"+ finally:+ # Restore original value+ litellm.disable_copilot_system_to_assistant = original_flag++