Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(ml_inference): accept a fractional latency from the decision model (#106517)

Robbie453d866aa2e6
diff --git a/products/ml_inference/backend/facade/contracts.py b/products/ml_inference/backend/facade/contracts.py
index ab993b32a9e7..bc378ca638e3 100644
--- a/products/ml_inference/backend/facade/contracts.py
+++ b/products/ml_inference/backend/facade/contracts.py
@@ -95,4 +95,4 @@ class DecisionResult:
model: str
answers: dict[str, DecisionAnswer]
input_tokens: int
- latency_ms: int | None = None
+ latency_ms: float | None = None
diff --git a/products/ml_inference/backend/presentation/serializers.py b/products/ml_inference/backend/presentation/serializers.py
index b4d0c8da04b6..8295efedf8e8 100644
--- a/products/ml_inference/backend/presentation/serializers.py
+++ b/products/ml_inference/backend/presentation/serializers.py
@@ -122,4 +122,4 @@ class DecideResponseSerializer(serializers.Serializer):
help_text="One answer per question, under the ids the request used.",
)
input_tokens = serializers.IntegerField(help_text="Tokens the model read, which is what the request is billed on.")
- latency_ms = serializers.IntegerField(allow_null=True, help_text="Time the model spent answering, if reported.")
+ latency_ms = serializers.FloatField(allow_null=True, help_text="Time the model spent answering, if reported.")
diff --git a/products/ml_inference/backend/tests/test_logic.py b/products/ml_inference/backend/tests/test_logic.py
index 488d6cb188ce..b29ec7c46013 100644
--- a/products/ml_inference/backend/tests/test_logic.py
+++ b/products/ml_inference/backend/tests/test_logic.py
@@ -32,7 +32,7 @@ ANSWERS: dict[str, Any] = {
"mood": {"score": 2.5, "confidence": 0.4, "probabilities": {"1": 0.2, "2": 0.3, "3": 0.5}, "legend": {}},
},
"usage": {"input_tokens": 772, "output_tokens": 0},
- "latency_ms": 31,
+ "latency_ms": 41.25,
}
@@ -94,7 +94,7 @@ class TestDecide:
assert body["questions"]["urgent"] == {"type": "noul", "instructions": "Is it urgent?"}
assert body["questions"]["route"]["criteria"] == {"billing": "money", "bug": "broken"}
assert result.input_tokens == 772
- assert result.latency_ms == 31
+ assert result.latency_ms == 41.25
def test_parses_every_answer_type(self) -> None:
result = decisions.parse_result(ANSWERS, QUESTIONS)
diff --git a/products/ml_inference/backend/tests/test_presentation.py b/products/ml_inference/backend/tests/test_presentation.py
index 730c8edc9940..bdd441cacd33 100644
--- a/products/ml_inference/backend/tests/test_presentation.py
+++ b/products/ml_inference/backend/tests/test_presentation.py
@@ -106,7 +106,7 @@ class TestDecideEndpoint(APIBaseTest):
),
},
input_tokens=50,
- latency_ms=31,
+ latency_ms=31.5,
)
response = self.client.post(self._url(), {"state": "charged twice", "questions": QUESTIONS}, format="json")
@@ -123,6 +123,7 @@ class TestDecideEndpoint(APIBaseTest):
}
assert body["answers"]["queue"]["choice"] == "billing"
assert body["input_tokens"] == 50
+ assert body["latency_ms"] == 31.5
sent = decide.call_args.args[0]
assert sent.team_id == self.team.id
assert sent.questions["queue"].criteria == {"billing": "money", "support": "product"}
diff --git a/products/ml_inference/frontend/DecisionPlaygroundScene.tsx b/products/ml_inference/frontend/DecisionPlaygroundScene.tsx
index 05c0de469b94..db476271beb1 100644
--- a/products/ml_inference/frontend/DecisionPlaygroundScene.tsx
+++ b/products/ml_inference/frontend/DecisionPlaygroundScene.tsx
@@ -199,7 +199,7 @@ export function DecisionPlaygroundScene(): JSX.Element {
<p className="text-secondary text-xs mt-2">
Answered by {decision.model} from {decision.input_tokens} input tokens
{decision.latency_ms !== null && decision.latency_ms !== undefined
- ? ` in ${decision.latency_ms} ms`
+ ? ` in ${Math.round(decision.latency_ms)} ms`
: ''}
.
</p>