Skip to content

Commit af93036

Browse files
fix white space and formatting
1 parent 50c0811 commit af93036

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/agentlab/llm/llm_utils.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ def call_openai_api_with_retries(client_function, api_params, max_retries=5):
232232
rate limiting, and invalid or error-containing responses.
233233
(This is now a wrapper around generic_call_api_with_retries for OpenAI)
234234
"""
235-
235+
236236
def is_openai_response_valid(response):
237237
# Check for explicit error field in response object first
238238
if getattr(response, "error", None):
239239
logging.warning(f"OpenAI API response contains an error attribute: {response.error}")
240240
return False # Treat as invalid for retry purposes
241-
if hasattr(response, "choices") and response.choices: # Chat Completion API
241+
if hasattr(response, "choices") and response.choices: # Chat Completion API
242242
return True
243-
if hasattr(response, "output") and response.output: # Response API
243+
if hasattr(response, "output") and response.output: # Response API
244244
return True
245245
logging.warning("OpenAI API response is missing 'choices' or 'output' is empty.")
246246
return False
@@ -260,13 +260,14 @@ def get_openai_status_code(exception):
260260
# if you want to customize them from their defaults in the generic function.
261261
)
262262

263+
263264
def call_anthropic_api_with_retries(client_function, api_params, max_retries=5):
264265
"""
265266
Makes an Anthropic API call with retries for transient failures,
266267
rate limiting, and invalid responses.
267268
(This is a wrapper around generic_call_api_with_retries for Anthropic)
268269
"""
269-
270+
270271
def is_anthropic_response_valid(response):
271272
"""Checks if the Anthropic response is valid."""
272273
# A successful Anthropic message response typically has:
@@ -283,11 +284,9 @@ def is_anthropic_response_valid(response):
283284
# For anthropic.types.Message, an error would typically be an exception.
284285
# However, if the client_function could return a dict with an 'error' key:
285286
if isinstance(response, dict) and response.get("type") == "error":
286-
logging.warning(
287-
f"Anthropic API response indicates an error: {response.get('error')}"
288-
)
287+
logging.warning(f"Anthropic API response indicates an error: {response.get('error')}")
289288
return False
290-
289+
291290
# For anthropic.types.Message objects from client.messages.create
292291
if hasattr(response, "type") and response.type == "message":
293292
if hasattr(response, "content") and isinstance(response.content, list):
@@ -299,7 +298,7 @@ def is_anthropic_response_valid(response):
299298
"Anthropic API response is of type 'message' but missing valid 'content'."
300299
)
301300
return False
302-
301+
303302
logging.warning(
304303
f"Anthropic API response does not appear to be a valid message object. Type: {getattr(response, 'type', 'N/A')}"
305304
)
@@ -316,18 +315,17 @@ def get_anthropic_status_code(exception):
316315
# anthropic.APIStatusError provides status_code.
317316
# anthropic.APIConnectionError for network issues.
318317
# Order can matter if there's inheritance; specific ones first.
319-
318+
320319
# Ensure these are the correct exception types from your installed anthropic library version.
321320
anthropic_rate_limit_exception = anthropic.RateLimitError
322321
# Broader API errors, APIStatusError is more specific for HTTP status related issues.
323322
# APIConnectionError for network problems. APIError as a general catch-all.
324323
anthropic_api_error_exceptions = (
325-
anthropic.APIStatusError, # Catches errors with a status_code
326-
anthropic.APIConnectionError, # Catches network-related issues
327-
anthropic.APIError, # General base class for other Anthropic API errors
324+
anthropic.APIStatusError, # Catches errors with a status_code
325+
anthropic.APIConnectionError, # Catches network-related issues
326+
anthropic.APIError, # General base class for other Anthropic API errors
328327
)
329328

330-
331329
return generic_call_api_with_retries(
332330
client_function=client_function,
333331
api_params=api_params,

src/agentlab/llm/tracking.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,5 +326,3 @@ def increment_stats_dict(self, stats_dict: dict):
326326
"""increment the stats_dict with the given values."""
327327
for k, v in stats_dict.items():
328328
self.stats_dict[k] += v
329-
330-

0 commit comments

Comments
 (0)