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.

chore(slack-app): drop the legacy gateway fallback from classifiers and reply suggestions (#128203)

Jonathan Mielood034ea10a66f
diff --git a/posthog/llm/gateway_client.py b/posthog/llm/gateway_client.py
index e91f3f64d4a3..bb475420fda1 100644
--- a/posthog/llm/gateway_client.py
+++ b/posthog/llm/gateway_client.py
@@ -479,6 +479,7 @@ def build_ai_gateway_openai_client(
api_key: str,
ai_product: str,
trace_id: str | None = None,
+ session_id: str | None = None,
properties: Mapping[str, str] | None = None,
distinct_id: str | None = None,
) -> OpenAI:
@@ -496,6 +497,7 @@ def build_ai_gateway_openai_client(
default_headers=ai_gateway_headers(
ai_product=ai_product,
trace_id=trace_id,
+ session_id=session_id,
properties=properties,
distinct_id=distinct_id,
),
diff --git a/posthog/llm/test_gateway_client.py b/posthog/llm/test_gateway_client.py
index c64d113c10ab..a9b0395573c6 100644
--- a/posthog/llm/test_gateway_client.py
+++ b/posthog/llm/test_gateway_client.py
@@ -576,6 +576,7 @@ class TestBuildAIGatewayOpenAIClient:
result = build_ai_gateway_openai_client(
api_key="pha_user_token",
ai_product="custom_image_scans",
+ session_id="session-42",
properties={"team_id": "42"},
distinct_id="team-42",
)
@@ -587,6 +588,7 @@ class TestBuildAIGatewayOpenAIClient:
headers = kwargs["default_headers"]
assert headers["X-PostHog-Product"] == "custom_image_scans"
assert headers["X-PostHog-Distinct-Id"] == "team-42"
+ assert headers["X-PostHog-Session-Id"] == "session-42"
assert json.loads(headers["X-PostHog-Properties"]) == {"ai_product": "custom_image_scans", "team_id": "42"}
assert result is mock_openai.return_value
diff --git a/products/slack_app/backend/logic/reply_suggestions.py b/products/slack_app/backend/logic/reply_suggestions.py
index 6005e09f5433..5c63529c4ce4 100644
--- a/products/slack_app/backend/logic/reply_suggestions.py
+++ b/products/slack_app/backend/logic/reply_suggestions.py
@@ -3,6 +3,7 @@
import json
from typing import Any
+from django.conf import settings
from django.core.cache import cache
import structlog
@@ -10,7 +11,7 @@ from openai.types.shared_params import ResponseFormatJSONSchema
from slack_sdk import WebClient
from posthog.dataclasses import frozen
-from posthog.llm.gateway_client import build_openai_client
+from posthog.llm.gateway_client import build_ai_gateway_openai_client
from posthog.llm.semantic_enrichment import extract_json_object
from posthog.slack.channels import clip_text
@@ -198,8 +199,8 @@ def request_reply_suggestions(
properties["task_id"] = attribution.task_id
if attribution.run_id:
properties["run_id"] = attribution.run_id
- client = build_openai_client(
- product="slack_app_routing",
+ client = build_ai_gateway_openai_client(
+ settings.AI_GATEWAY_API_KEY,
ai_product="slack_app_routing",
trace_id=attribution.trace_id,
session_id=attribution.session_id,
diff --git a/products/slack_app/backend/temporal/activities/classifiers.py b/products/slack_app/backend/temporal/activities/classifiers.py
index ce04d750dbe8..92b733d3ffc5 100644
--- a/products/slack_app/backend/temporal/activities/classifiers.py
+++ b/products/slack_app/backend/temporal/activities/classifiers.py
@@ -2,12 +2,20 @@ import re
from collections.abc import Sequence
from pathlib import Path
+from django.conf import settings
+
import structlog
+from openai import OpenAI
from openai.types.shared_params import ReasoningEffort, ResponseFormatJSONSchema
from pydantic import BaseModel, ValidationError
from temporalio import activity
-from posthog.llm.gateway_client import Product, build_anthropic_client, build_openai_client, trace_id_from_seed
+from posthog.llm.gateway_client import (
+ GatewayNotConfiguredError,
+ build_ai_gateway_anthropic_client,
+ build_ai_gateway_openai_client,
+ trace_id_from_seed,
+)
from posthog.llm.semantic_enrichment import extract_json_object
from posthog.models.integration import SlackIntegration
from posthog.models.repo_routing_rule import RepoRoutingRule
@@ -50,9 +58,6 @@ CLASSIFIER_MODEL = "claude-haiku-4-5-20251001"
# The classifiers bill the customer's PostHog AI credits, the same as the Slack agent's runs,
# so they share its product.
CLASSIFIER_AI_PRODUCT = "slack_app"
-# The Python gateway's `slack_app` route refuses API keys, so its fallback keeps the
-# `slack_app_routing` route, which accepts them. The usage report does not bill that route.
-CLASSIFIER_FALLBACK_ROUTE: Product = "slack_app_routing"
# Every classifier here and every Slack agent run share `ai_product="slack_app"`, so the captured
# generation carries this property to say which classifier made the call. An online evaluation
@@ -69,6 +74,15 @@ def _classifier_properties(classifier: str, team_id: int | None) -> dict[str, st
return properties
+def _classifier_openai_client(classifier: str, team_id: int | None, trace_id: str | None) -> OpenAI:
+ return build_ai_gateway_openai_client(
+ settings.AI_GATEWAY_API_KEY,
+ ai_product=CLASSIFIER_AI_PRODUCT,
+ trace_id=trace_id,
+ properties=_classifier_properties(classifier, team_id),
+ )
+
+
def _thread_trace_id(slack_team_id: str | None, thread_ts: str | None) -> str | None:
"""Group one Slack thread's routing calls into a single trace.
@@ -235,8 +249,7 @@ def classify_task_needs_repo(
)
try:
# The Go gateway refuses a Claude model on chat completions.
- client = build_anthropic_client(
- product=CLASSIFIER_FALLBACK_ROUTE,
+ client = build_ai_gateway_anthropic_client(
ai_product=CLASSIFIER_AI_PRODUCT,
trace_id=trace_id,
properties=_classifier_properties("task_needs_repo", team_id),
@@ -363,12 +376,9 @@ def classify_message_is_agent_directed(
event_text=event_text,
)
try:
- client = build_openai_client(
- product=CLASSIFIER_FALLBACK_ROUTE,
- ai_product=CLASSIFIER_AI_PRODUCT,
- trace_id=trace_id,
- properties=_classifier_properties("agent_directed", team_id),
- ).with_options(timeout=AGENT_DIRECTED_TIMEOUT_SECONDS, max_retries=AGENT_DIRECTED_MAX_RETRIES)
+ client = _classifier_openai_client("agent_directed", team_id, trace_id).with_options(
+ timeout=AGENT_DIRECTED_TIMEOUT_SECONDS, max_retries=AGENT_DIRECTED_MAX_RETRIES
+ )
response = client.chat.completions.create(
model=AGENT_DIRECTED_CLASSIFIER_MODEL,
messages=[{"role": "user", "content": prompt}],
@@ -542,12 +552,9 @@ def classify_slack_app_model_override(
)
try:
- client = build_openai_client(
- product=CLASSIFIER_FALLBACK_ROUTE,
- ai_product=CLASSIFIER_AI_PRODUCT,
- trace_id=trace_id,
- properties=_classifier_properties("model_override", team_id),
- ).with_options(timeout=MODEL_OVERRIDE_TIMEOUT_SECONDS, max_retries=MODEL_OVERRIDE_MAX_RETRIES)
+ client = _classifier_openai_client("model_override", team_id, trace_id).with_options(
+ timeout=MODEL_OVERRIDE_TIMEOUT_SECONDS, max_retries=MODEL_OVERRIDE_MAX_RETRIES
+ )
response = client.chat.completions.create(
model=MODEL_OVERRIDE_CLASSIFIER_MODEL,
messages=[{"role": "user", "content": prompt}],
@@ -562,6 +569,9 @@ def classify_slack_app_model_override(
# but the model is still the classifier's word, not ours, until checked against
# the catalogue below.
reply = SlackAppModelOverride.model_validate(parsed)
+ except GatewayNotConfiguredError:
+ logger.exception("slack_app_model_override_classify_failed")
+ return None
except (ValidationError, ValueError):
logger.info("slack_app_model_override_unusable_reply")
return None
@@ -695,13 +705,10 @@ def classify_slack_app_project_route(
event_text=event_text,
)
+ client = _classifier_openai_client("project_route", team_id, trace_id).with_options(
+ timeout=PROJECT_ROUTE_TIMEOUT_SECONDS, max_retries=PROJECT_ROUTE_MAX_RETRIES
+ )
try:
- client = build_openai_client(
- product=CLASSIFIER_FALLBACK_ROUTE,
- ai_product=CLASSIFIER_AI_PRODUCT,
- trace_id=trace_id,
- properties=_classifier_properties("project_route", team_id),
- ).with_options(timeout=PROJECT_ROUTE_TIMEOUT_SECONDS, max_retries=PROJECT_ROUTE_MAX_RETRIES)
response = client.chat.completions.create(
model=PROJECT_ROUTE_CLASSIFIER_MODEL,
messages=[{"role": "user", "content": prompt}],
diff --git a/products/slack_app/backend/temporal/tests/activities/test_classifier_gateway_routing.py b/products/slack_app/backend/temporal/tests/activities/test_classifier_gateway_routing.py
index 172b7daf1c09..f94e9c3f368e 100644
--- a/products/slack_app/backend/temporal/tests/activities/test_classifier_gateway_routing.py
+++ b/products/slack_app/backend/temporal/tests/activities/test_classifier_gateway_routing.py
@@ -1,11 +1,14 @@
import json
+from contextlib import suppress
+import pytest
from unittest.mock import MagicMock, patch
from django.test import override_settings
from parameterized import parameterized
+from posthog.llm.gateway_client import GatewayNotConfiguredError
from posthog.models.integration import Integration
from posthog.models.organization import Organization
from posthog.models.team.team import Team
@@ -118,14 +121,12 @@ class TestClassifierGatewayRouting:
@patch("posthog.llm.gateway_client.httpx.Client")
@patch("posthog.llm.gateway_client.Anthropic")
- def test_needs_repo_falls_back_to_python_route_when_unset(self, mock_anthropic, _mock_httpx):
+ def test_needs_repo_never_reaches_the_python_route(self, mock_anthropic, _mock_httpx):
_messages_reply(mock_anthropic, '{"needs_repo": true}')
with override_settings(**PYTHON_GATEWAY):
- assert _classify_needs_repo() is True
+ assert _classify_needs_repo() is False
- kwargs = mock_anthropic.call_args.kwargs
- assert kwargs["base_url"] == f"{LLM_GATEWAY_URL}/slack_app_routing"
- assert kwargs["api_key"] == LLM_GATEWAY_KEY
+ mock_anthropic.assert_not_called()
@parameterized.expand(OPENAI_CLASSIFIERS)
@patch("posthog.llm.gateway_client.httpx.Client")
@@ -143,13 +144,17 @@ class TestClassifierGatewayRouting:
@parameterized.expand(OPENAI_CLASSIFIERS)
@patch("posthog.llm.gateway_client.httpx.Client")
@patch("posthog.llm.gateway_client.OpenAI")
- def test_openai_classifier_falls_back_to_python_route_when_unset(
- self, _name, classify, reply, mock_openai, _mock_httpx
- ):
+ def test_openai_classifier_never_reaches_the_python_route(self, _name, classify, reply, mock_openai, _mock_httpx):
_chat_reply(mock_openai, reply)
- with override_settings(**PYTHON_GATEWAY):
- assert classify()
+ with override_settings(**PYTHON_GATEWAY), suppress(GatewayNotConfiguredError):
+ classify()
- kwargs = mock_openai.call_args.kwargs
- assert kwargs["base_url"] == f"{LLM_GATEWAY_URL}/slack_app_routing/v1"
- assert kwargs["api_key"] == LLM_GATEWAY_KEY
+ mock_openai.assert_not_called()
+
+ @patch("posthog.llm.gateway_client.httpx.Client")
+ @patch("posthog.llm.gateway_client.OpenAI")
+ def test_project_route_raises_without_the_go_gateway(self, mock_openai, _mock_httpx):
+ with override_settings(**PYTHON_GATEWAY), pytest.raises(GatewayNotConfiguredError):
+ _classify_project_route()
+
+ mock_openai.assert_not_called()
diff --git a/products/slack_app/backend/temporal/tests/activities/test_classify_message_is_agent_directed.py b/products/slack_app/backend/temporal/tests/activities/test_classify_message_is_agent_directed.py
index 8aa8a5ce8674..8f8e2fa210bc 100644
--- a/products/slack_app/backend/temporal/tests/activities/test_classify_message_is_agent_directed.py
+++ b/products/slack_app/backend/temporal/tests/activities/test_classify_message_is_agent_directed.py
@@ -17,7 +17,9 @@ THREAD = [
class TestClassifyMessageIsAgentDirected:
def test_emoji_only_is_dropped_without_paying_for_the_model(self):
- with patch("products.slack_app.backend.temporal.activities.classifiers.build_openai_client") as get_client:
+ with patch(
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client"
+ ) as get_client:
assert classify_message_is_agent_directed(":thumbsup: :tada:", TASK_TITLE, THREAD) is False
get_client.assert_not_called()
@@ -40,7 +42,7 @@ class TestClassifyMessageIsAgentDirected:
client = self._fake_client("")
client.chat.completions.create.side_effect = RuntimeError("boom")
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=client,
):
assert classify_message_is_agent_directed("also check the breakpoint", TASK_TITLE, THREAD) is False
@@ -50,7 +52,7 @@ class TestClassifyMessageIsAgentDirected:
# the reply is lost outright instead of taking the drop this is built around.
client = self._fake_client('{"agent_directed": false}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=client,
):
classify_message_is_agent_directed("lunch in 5?", TASK_TITLE, THREAD)
@@ -64,7 +66,7 @@ class TestClassifyMessageIsAgentDirected:
# A rejected `max_tokens` would read as "not agent directed" on every untagged reply.
client = self._fake_client('{"agent_directed": false}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=client,
):
classify_message_is_agent_directed("lunch in 5?", TASK_TITLE, THREAD)
@@ -78,7 +80,7 @@ class TestClassifyMessageIsAgentDirected:
# reasoning — prose parses to nothing, which reads as a refused call.
client = self._fake_client('{"agent_directed": false}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=client,
):
classify_message_is_agent_directed("lunch in 5?", TASK_TITLE, THREAD)
@@ -108,7 +110,7 @@ class TestClassifyMessageIsAgentDirected:
def _render_prompt(self, text: str) -> str:
client = self._fake_client('{"agent_directed": false}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=client,
):
classify_message_is_agent_directed(text, TASK_TITLE, THREAD)
@@ -116,7 +118,7 @@ class TestClassifyMessageIsAgentDirected:
def _classify(self, text: str, content: str) -> bool:
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=self._fake_client(content),
):
return classify_message_is_agent_directed(text, TASK_TITLE, THREAD)
diff --git a/products/slack_app/backend/temporal/tests/activities/test_classify_slack_app_model_override.py b/products/slack_app/backend/temporal/tests/activities/test_classify_slack_app_model_override.py
index 9cb25243ef2f..ca1c47fdb68f 100644
--- a/products/slack_app/backend/temporal/tests/activities/test_classify_slack_app_model_override.py
+++ b/products/slack_app/backend/temporal/tests/activities/test_classify_slack_app_model_override.py
@@ -2,6 +2,8 @@ from unittest.mock import MagicMock, patch
from parameterized import parameterized
+from posthog.llm.gateway_client import GatewayNotConfiguredError
+
from products.slack_app.backend.services.model_catalogue import ModelChoice
from products.slack_app.backend.temporal.activities.classifiers import classify_slack_app_model_override
from products.slack_app.backend.temporal.slack_app_mention_processing import POSTHOG_CODE_SLACK_MENTION_TIMEOUT_SECONDS
@@ -72,13 +74,24 @@ class TestClassifySlackAppModelOverride:
def test_returns_none(self, _name, content):
assert self._classify("use fable for this", content) is None
- def test_llm_failure_falls_back_to_no_override(self):
- with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
- side_effect=RuntimeError("boom"),
+ @parameterized.expand(
+ [
+ ("gateway_error", RuntimeError("boom")),
+ ("gateway_unconfigured", GatewayNotConfiguredError("AI_GATEWAY_URL is not set")),
+ ]
+ )
+ def test_llm_failure_falls_back_to_no_override(self, _name, error):
+ with (
+ patch(
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
+ side_effect=error,
+ ),
+ patch("products.slack_app.backend.temporal.activities.classifiers.logger") as logger,
):
assert classify_slack_app_model_override("use fable for this", CHOICES) is None
+ logger.exception.assert_called_once_with("slack_app_model_override_classify_failed")
+
def test_reply_is_pinned_to_the_live_catalogue(self):
"""The schema, not the prompt, is what stops the classifier naming a model this
workspace can't drive. Asking for it in prose was the old guarantee and it only
@@ -88,7 +101,7 @@ class TestClassifySlackAppModelOverride:
"""
fake_client = self._fake_client('{"model": null, "reasoning_effort": null}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=fake_client,
):
classify_slack_app_model_override("use fable for this", CHOICES)
@@ -112,7 +125,7 @@ class TestClassifySlackAppModelOverride:
# instead of taking the fallback this classifier is built around.
fake_client = self._fake_client('{"model": null, "reasoning_effort": null}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=fake_client,
):
classify_slack_app_model_override("use fable for this", CHOICES)
@@ -126,7 +139,7 @@ class TestClassifySlackAppModelOverride:
# The route 400s on `max_tokens`, and the except turns that into a silent "no override".
fake_client = self._fake_client('{"model": null, "reasoning_effort": null}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=fake_client,
):
classify_slack_app_model_override("use fable for this", CHOICES)
@@ -147,7 +160,7 @@ class TestClassifySlackAppModelOverride:
def _render_prompt(self, text: str) -> str:
fake_client = self._fake_client('{"model": null, "reasoning_effort": null}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=fake_client,
):
classify_slack_app_model_override(text, CHOICES)
@@ -165,7 +178,7 @@ class TestClassifySlackAppModelOverride:
def _classify(self, text: str, content: str):
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_openai_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client",
return_value=self._fake_client(content),
):
return classify_slack_app_model_override(text, CHOICES)
diff --git a/products/slack_app/backend/temporal/tests/activities/test_classify_slack_app_project_route.py b/products/slack_app/backend/temporal/tests/activities/test_classify_slack_app_project_route.py
index f0a16d46bf7f..df2f8388f090 100644
--- a/products/slack_app/backend/temporal/tests/activities/test_classify_slack_app_project_route.py
+++ b/products/slack_app/backend/temporal/tests/activities/test_classify_slack_app_project_route.py
@@ -25,7 +25,7 @@ STAGING = _project(team_id=41, integration_id=410, name="Staging")
PRODUCTION = _project(team_id=42, integration_id=420, name="Production")
PROJECTS = [STAGING, PRODUCTION]
-CLASSIFIER = "products.slack_app.backend.temporal.activities.classifiers.build_openai_client"
+CLASSIFIER = "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_openai_client"
class TestClassifySlackAppProjectRoute:
diff --git a/products/slack_app/backend/temporal/tests/test_classify_task_needs_repo.py b/products/slack_app/backend/temporal/tests/test_classify_task_needs_repo.py
index eeb87cc7facf..37eaee77de7b 100644
--- a/products/slack_app/backend/temporal/tests/test_classify_task_needs_repo.py
+++ b/products/slack_app/backend/temporal/tests/test_classify_task_needs_repo.py
@@ -164,7 +164,7 @@ class TestClassifyTaskNeedsRepo:
) -> bool:
fake_client = _fake_messages_client(content)
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_anthropic_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_anthropic_client",
return_value=fake_client,
):
result = classify_task_needs_repo(
@@ -180,7 +180,7 @@ class TestClassifyTaskNeedsRepo:
"""A flaky LLM call must not wall users behind the Connect-GitHub gate."""
text = "something the heuristic can't classify on its own"
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_anthropic_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_anthropic_client",
side_effect=RuntimeError("boom"),
):
result = classify_task_needs_repo(text, [SlackThreadMessage(user="Alessandro", text=text)])
@@ -191,13 +191,12 @@ class TestClassifyTaskNeedsRepo:
text = "ambiguous ask the heuristic does not catch"
fake_client = _fake_messages_client('{"needs_repo": true}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_anthropic_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_anthropic_client",
return_value=fake_client,
) as build_client:
assert classify_task_needs_repo(text, [SlackThreadMessage(user="Alessandro", text=text)]) is True
build_client.assert_called_once_with(
- product="slack_app_routing",
ai_product="slack_app",
trace_id=None,
properties={CLASSIFIER_PROPERTY: "task_needs_repo"},
@@ -217,7 +216,7 @@ class TestClassifyTaskNeedsRepo:
MagicMock(type="text", text='{"needs_repo": true}'),
]
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_anthropic_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_anthropic_client",
return_value=fake_client,
):
assert classify_task_needs_repo(text, [SlackThreadMessage(user="Alessandro", text=text)]) is True
@@ -242,7 +241,7 @@ def test_needs_repo_activity_feeds_team_rules_to_the_classifier(team):
fake_client = _fake_messages_client('{"needs_repo": true}')
with patch(
- "products.slack_app.backend.temporal.activities.classifiers.build_anthropic_client",
+ "products.slack_app.backend.temporal.activities.classifiers.build_ai_gateway_anthropic_client",
return_value=fake_client,
):
result = classify_posthog_code_task_needs_repo_activity(
diff --git a/products/slack_app/backend/tests/test_reply_suggestions.py b/products/slack_app/backend/tests/test_reply_suggestions.py
index bae786616bfe..7419a8132a40 100644
--- a/products/slack_app/backend/tests/test_reply_suggestions.py
+++ b/products/slack_app/backend/tests/test_reply_suggestions.py
@@ -86,7 +86,7 @@ class TestSuggestReplies(SimpleTestCase):
]
)
def test_suggestions_from_model_reply(self, _name: str, content: str, expected: list[SuggestedReply]) -> None:
- with patch("products.slack_app.backend.logic.reply_suggestions.build_openai_client") as build:
+ with patch("products.slack_app.backend.logic.reply_suggestions.build_ai_gateway_openai_client") as build:
build.return_value.with_options.return_value.chat.completions.create.return_value = _completion(content)
assert suggest_replies("Should I open a PR?", ReplySuggestionAttribution()) == expected
@@ -94,14 +94,13 @@ class TestSuggestReplies(SimpleTestCase):
attribution = ReplySuggestionAttribution(
trace_id="trace-1", session_id="T1:C1:1.0", distinct_id="user-1", task_id="task-1", run_id="run-1"
)
- with patch("products.slack_app.backend.logic.reply_suggestions.build_openai_client") as build:
+ with patch("products.slack_app.backend.logic.reply_suggestions.build_ai_gateway_openai_client") as build:
build.return_value.with_options.return_value.chat.completions.create.return_value = _completion(
json.dumps({"suggestions": []})
)
suggest_replies("Should I open a PR?", attribution)
assert build.call_args.kwargs == {
- "product": "slack_app_routing",
"ai_product": "slack_app_routing",
"trace_id": "trace-1",
"session_id": "T1:C1:1.0",
@@ -112,12 +111,12 @@ class TestSuggestReplies(SimpleTestCase):
assert create.call_args.kwargs["user"] == "user-1"
def test_model_failure_offers_nothing(self) -> None:
- with patch("products.slack_app.backend.logic.reply_suggestions.build_openai_client") as build:
+ with patch("products.slack_app.backend.logic.reply_suggestions.build_ai_gateway_openai_client") as build:
build.return_value.with_options.return_value.chat.completions.create.side_effect = TimeoutError()
assert suggest_replies("Should I open a PR?", ReplySuggestionAttribution()) == []
def test_the_person_message_reaches_the_model_apart_from_the_answer(self) -> None:
- with patch("products.slack_app.backend.logic.reply_suggestions.build_openai_client") as build:
+ with patch("products.slack_app.backend.logic.reply_suggestions.build_ai_gateway_openai_client") as build:
create = build.return_value.with_options.return_value.chat.completions.create
create.return_value = _completion(json.dumps({"suggestions": []}))
suggest_replies("Should I open a PR?", ReplySuggestionAttribution(), "Why does the retry never stop?")