MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / _fuzzy_match

Method _fuzzy_match

uncommon_route/model_map.py:448–493  ·  view source on GitHub ↗

Find the best-matching upstream model for *internal*. Scoring heuristic (highest wins, minimum 50 to accept): - Exact core name match: 100 - Normalized core name match: 90 - Substring containment: 70 * (shorter/longer) - Sam

(self, internal: str)

Source from the content-addressed store, hash-verified

446 return None
447
448 def _fuzzy_match(self, internal: str) -> str | None:
449 """Find the best-matching upstream model for *internal*.
450
451 Scoring heuristic (highest wins, minimum 50 to accept):
452 - Exact core name match: 100
453 - Normalized core name match: 90
454 - Substring containment: 70 * (shorter/longer)
455 - Same provider prefix bonus: +10
456 - Similar provider prefix bonus: +5
457 """
458 int_core = _core(internal)
459 int_norm = _normalize(int_core)
460 int_prov = _provider_prefix(internal)
461
462 best_score = 0
463 best: str | None = None
464
465 for upstream in self._upstream_models:
466 if is_routable_chat_model(internal) and not is_routable_chat_model(upstream):
467 continue
468 up_core = _core(upstream)
469 up_norm = _normalize(up_core)
470 up_prov = _provider_prefix(upstream)
471
472 if int_core == up_core:
473 score = 100
474 elif int_norm == up_norm:
475 score = 90
476 elif int_norm in up_norm or up_norm in int_norm:
477 longer = max(len(int_norm), len(up_norm))
478 shorter = min(len(int_norm), len(up_norm))
479 score = int(70 * (shorter / longer)) if longer else 0
480 else:
481 continue
482
483 if int_prov and up_prov:
484 if int_prov == up_prov:
485 score += 10
486 elif int_prov in up_prov or up_prov in int_prov:
487 score += 5
488
489 if score > best_score:
490 best_score = score
491 best = upstream
492
493 return best if best_score >= 50 else None
494
495 # ---- resolution -------------------------------------------------------
496

Callers 1

_build_mapMethod · 0.95

Calls 4

_coreFunction · 0.85
_normalizeFunction · 0.85
_provider_prefixFunction · 0.85
is_routable_chat_modelFunction · 0.85

Tested by

no test coverage detected