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

Function _make_feedback_app

tests/test_feedback.py:38–95  ·  view source on GitHub ↗
(
    monkeypatch: pytest.MonkeyPatch,
    *,
    feedback: FeedbackCollector | None = None,
)

Source from the content-addressed store, hash-verified

36
37
38def _make_feedback_app(
39 monkeypatch: pytest.MonkeyPatch,
40 *,
41 feedback: FeedbackCollector | None = None,
42) -> tuple[TestClient, httpx.AsyncClient]:
43 def fake_route(*args, **kwargs) -> RoutingDecision:
44 features = kwargs.get("routing_features") or RoutingFeatures()
45 return RoutingDecision(
46 model="minimax/minimax-m2.5",
47 tier=Tier.SIMPLE,
48 capability_lane=features.capability_lane or CapabilityLane.GENERAL,
49 served_quality=ServedQuality.ECONOMY,
50 served_quality_target=ServedQuality.ECONOMY,
51 served_quality_floor=ServedQuality.ECONOMY,
52 continuity_quality_floor=features.continuity_quality_floor,
53 mode=RoutingMode.AUTO,
54 confidence=0.91,
55 method="pool",
56 reasoning="test feedback route",
57 cost_estimate=0.001,
58 baseline_cost=0.004,
59 savings=0.75,
60 raw_confidence=0.91,
61 complexity=0.2,
62 routing_features=features,
63 )
64
65 def handler(request: httpx.Request) -> httpx.Response:
66 return httpx.Response(
67 200,
68 json={
69 "id": "chatcmpl_feedback",
70 "object": "chat.completion",
71 "created": 1,
72 "model": "minimax/minimax-m2.5",
73 "choices": [{
74 "index": 0,
75 "message": {"role": "assistant", "content": "ok"},
76 "finish_reason": "stop",
77 }],
78 "usage": {"prompt_tokens": 10, "completion_tokens": 1, "total_tokens": 11},
79 },
80 headers={"content-type": "application/json"},
81 )
82
83 async_client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
84 monkeypatch.setattr("uncommon_route.proxy._get_client", lambda: async_client)
85 monkeypatch.setattr("uncommon_route.proxy.route", fake_route)
86
87 app = create_app(
88 upstream="http://127.0.0.1:1/fake",
89 spend_control=SpendControl(storage=InMemorySpendControlStorage()),
90 route_stats=RouteStats(storage=InMemoryRouteStatsStorage()),
91 feedback=feedback or FeedbackCollector(),
92 trace_store=TraceStore(storage=InMemoryTraceStorage()),
93 connections_store=ConnectionsStore(storage=InMemoryConnectionsStorage()),
94 )
95 return TestClient(app, raise_server_exceptions=False), async_client

Calls 10

create_appFunction · 0.90
SpendControlClass · 0.90
RouteStatsClass · 0.90
FeedbackCollectorClass · 0.90
TraceStoreClass · 0.90
ConnectionsStoreClass · 0.90

Tested by

no test coverage detected