refactor(ai_client): remove ProviderError class; ErrorInfo is the new error type

This commit is contained in:
ed
2026-06-12 19:41:41 -04:00
parent da44e934fc
commit 64b787b881
4 changed files with 29 additions and 54 deletions
+7 -5
View File
@@ -4,7 +4,7 @@ from typing import Any, Callable, Optional
from openai import OpenAIError, RateLimitError, AuthenticationError, PermissionDeniedError, APIConnectionError, APIStatusError, BadRequestError
from src.result_types import ErrorInfo, ErrorKind
from src.result_types import ErrorInfo, ErrorKind, Result
@dataclass(frozen=True)
class NormalizedResponse:
@@ -64,7 +64,7 @@ def send_openai_compatible(
request: OpenAICompatibleRequest,
*,
capabilities: Any,
) -> NormalizedResponse:
) -> Result[str]:
kwargs: dict[str, Any] = {
"model": request.model,
"messages": request.messages,
@@ -80,10 +80,12 @@ def send_openai_compatible(
kwargs["extra_body"] = request.extra_body
try:
if request.stream:
return _send_streaming(client, kwargs, request.stream_callback)
return _send_blocking(client, kwargs)
response = _send_streaming(client, kwargs, request.stream_callback)
else:
response = _send_blocking(client, kwargs)
return Result(data=response.text)
except OpenAIError as exc:
raise _classify_openai_compatible_error(exc) from exc
return Result(data="", errors=[_classify_openai_compatible_error(exc, source="openai_compatible")])
def _send_blocking(client: Any, kwargs: dict[str, Any]) -> NormalizedResponse:
resp = client.chat.completions.create(**kwargs)