diff --git a/litellm/__init__.py b/litellm/__init__.py index e0fb010c1d4..8ae989d4e14 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -63,6 +63,7 @@ from litellm.constants import ( replicate_models, clarifai_models, huggingface_models, + modelscope_models, empower_models, together_ai_models, baseten_models, @@ -625,7 +626,6 @@ aiml_models: Set = set() deepgram_models: Set = set() elevenlabs_models: Set = set() dashscope_models: Set = set() -modelscope_models: Set = set() moonshot_models: Set = set() publicai_models: Set = set() v0_models: Set = set() diff --git a/litellm/llms/modelscope/chat/transformation.py b/litellm/llms/modelscope/chat/transformation.py index 9f26bee5f54..ddc72376f8f 100644 --- a/litellm/llms/modelscope/chat/transformation.py +++ b/litellm/llms/modelscope/chat/transformation.py @@ -2,7 +2,7 @@ Translates from OpenAI's `/v1/chat/completions` to ModelScope's `/v1/chat/completions` """ -from typing import Any, Coroutine, List, Literal, Optional, Tuple, Union, overload +from typing import Any, Coroutine, List, Literal, Optional, Tuple, Union, cast, overload from litellm.secret_managers.main import get_secret_str from litellm.types.llms.openai import AllMessageValues @@ -43,14 +43,13 @@ class ModelScopeChatConfig(OpenAIGPTConfig): Messages with non-text content (e.g. image_url for vision models) are kept as lists so the parent class can normalize them properly. """ + messages = [cast(AllMessageValues, {**m}) for m in messages] for message in messages: if _has_non_text_content(message): continue content = message.get("content") if isinstance(content, list): - message["content"] = "".join( - item.get("text") or "" for item in content - ) + message["content"] = "".join(item.get("text") or "" for item in content) if is_async: return super()._transform_messages( @@ -65,9 +64,7 @@ class ModelScopeChatConfig(OpenAIGPTConfig): self, api_base: Optional[str], api_key: Optional[str] ) -> Tuple[Optional[str], Optional[str]]: api_base = ( - api_base - or get_secret_str("MODELSCOPE_API_BASE") - or self.DEFAULT_BASE_URL + api_base or get_secret_str("MODELSCOPE_API_BASE") or self.DEFAULT_BASE_URL ) # type: ignore dynamic_api_key = api_key or get_secret_str("MODELSCOPE_API_KEY") return api_base, dynamic_api_key diff --git a/provider_endpoints_support.json b/provider_endpoints_support.json index b4f782f9c3e..517dd589302 100644 --- a/provider_endpoints_support.json +++ b/provider_endpoints_support.json @@ -1468,6 +1468,24 @@ "interactions": true } }, + "modelscope": { + "display_name": "ModelScope (`modelscope`)", + "url": "https://docs.litellm.ai/docs/providers/modelscope", + "endpoints": { + "chat_completions": true, + "messages": true, + "responses": true, + "embeddings": false, + "image_generations": true, + "audio_transcriptions": false, + "audio_speech": false, + "moderations": false, + "batches": false, + "rerank": false, + "a2a": false, + "interactions": false + } + }, "moonshot": { "display_name": "Moonshot (`moonshot`)", "url": "https://docs.litellm.ai/docs/providers/moonshot",