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

Function fetch_models_once

scripts/python_ui/streamlit.py:167–191  ·  view source on GitHub ↗

Fetch models once and cache the results.

()

Source from the content-addressed store, hash-verified

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