Skip to content

Commit 55edac2

Browse files
authored
Revert 'Adds X-Request-LightspeedUser to WCA requests (#1667)' (#1669)
1 parent cf9576d commit 55edac2

File tree

4 files changed

+14
-60
lines changed

4 files changed

+14
-60
lines changed

ansible_ai_connect/ai/api/model_pipelines/tests/test_wca_client.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
from ansible_ai_connect.ai.api.model_pipelines.tests import mock_pipeline_config
5959
from ansible_ai_connect.ai.api.model_pipelines.wca.pipelines_base import (
6060
WCA_REQUEST_ID_HEADER,
61-
WCA_REQUEST_USER_UUID_HEADER,
6261
ibm_cloud_identity_token_hist,
6362
ibm_cloud_identity_token_retry_counter,
6463
wca_codegen_hist,
@@ -847,7 +846,6 @@ def _do_inference(
847846
):
848847
model_id = "zavala"
849848
api_key = "abc123"
850-
user_uuid = str(uuid.uuid4())
851849
context = ""
852850
prompt = prompt if prompt else "- name: install ffmpeg on Red Hat Enterprise Linux"
853851

@@ -876,14 +874,13 @@ def _do_inference(
876874
response = MockResponse(
877875
json=predictions,
878876
status_code=200,
879-
headers={WCA_REQUEST_ID_HEADER: request_id, WCA_REQUEST_USER_UUID_HEADER: user_uuid},
877+
headers={WCA_REQUEST_ID_HEADER: request_id},
880878
)
881879

882880
requestHeaders = {
883881
"Content-Type": "application/json",
884882
"Authorization": f"Bearer {token['access_token']}",
885883
WCA_REQUEST_ID_HEADER: suggestion_id,
886-
WCA_REQUEST_USER_UUID_HEADER: user_uuid,
887884
}
888885

889886
model_client = WCASaaSCompletionsPipeline(self.config)
@@ -892,13 +889,9 @@ def _do_inference(
892889
model_client.get_model_id = Mock(return_value=model_id)
893890
model_client.get_api_key = Mock(return_value=api_key)
894891

895-
mock_request = Mock()
896-
mock_request.user = Mock()
897-
mock_request.user.uuid = user_uuid
898-
899892
result = model_client.invoke(
900893
CompletionsParameters.init(
901-
request=mock_request,
894+
request=Mock(),
902895
model_input=model_input,
903896
model_id=model_id,
904897
suggestion_id=suggestion_id,
@@ -1492,7 +1485,6 @@ def test_get_model_id_without_setting(self):
14921485
class TestWCAOnPremCodegen(WisdomServiceLogAwareTestCase):
14931486
prompt = "- name: install ffmpeg on Red Hat Enterprise Linux"
14941487
suggestion_id = "suggestion_id"
1495-
user_uuid = str(uuid.uuid4())
14961488
token = base64.b64encode(bytes("username:12345", "ascii")).decode("ascii")
14971489
codegen_data = {
14981490
"model_id": "model-name",
@@ -1501,7 +1493,6 @@ class TestWCAOnPremCodegen(WisdomServiceLogAwareTestCase):
15011493
request_headers = {
15021494
"Authorization": f"ZenApiKey {token}",
15031495
WCA_REQUEST_ID_HEADER: suggestion_id,
1504-
WCA_REQUEST_USER_UUID_HEADER: user_uuid,
15051496
}
15061497
model_input = {
15071498
"instances": [
@@ -1528,13 +1519,9 @@ def setUp(self):
15281519
self.model_client.session.post = Mock(return_value=MockResponse(json={}, status_code=200))
15291520

15301521
def test_headers(self):
1531-
mock_request = Mock()
1532-
mock_request.user = Mock()
1533-
mock_request.user.uuid = self.user_uuid
1534-
15351522
self.model_client.invoke(
15361523
CompletionsParameters.init(
1537-
request=mock_request, model_input=self.model_input, suggestion_id=self.suggestion_id
1524+
request=Mock(), model_input=self.model_input, suggestion_id=self.suggestion_id
15381525
),
15391526
)
15401527
self.model_client.session.post.assert_called_once_with(
@@ -1546,13 +1533,10 @@ def test_headers(self):
15461533
)
15471534

15481535
def test_disabled_model_server_ssl(self):
1549-
mock_request = Mock()
1550-
mock_request.user = Mock()
1551-
mock_request.user.uuid = self.user_uuid
15521536
self.config.verify_ssl = False
15531537
self.model_client.invoke(
15541538
CompletionsParameters.init(
1555-
request=mock_request, model_input=self.model_input, suggestion_id=self.suggestion_id
1539+
request=Mock(), model_input=self.model_input, suggestion_id=self.suggestion_id
15561540
),
15571541
)
15581542
self.model_client.session.post.assert_called_once_with(

ansible_ai_connect/ai/api/model_pipelines/wca/pipelines_base.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181

8282
WCA_REQUEST_ID_HEADER = "X-Request-ID"
8383

84-
WCA_REQUEST_USER_UUID_HEADER = "X-Request-LightspeedUser"
85-
8684
# from django_prometheus.middleware.DEFAULT_LATENCY_BUCKETS
8785
DEFAULT_LATENCY_BUCKETS = (
8886
0.01,
@@ -245,20 +243,6 @@ class WCABasePipeline(
245243
def __init__(self, config: WCA_PIPELINE_CONFIGURATION):
246244
super().__init__(config=config)
247245

248-
def _prepare_request_headers(
249-
self, request_user: Optional[User], api_key: str, identifier: Optional[str]
250-
) -> dict[str, Optional[str]]:
251-
"""
252-
Helper method to extract user UUID and get request headers.
253-
"""
254-
lightspeed_user_uuid_str: Optional[str] = None
255-
if request_user and hasattr(request_user, "uuid"):
256-
lightspeed_user_uuid_str = str(request_user.uuid)
257-
258-
return self.get_request_headers(
259-
api_key, identifier, lightspeed_user_uuid=lightspeed_user_uuid_str
260-
)
261-
262246
@staticmethod
263247
def log_backoff_exception(details):
264248
_, exc, _ = sys.exc_info()
@@ -300,7 +284,7 @@ def on_backoff_explain_role(details):
300284

301285
@abstractmethod
302286
def get_request_headers(
303-
self, api_key: str, identifier: Optional[str], lightspeed_user_uuid: Optional[str] = None
287+
self, api_key: str, identifier: Optional[str]
304288
) -> dict[str, Optional[str]]:
305289
raise NotImplementedError
306290

@@ -334,12 +318,7 @@ def invoke(self, params: CompletionsParameters) -> CompletionsResponse:
334318
try:
335319
api_key = self.get_api_key(request.user)
336320
model_id = self.get_model_id(request.user, model_id)
337-
338-
headers = self._prepare_request_headers(request.user, api_key, suggestion_id)
339-
340-
result = self.infer_from_parameters(
341-
api_key, model_id, context, prompt, suggestion_id, headers
342-
)
321+
result = self.infer_from_parameters(api_key, model_id, context, prompt, suggestion_id)
343322

344323
response = result.json()
345324
response["model_id"] = model_id
@@ -349,15 +328,14 @@ def invoke(self, params: CompletionsParameters) -> CompletionsResponse:
349328
except requests.exceptions.Timeout:
350329
raise ModelTimeoutError(model_id=model_id)
351330

352-
def infer_from_parameters(
353-
self, api_key, model_id, context, prompt, suggestion_id=None, headers=None
354-
):
331+
def infer_from_parameters(self, api_key, model_id, context, prompt, suggestion_id=None):
355332
data = {
356333
"model_id": model_id,
357334
"prompt": f"{context}{prompt}",
358335
}
359336
logger.debug(f"Inference API request payload: {json.dumps(data)}")
360337

338+
headers = self.get_request_headers(api_key, suggestion_id)
361339
task_count = len(get_task_names_from_prompt(prompt))
362340
prediction_url = f"{self.config.inference_url}/v1/wca/codegen/ansible"
363341

@@ -493,8 +471,7 @@ def invoke(self, params: PlaybookGenerationParameters) -> PlaybookGenerationResp
493471
api_key = self.get_api_key(request.user)
494472
model_id = self.get_model_id(request.user, model_id)
495473

496-
headers = self._prepare_request_headers(request.user, api_key, generation_id)
497-
474+
headers = self.get_request_headers(api_key, generation_id)
498475
data = {
499476
"model_id": model_id,
500477
"text": text,
@@ -576,8 +553,7 @@ def invoke(self, params: RoleGenerationParameters) -> RoleGenerationResponse:
576553
api_key = self.get_api_key(request.user)
577554
model_id = self.get_model_id(request.user, model_id)
578555

579-
headers = self._prepare_request_headers(request.user, api_key, generation_id)
580-
556+
headers = self.get_request_headers(api_key, generation_id)
581557
data = {
582558
"model_id": model_id,
583559
"text": text,
@@ -658,8 +634,7 @@ def invoke(self, params: PlaybookExplanationParameters) -> PlaybookExplanationRe
658634
api_key = self.get_api_key(request.user)
659635
model_id = self.get_model_id(request.user, model_id)
660636

661-
headers = self._prepare_request_headers(request.user, api_key, explanation_id)
662-
637+
headers = self.get_request_headers(api_key, explanation_id)
663638
data = {
664639
"model_id": model_id,
665640
"playbook": content,
@@ -721,8 +696,7 @@ def invoke(self, params: RoleExplanationParameters) -> RoleExplanationResponse:
721696
api_key = self.get_api_key(request.user)
722697
model_id = self.get_model_id(request.user, model_id)
723698

724-
headers = self._prepare_request_headers(request.user, api_key, explanation_id)
725-
699+
headers = self.get_request_headers(api_key, explanation_id)
726700
data = {
727701
"role_name": params.role_name,
728702
"model_id": model_id,

ansible_ai_connect/ai/api/model_pipelines/wca/pipelines_onprem.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
)
4848
from ansible_ai_connect.ai.api.model_pipelines.wca.pipelines_base import (
4949
WCA_REQUEST_ID_HEADER,
50-
WCA_REQUEST_USER_UUID_HEADER,
5150
WCABaseCompletionsPipeline,
5251
WCABaseContentMatchPipeline,
5352
WCABaseMetaData,
@@ -115,13 +114,12 @@ def __init__(self, config: WCAOnPremConfiguration):
115114
# User may provide an override value if the setting is not defined.
116115

117116
def get_request_headers(
118-
self, api_key: str, identifier: Optional[str], lightspeed_user_uuid: Optional[str] = None
117+
self, api_key: str, identifier: Optional[str]
119118
) -> dict[str, Optional[str]]:
120119
base_headers = self._get_base_headers(api_key)
121120
return {
122121
**base_headers,
123122
WCA_REQUEST_ID_HEADER: str(identifier) if identifier else None,
124-
WCA_REQUEST_USER_UUID_HEADER: lightspeed_user_uuid if lightspeed_user_uuid else None,
125123
}
126124

127125
def _get_base_headers(self, api_key: str) -> dict[str, str]:

ansible_ai_connect/ai/api/model_pipelines/wca/pipelines_saas.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
from ansible_ai_connect.ai.api.model_pipelines.wca.pipelines_base import (
5858
MODEL_MESH_HEALTH_CHECK_TOKENS,
5959
WCA_REQUEST_ID_HEADER,
60-
WCA_REQUEST_USER_UUID_HEADER,
6160
WCABaseCompletionsPipeline,
6261
WCABaseContentMatchPipeline,
6362
WCABaseMetaData,
@@ -230,13 +229,12 @@ def __init__(self, config: WCASaaSConfiguration):
230229
super().__init__(config=config)
231230

232231
def get_request_headers(
233-
self, api_key: str, identifier: Optional[str], lightspeed_user_uuid: Optional[str] = None
232+
self, api_key: str, identifier: Optional[str]
234233
) -> dict[str, Optional[str]]:
235234
base_headers = self._get_base_headers(api_key)
236235
return {
237236
**base_headers,
238237
WCA_REQUEST_ID_HEADER: str(identifier) if identifier else None,
239-
WCA_REQUEST_USER_UUID_HEADER: lightspeed_user_uuid if lightspeed_user_uuid else None,
240238
}
241239

242240
def _get_base_headers(self, api_key: str) -> dict[str, str]:

0 commit comments

Comments
 (0)