From 637e320b11f99fd58544648be77939200b3f82ff Mon Sep 17 00:00:00 2001 From: jnjpng Date: Thu, 15 Jan 2026 18:50:23 -0800 Subject: [PATCH] chore: fix up minor nits and typing for chatgpt client (#8807) base --- letta/llm_api/chatgpt_oauth_client.py | 8 ++++---- letta/schemas/providers/chatgpt_oauth.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/letta/llm_api/chatgpt_oauth_client.py b/letta/llm_api/chatgpt_oauth_client.py index 6819ac95..c9a2651e 100644 --- a/letta/llm_api/chatgpt_oauth_client.py +++ b/letta/llm_api/chatgpt_oauth_client.py @@ -4,7 +4,6 @@ import json from typing import Any, AsyncIterator, Callable, Dict, List, Optional, Union import httpx -from openai import AsyncStream from openai.types.chat.chat_completion_chunk import ChatCompletionChunk from openai.types.responses import ( Response, @@ -518,7 +517,7 @@ class ChatGPTOAuthClient(LLMClientBase): self, request_data: dict, llm_config: LLMConfig, - ) -> AsyncStream[ResponseStreamEvent]: + ) -> AsyncStreamWrapper: """Stream response from ChatGPT backend. Note: ChatGPT backend uses SSE by default. This returns a custom @@ -926,7 +925,8 @@ class ChatGPTOAuthClient(LLMClientBase): part=part, ) - # Unhandled event types + # Unhandled event types - log for debugging + logger.debug(f"Unhandled SSE event type: {event_type}") return None def _handle_http_error_from_status(self, status_code: int, error_body: str) -> Exception: @@ -947,7 +947,7 @@ class ChatGPTOAuthClient(LLMClientBase): elif status_code == 429: return LLMRateLimitError( message=f"ChatGPT rate limit exceeded: {error_body}", - code=ErrorCode.RATE_LIMITED, + code=ErrorCode.RATE_LIMIT_EXCEEDED, ) elif status_code >= 500: return LLMServerError( diff --git a/letta/schemas/providers/chatgpt_oauth.py b/letta/schemas/providers/chatgpt_oauth.py index 8df9cd60..b38160a2 100644 --- a/letta/schemas/providers/chatgpt_oauth.py +++ b/letta/schemas/providers/chatgpt_oauth.py @@ -79,7 +79,7 @@ class ChatGPTOAuthCredentials(BaseModel): if expires_at > 10**12: expires_at = expires_at // 1000 # Convert ms to seconds - current_time = datetime.utcnow().timestamp() + current_time = datetime.now(datetime.timezone.utc).timestamp() is_expired = current_time >= (expires_at - buffer_seconds) logger.debug(f"Token expiry check: current={current_time}, expires_at={expires_at}, buffer={buffer_seconds}, expired={is_expired}") return is_expired @@ -217,7 +217,7 @@ class ChatGPTOAuthProvider(Provider): # Calculate new expiry time expires_in = data.get("expires_in", 3600) - new_expires_at = int(datetime.utcnow().timestamp()) + expires_in + new_expires_at = int(datetime.now(datetime.timezone.utc).timestamp()) + expires_in new_access_token = data["access_token"] new_refresh_token = data.get("refresh_token", creds.refresh_token)