Skip to content

Commit 3badd28

Browse files
committed
GRPC clients version 11.10.9
1 parent 2b48310 commit 3badd28

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

clarifai_grpc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "11.10.8"
1+
__version__ = "11.10.9"
22

33
import os
44

tests/public_models/openai_tool_calling_helper.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def call_openai_tool_calling(model_url, config):
6868
api_key=os.environ.get('CLARIFAI_PAT_KEY'),
6969
base_url=f"https://{channel._target}/v2/ext/openai/v1",
7070
default_headers={"X-Clarifai-Request-Id-Prefix": f"python-openai-{CLIENT_VERSION}"},
71-
timeout=10 # 10 seconds timeout to avoid hanging
71+
timeout=10, # 10 seconds timeout to avoid hanging
7272
)
7373

7474
# Build tool definition with strict parameter
@@ -116,8 +116,7 @@ def call_openai_tool_calling(model_url, config):
116116
if attempt == MAX_RETRY_ATTEMPTS - 1:
117117
break
118118
print(
119-
f"Retrying tool calling for '{model_url}' after error: {e}. "
120-
f"Attempt #{attempt + 1}"
119+
f"Retrying tool calling for '{model_url}' after error: {e}. Attempt #{attempt + 1}"
121120
)
122121
time.sleep(attempt + 1)
123122
except Exception as e:
@@ -147,9 +146,9 @@ def validate_tool_calling_response(response, config):
147146
assert response is not None, "Response is None"
148147

149148
if config["stream"]:
150-
assert isinstance(
151-
response, list
152-
) and response, f"Invalid streaming response: {type(response)}"
149+
assert isinstance(response, list) and response, (
150+
f"Invalid streaming response: {type(response)}"
151+
)
153152

154153
# Check finish_reason and usage
155154
has_finish_reason = any(
@@ -168,9 +167,9 @@ def validate_tool_calling_response(response, config):
168167
]
169168

170169
# Validate exactly ONE chunk contains tool calls
171-
assert (
172-
len(chunks_with_tool_calls) == 1
173-
), f"Expected exactly 1 chunk with tool calls, got {len(chunks_with_tool_calls)}"
170+
assert len(chunks_with_tool_calls) == 1, (
171+
f"Expected exactly 1 chunk with tool calls, got {len(chunks_with_tool_calls)}"
172+
)
174173

175174
# Get the single chunk's tool calls
176175
tool_calls = chunks_with_tool_calls[0].choices[0].delta.tool_calls
@@ -181,14 +180,16 @@ def validate_tool_calling_response(response, config):
181180
tool_call = tool_calls[0]
182181

183182
# Validate has function name
184-
assert (
185-
tool_call.function and tool_call.function.name
186-
), "Tool call missing function or name"
183+
assert tool_call.function and tool_call.function.name, (
184+
"Tool call missing function or name"
185+
)
187186

188187
# Validate has complete valid JSON arguments
189-
assert (
190-
tool_call.function.arguments and is_valid_tool_arguments(tool_call.function.arguments)
191-
), f"Invalid or missing arguments: {tool_call.function.arguments if tool_call.function else 'N/A'}"
188+
assert tool_call.function.arguments and is_valid_tool_arguments(
189+
tool_call.function.arguments
190+
), (
191+
f"Invalid or missing arguments: {tool_call.function.arguments if tool_call.function else 'N/A'}"
192+
)
192193

193194
else:
194195
# Non-streaming
@@ -197,21 +198,27 @@ def validate_tool_calling_response(response, config):
197198
message = response.choices[0].message
198199

199200
if config["tool_choice"] == "required":
200-
assert hasattr(message, 'tool_calls') and message.tool_calls, "Message missing tool_calls"
201+
assert hasattr(message, 'tool_calls') and message.tool_calls, (
202+
"Message missing tool_calls"
203+
)
201204

202205
tool_call = message.tool_calls[0]
203-
assert tool_call.function and tool_call.function.name, "Tool call missing function or name"
206+
assert tool_call.function and tool_call.function.name, (
207+
"Tool call missing function or name"
208+
)
204209

205-
assert is_valid_tool_arguments(
206-
tool_call.function.arguments
207-
), f"Invalid arguments: {tool_call.function.arguments}"
210+
assert is_valid_tool_arguments(tool_call.function.arguments), (
211+
f"Invalid arguments: {tool_call.function.arguments}"
212+
)
208213

209214

210215
def _list_featured_models_with_use_case_filters(per_page=50, use_cases=None):
211216
"""Lists featured models from the Clarifai platform."""
212217
channel = ClarifaiChannel.get_grpc_channel()
213218
stub = service_pb2_grpc.V2Stub(channel)
214-
request = service_pb2.ListModelsRequest(per_page=per_page, featured_only=True, use_cases=use_cases)
219+
request = service_pb2.ListModelsRequest(
220+
per_page=per_page, featured_only=True, use_cases=use_cases
221+
)
215222
response = stub.ListModels(request, metadata=metadata(pat=True))
216223
if response.status.code != status_code_pb2.SUCCESS:
217224
raise Exception(f"ListModels failed: {response.status.description}")

0 commit comments

Comments
 (0)