chore: fix up minor nits and typing for chatgpt client (#8807)

base
This commit is contained in:
jnjpng
2026-01-15 18:50:23 -08:00
committed by Sarah Wooders
parent 5017cb1d12
commit 637e320b11
2 changed files with 6 additions and 6 deletions

View File

@@ -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(

View File

@@ -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)