MCPcopy Create free account
hub / github.com/OpenDCAI/DataFlow-MM / switch_model

Method switch_model

dataflow/serving/lite_llm_serving.py:88–131  ·  view source on GitHub ↗

Switch to a different model with potentially different API configuration. Args: model: Model name to switch to key_name_of_api_key: New environment variable name for API key (optional) api_base: New API base URL (optional) api

(self, 
                     model: str,
                     key_name_of_api_key: Optional[str] = None,
                     api_base: Optional[str] = None,
                     api_version: Optional[str] = None,
                     **kwargs: Any)

Source from the content-addressed store, hash-verified

86 self.logger.info(f"LiteLLMServing initialized with model: {model}")
87
88 def switch_model(self,
89 model: str,
90 key_name_of_api_key: Optional[str] = None,
91 api_base: Optional[str] = None,
92 api_version: Optional[str] = None,
93 **kwargs: Any):
94 """
95 Switch to a different model with potentially different API configuration.
96
97 Args:
98 model: Model name to switch to
99 key_name_of_api_key: New environment variable name for API key (optional)
100 api_base: New API base URL (optional)
101 api_version: New API version (optional)
102 **kwargs: Additional parameters for the new model
103 """
104 # Update model
105 self.model = model
106
107 # Update API key if new environment variable provided
108 if key_name_of_api_key is not None:
109 self.api_key = os.environ.get(key_name_of_api_key)
110 if self.api_key is None:
111 error_msg = f"Lack of `{key_name_of_api_key}` in environment variables. Please set `{key_name_of_api_key}` as your api-key before switching model."
112 self.logger.error(error_msg)
113 raise ValueError(error_msg)
114 self.key_name_of_api_key = key_name_of_api_key
115
116 # Update other API configuration if provided
117 if api_base is not None:
118 self.api_base = api_base
119 if api_version is not None:
120 self.api_version = api_version
121
122 # Update other parameters from kwargs
123 for key, value in kwargs.items():
124 if hasattr(self, key):
125 setattr(self, key, value)
126 else:
127 self.kwargs[key] = value
128
129 # Validate the new configuration
130 self._validate_setup()
131 self.logger.success(f"Switched to model: {model}")
132
133 def format_response(self, response: Dict[str, Any]) -> str:
134 """

Callers

nothing calls this directly

Calls 2

_validate_setupMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected