MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / fetch_models_once

Function fetch_models_once

scripts/python_ui/streamlit.py:168–192  ·  view source on GitHub ↗

Fetch models once and cache the results.

()

Source from the content-addressed store, hash-verified

166
167
168def fetch_models_once() -> Dict[str, List[str]]:
169 """Fetch models once and cache the results."""
170 logger.info("Fetching models")
171 current_time = time.time()
172 cache_timeout = 300 # 5 minutes
173
174 if (
175 st.session_state.cached_models is not None
176 and current_time - st.session_state.last_model_fetch < cache_timeout
177 ):
178 logger.debug("Using cached models")
179 return st.session_state.cached_models
180
181 logger.debug("Cache expired or not available, fetching new models")
182 success, stdout, stderr = safe_run_command(["fabric", "--listmodels"])
183 if not success:
184 logger.error(f"Failed to fetch models: {stderr}")
185 st.error(f"Failed to fetch models: {stderr}")
186 return {}
187
188 providers = parse_models_output(stdout)
189 logger.info(f"Found {len(providers)} providers")
190 st.session_state.cached_models = providers
191 st.session_state.last_model_fetch = current_time
192 return providers
193
194
195def get_configured_providers() -> Dict[str, List[str]]:

Callers 2

get_configured_providersFunction · 0.85

Calls 2

safe_run_commandFunction · 0.85
parse_models_outputFunction · 0.85

Tested by

no test coverage detected