MCPcopy Create free account
hub / github.com/aigc3d/LHM / query

Method query

LHM/utils/model_query_utils.py:93–123  ·  view source on GitHub ↗

Query the best available model for current memory conditions. Args: model_name (str): The preferred model name to try first Returns: str: Name of the selected model Raises: KeyError: If requested model is

(self, model_name)

Source from the content-addressed store, hash-verified

91 return available_memory
92
93 def query(self, model_name):
94 """Query the best available model for current memory conditions.
95
96 Args:
97 model_name (str): The preferred model name to try first
98
99 Returns:
100 str: Name of the selected model
101
102 Raises:
103 KeyError: If requested model is not in the configuration
104 ValueError: If no suitable model can be found
105 """
106 if model_name not in self.model_requirements:
107 raise KeyError(f"Model '{model_name}' not found in configuration")
108
109 available_mb = self.available_mb - self.extra_memory
110 required_mb = self.model_requirements[model_name]
111
112 # Return preferred model if sufficient memory
113 if available_mb >= required_mb:
114 return model_name
115
116 # Find the best alternative model
117 for name, req in self.sorted_models:
118 if req <= available_mb:
119 print(f"Insufficient memory, switching to largest available model: "
120 f"{model_name} -> {name}")
121 return name
122
123 raise ValueError("No available model meets current memory constraints")
124
125 def get_available_models(self):
126 """Get list of currently available models sorted by priority.

Callers 3

launch_gradio_appFunction · 0.95
launch_gradio_appFunction · 0.95
launch_gradio_appFunction · 0.95

Calls 1

printFunction · 0.85

Tested by

no test coverage detected