From fd44f31c8d4bc013cd7e457a4f5ca4df44faf5e7 Mon Sep 17 00:00:00 2001 From: Luv Bansal Date: Tue, 30 Sep 2025 13:55:47 +0530 Subject: [PATCH] fix top_k when ui hits openai_transport_* methods --- clarifai/runners/models/openai_class.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clarifai/runners/models/openai_class.py b/clarifai/runners/models/openai_class.py index ec952652..bbe69ad3 100644 --- a/clarifai/runners/models/openai_class.py +++ b/clarifai/runners/models/openai_class.py @@ -149,6 +149,16 @@ def _update_old_fields(self, request_data: Dict[str, Any]) -> Dict[str, Any]: request_data['max_completion_tokens'] = request_data.pop('max_tokens') if 'top_p' in request_data: request_data['top_p'] = float(request_data['top_p']) + if 'top_k' in request_data: + top_k = int(request_data.pop("top_k", -1)) + if top_k > 0: + extra_body = request_data.get("extra_body", {}) + assert isinstance(extra_body, dict), ValueError( + "`extra_body` must be a dictionary" + ) + extra_body.update({"top_k": top_k}) + request_data.update({"extra_body": extra_body}) + # Note(zeiler): temporary fix for our playground sending additional fields. # FIXME: remove this once the playground is updated. # Shouldn't need to do anything with the responses API since playground isn't yet using it.