: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(ml_inference): ask the AI gateway for JevK5 instead of Kev (#106029)
Robbie2d88bf768f5e
diff --git a/products/ml_inference/backend/facade/contracts.py b/products/ml_inference/backend/facade/contracts.pyindex eed7fb610981..42d9fcaed160 100644--- a/products/ml_inference/backend/facade/contracts.py+++ b/products/ml_inference/backend/facade/contracts.py@@ -8,7 +8,7 @@ from pydantic.dataclasses import dataclassfrom .enums import DecisionQuestionType-DEFAULT_DECISION_MODEL = "posthog/posthog/decision-4b"+DEFAULT_DECISION_MODEL = "posthog/alibiserikbay/jevk5-0.2"class DecisionsDisabledError(Exception):@@ -33,6 +33,8 @@ class DecisionGatewayError(Exception):MAX_QUESTIONS_PER_REQUEST = 32+# JevK5 answers with one letter per option, A to P.+MAX_OPTIONS_PER_QUESTION = 16@dataclass(frozen=True)@@ -50,6 +52,8 @@ class DecisionQuestion:raise ValueError("a choice question needs its options as criteria, keyed by name")if self.type == DecisionQuestionType.NOUL and isinstance(self.criteria, list):raise ValueError("a yes/no question takes criteria keyed by name, not a list")+ if self.criteria is not None and len(self.criteria) > MAX_OPTIONS_PER_QUESTION:+ raise ValueError(f"a question takes at most {MAX_OPTIONS_PER_QUESTION} options")@dataclass(frozen=True)diff --git a/products/ml_inference/backend/presentation/serializers.py b/products/ml_inference/backend/presentation/serializers.pyindex f162cc98f87b..b4d0c8da04b6 100644--- a/products/ml_inference/backend/presentation/serializers.py+++ b/products/ml_inference/backend/presentation/serializers.py@@ -3,12 +3,11 @@ from typing import Anyfrom drf_spectacular.utils import extend_schema_fieldfrom rest_framework import serializers-from ..facade.contracts import DEFAULT_DECISION_MODEL, MAX_QUESTIONS_PER_REQUEST+from ..facade.contracts import DEFAULT_DECISION_MODEL, MAX_OPTIONS_PER_QUESTION, MAX_QUESTIONS_PER_REQUESTfrom ..facade.enums import DecisionQuestionTypeMAX_STATE_CHARS = 65_536MAX_INSTRUCTIONS_CHARS = 2_000-MAX_OPTIONS_PER_QUESTION = 255MAX_OPTION_CHARS = 500diff --git a/products/ml_inference/backend/tests/test_api.py b/products/ml_inference/backend/tests/test_api.pyindex ce4c2d832683..49f17f397d0b 100644--- a/products/ml_inference/backend/tests/test_api.py+++ b/products/ml_inference/backend/tests/test_api.py@@ -31,6 +31,6 @@ class TestDecideFacade:@patch("products.ml_inference.backend.logic.decisions.decide")@patch("products.ml_inference.backend.logic.decisions.decisions_enabled", return_value=False)def test_unchecked_path_skips_enrollment(self, _enabled, decide) -> None:- decide.return_value = DecisionResult(model="kev-4b", answers={}, input_tokens=1)+ decide.return_value = DecisionResult(model="jevk5-0.2", answers={}, input_tokens=1)- assert api.decide_unchecked(_request()).model == "kev-4b"+ assert api.decide_unchecked(_request()).model == "jevk5-0.2"diff --git a/products/ml_inference/backend/tests/test_logic.py b/products/ml_inference/backend/tests/test_logic.pyindex b3e448df0f84..865c2148f683 100644--- a/products/ml_inference/backend/tests/test_logic.py+++ b/products/ml_inference/backend/tests/test_logic.py@@ -25,7 +25,7 @@ from products.ml_inference.backend.logic import decisionsGATEWAY = {"AI_GATEWAY_URL": "https://gateway.example.com/v1", "AI_GATEWAY_API_KEY": "phs_test"}ANSWERS: dict[str, Any] = {- "model": "kev-latest",+ "model": "jevk5-0.2","answers": {"urgent": {"noul": 0.91},"route": {"choice": "billing", "confidence": 0.6, "probabilities": {"billing": 0.7, "bug": 0.3}},@@ -57,6 +57,17 @@ def test_a_request_refuses_more_questions_than_the_cap() -> None:DecisionRequest(team_id=1, state="text", questions={f"q{i}": question for i in range(33)})+ "criteria",+ [{str(i): "m" for i in range(17)}, [str(i) for i in range(17)]],+ ids=["choice", "score"],+)+def test_a_question_refuses_more_options_than_the_model_has_letters(criteria: dict[str, str] | list[str]) -> None:+ question_type = DecisionQuestionType.CHOICE if isinstance(criteria, dict) else DecisionQuestionType.SCORE+ with pytest.raises(ValueError, match="at most 16 options"):+ DecisionQuestion(type=question_type, instructions="?", criteria=criteria)++class TestDecide:@pytest.mark.parametrize("gateway_url",@@ -78,7 +89,7 @@ class TestDecide:assert json.loads(request.headers["X-PostHog-Properties"]) == {"ai_product": "ml_inference"}assert request.headers["X-PostHog-Distinct-Id"] == "team-42"body = json.loads(request.content)- assert body["model"] == "posthog/posthog/decision-4b"+ assert body["model"] == "posthog/alibiserikbay/jevk5-0.2"assert body["state"] == "ticket text"assert body["questions"]["urgent"] == {"type": "noul", "instructions": "Is it urgent?"}assert body["questions"]["route"]["criteria"] == {"billing": "money", "bug": "broken"}@@ -101,9 +112,9 @@ class TestDecide:[{},[],- {"model": "kev-latest", "answers": {}, "usage": {}},- {"model": "kev-latest", "answers": {"q": {"verdict": "maybe"}}, "usage": {"input_tokens": 1}},- {"model": "kev-latest", "answers": {"q": "yes"}, "usage": {"input_tokens": 1}},+ {"model": "jevk5-0.2", "answers": {}, "usage": {}},+ {"model": "jevk5-0.2", "answers": {"q": {"verdict": "maybe"}}, "usage": {"input_tokens": 1}},+ {"model": "jevk5-0.2", "answers": {"q": "yes"}, "usage": {"input_tokens": 1}},{**ANSWERS, "answers": {**ANSWERS["answers"], "extra": {"noul": 0.5}}},{**ANSWERS, "answers": {k: v for k, v in ANSWERS["answers"].items() if k != "mood"}},{**ANSWERS, "answers": {**ANSWERS["answers"], "urgent": {"noul": 0.9, "choice": "billing"}}},@@ -145,7 +156,7 @@ class TestDecide:with override_settings(AI_GATEWAY_URL=gateway_url, AI_GATEWAY_API_KEY="phs_test"):if allowed:- assert decisions.decide(_request(), transport=transport).model == "kev-latest"+ assert decisions.decide(_request(), transport=transport).model == "jevk5-0.2"else:with pytest.raises(GatewayNotConfiguredError):decisions.decide(_request(), transport=transport)diff --git a/products/ml_inference/backend/tests/test_presentation.py b/products/ml_inference/backend/tests/test_presentation.pyindex db2ea3934986..7ee21490b633 100644--- a/products/ml_inference/backend/tests/test_presentation.py+++ b/products/ml_inference/backend/tests/test_presentation.py@@ -66,7 +66,7 @@ class TestDecideRequestValidation(SimpleTestCase):{"state": "text","questions": {- "q": {"type": "choice", "instructions": "?", "criteria": {str(i): "m" for i in range(256)}}+ "q": {"type": "choice", "instructions": "?", "criteria": {str(i): "m" for i in range(17)}}},},),@@ -88,7 +88,7 @@ class TestDecideRequestValidation(SimpleTestCase):serializer = DecideRequestSerializer(data={"state": "text", "questions": QUESTIONS})assert serializer.is_valid(), serializer.errors- assert serializer.validated_data["model"] == "posthog/posthog/decision-4b"+ assert serializer.validated_data["model"] == "posthog/alibiserikbay/jevk5-0.2"class TestDecideEndpoint(APIBaseTest):@@ -98,7 +98,7 @@ class TestDecideEndpoint(APIBaseTest):@patch("products.ml_inference.backend.presentation.views.api.decide")def test_returns_typed_answers(self, decide) -> None:decide.return_value = DecisionResult(- model="kev-4b",+ model="jevk5-0.2",answers={"urgent": NoulAnswer(probability=0.94),"queue": ChoiceAnswer(diff --git a/products/ml_inference/frontend/DecisionPlayground.stories.tsx b/products/ml_inference/frontend/DecisionPlayground.stories.tsxindex 05a39cb6cc11..d4a5e148b7b2 100644--- a/products/ml_inference/frontend/DecisionPlayground.stories.tsx+++ b/products/ml_inference/frontend/DecisionPlayground.stories.tsx@@ -11,7 +11,7 @@ const answered = mswDecorator({'api/projects/:team_id/ml_inference/decisions/decide/': [200,{- model: 'kev-4b',+ model: 'jevk5-0.2',answers: {acceptable: {type: 'noul',diff --git a/products/ml_inference/frontend/DecisionPlaygroundScene.tsx b/products/ml_inference/frontend/DecisionPlaygroundScene.tsxindex 7a51df7533f1..05c0de469b94 100644--- a/products/ml_inference/frontend/DecisionPlaygroundScene.tsx+++ b/products/ml_inference/frontend/DecisionPlaygroundScene.tsx@@ -26,6 +26,7 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'import { DecisionAnswerCell } from './DecisionAnswerCell'import {+ MAX_OPTIONS_PER_QUESTION,PlaygroundOption,PlaygroundQuestion,PlaygroundQuestionType,@@ -273,6 +274,11 @@ function QuestionRow({size="small"icon={<IconPlus />}onClick={onAddOption}+ disabledReason={+ question.options.length >= MAX_OPTIONS_PER_QUESTION+ ? `A question takes at most ${MAX_OPTIONS_PER_QUESTION} options.`+ : undefined+ }data-attr="decision-playground-add-option">{question.type === 'choice' ? 'Add option' : 'Add label'}diff --git a/products/ml_inference/frontend/decisionPlaygroundLogic.test.ts b/products/ml_inference/frontend/decisionPlaygroundLogic.test.tsindex 1573f534c432..25b8c71abee2 100644--- a/products/ml_inference/frontend/decisionPlaygroundLogic.test.ts+++ b/products/ml_inference/frontend/decisionPlaygroundLogic.test.ts@@ -77,6 +77,16 @@ describe('decisionPlaygroundLogic request building', () => {['{"tone": {"type": "score", "instructions": "?", "criteria": {"a": "b"}}}', 'criteria must be a list'],['{"tone": {"type": "score", "instructions": "?", "criteria": ["calm", null]}}', 'scale label 2 must be text'],['{"queue": {"type": "choice", "instructions": "?", "criteria": {"a": {"b": 1}}}}', 'option "a" must be text'],+ [+ JSON.stringify({+ tone: {+ type: 'score',+ instructions: '?',+ criteria: Array.from({ length: 17 }, (_, level) => `level ${level}`),+ },+ }),+ 'takes at most 16 options',+ ],])('rejects %s with a message naming the problem', (text, message) => {expect(() => questionsFromJson(text)).toThrow(message)})diff --git a/products/ml_inference/frontend/decisionPlaygroundLogic.ts b/products/ml_inference/frontend/decisionPlaygroundLogic.tsindex 64defdda2492..d817b96074e9 100644--- a/products/ml_inference/frontend/decisionPlaygroundLogic.ts+++ b/products/ml_inference/frontend/decisionPlaygroundLogic.ts@@ -10,6 +10,8 @@ export type PlaygroundQuestionType = 'noul' | 'choice' | 'score'export type QuestionsView = 'form' | 'json'const QUESTION_TYPES: PlaygroundQuestionType[] = ['noul', 'choice', 'score']+// Mirrors MAX_OPTIONS_PER_QUESTION in the backend serializer: the model answers with one letter per option, A to P.+export const MAX_OPTIONS_PER_QUESTION = 16export interface PlaygroundOption {key: string@@ -157,7 +159,11 @@ export function questionsFromJson(text: string): PlaygroundQuestion[] {throw new Error(`Question "${key}" needs instructions`)}const questionType = type as PlaygroundQuestionType- return { key, type: questionType, instructions, options: optionsFromCriteria(key, questionType, criteria) }+ const options = optionsFromCriteria(key, questionType, criteria)+ if (options.length > MAX_OPTIONS_PER_QUESTION) {+ throw new Error(`Question "${key}" takes at most ${MAX_OPTIONS_PER_QUESTION} options`)+ }+ return { key, type: questionType, instructions, options }})}diff --git a/products/ml_inference/frontend/generated/api.zod.ts b/products/ml_inference/frontend/generated/api.zod.tsindex 2dfa8e3f9c47..9a513c53deeb 100644--- a/products/ml_inference/frontend/generated/api.zod.ts+++ b/products/ml_inference/frontend/generated/api.zod.ts@@ -17,7 +17,7 @@ export const mlInferenceDecisionsDecideCreateBodyStateMax = 65536export const mlInferenceDecisionsDecideCreateBodyQuestionsInstructionsMax = 2000-export const mlInferenceDecisionsDecideCreateBodyModelDefault = `posthog/posthog/decision-4b`+export const mlInferenceDecisionsDecideCreateBodyModelDefault = `posthog/alibiserikbay/jevk5-0.2`export const mlInferenceDecisionsDecideCreateBodyModelMax = 200export const MlInferenceDecisionsDecideCreateBody = /* @__PURE__ */ zod.object({