(body: dict[str, Any], request: Request)
| 3055 | ) |
| 3056 | |
| 3057 | def _build_selector_preview(body: dict[str, Any], request: Request) -> dict[str, Any]: |
| 3058 | model = str(body.get("model") or "").strip().lower() |
| 3059 | routing_mode = routing_mode_from_model(model) |
| 3060 | if routing_mode is None: |
| 3061 | return { |
| 3062 | "virtual": False, |
| 3063 | "requested_model": model, |
| 3064 | "served_model": model, |
| 3065 | "reasoning": "passthrough", |
| 3066 | "selector": _selector_state(), |
| 3067 | } |
| 3068 | |
| 3069 | prompt, system_prompt, max_tokens = _extract_prompt(body) |
| 3070 | step_type, tool_names = _classify_step(body) |
| 3071 | routing_features = _extract_routing_features( |
| 3072 | body, |
| 3073 | step_type=step_type, |
| 3074 | tool_names=tool_names, |
| 3075 | prompt=prompt, |
| 3076 | max_output_tokens=max_tokens, |
| 3077 | session_id=_resolve_session_id(request, body), |
| 3078 | ) |
| 3079 | routing_features = _routing_features_with_quality_context( |
| 3080 | routing_features, |
| 3081 | api_format="openai", |
| 3082 | endpoint_name="chat_completions", |
| 3083 | session_id=_resolve_session_id(request, body), |
| 3084 | has_tools=bool(body.get("tools") or body.get("customTools")), |
| 3085 | ) |
| 3086 | ctx_features = extract_context_features(body, step_type, prompt) |
| 3087 | user_keyed = _providers.keyed_models() or None |
| 3088 | base_available_models = _mapper.routable_models if _mapper.discovered else list(DEFAULT_MODEL_PRICING.keys()) |
| 3089 | if user_keyed: |
| 3090 | base_available_models = _merge_available_models(base_available_models, sorted(user_keyed)) |
| 3091 | available_models = _circuit_breaker.filter_available(base_available_models) |
| 3092 | decision = route( |
| 3093 | prompt, |
| 3094 | system_prompt, |
| 3095 | max_tokens, |
| 3096 | config=_routing_config, |
| 3097 | routing_mode=routing_mode, |
| 3098 | routing_features=routing_features, |
| 3099 | user_keyed_models=user_keyed, |
| 3100 | model_experience=_model_experience, |
| 3101 | route_confidence_calibrator=_route_confidence, |
| 3102 | context_features=ctx_features, |
| 3103 | pricing=_get_pricing(), |
| 3104 | available_models=available_models or None, |
| 3105 | model_capabilities=_routing_config.model_capabilities, |
| 3106 | messages=body.get("messages"), |
| 3107 | record_lifecycle=False, |
| 3108 | ) |
| 3109 | reasoning = decision.reasoning |
| 3110 | |
| 3111 | effective_requirements = decision.routing_features.request_requirements() |
| 3112 | effective_hints = decision.routing_features.workload_hints() |
| 3113 | |
| 3114 | return { |
no test coverage detected