Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
chore: fix up minor nits and typing for chatgpt client (#8807)
jnjpng637e320b11f9
diff --git a/letta/llm_api/chatgpt_oauth_client.py b/letta/llm_api/chatgpt_oauth_client.pyindex 6819ac956..c9a2651e0 100644--- a/letta/llm_api/chatgpt_oauth_client.py+++ b/letta/llm_api/chatgpt_oauth_client.py@@ -4,7 +4,6 @@ import jsonfrom typing import Any, AsyncIterator, Callable, Dict, List, Optional, Unionimport httpx-from openai import AsyncStreamfrom openai.types.chat.chat_completion_chunk import ChatCompletionChunkfrom 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 Nonedef _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.pyindex 8df9cd607..b38160a21 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 timeexpires_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_innew_access_token = data["access_token"]new_refresh_token = data.get("refresh_token", creds.refresh_token)