Decode Gemini errors sent as a single object, not only as an array

Aperta
#484 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
swift

Direzione di ricerca

Read JSONResponseErrorDecoder.decodeErrorResponse(data:) and the existing testAsyncChatsThrowsStatusErrorForSingleGeminiErrorObject test added in #471. First verify whether Gemini's OpenAI-compatible endpoint returns errors as a single object; the issue says this is unconfirmed. If it does, update decoding and the test to expect GeminiAPIErrorResponse; done means the caller receives the Gemini error message for that response.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

JSONResponseErrorDecoder recognizes a Gemini error only when it comes wrapped in an array:

[{"error": {"code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT"}}]

The same error sent as a single object isn't recognized:

{"error": {"code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT"}}

It isn't an APIErrorResponse either, because type is required. So the caller never sees the message:

  • Before #471, the body surfaced as a DecodingError about the expected result type.
  • With #471, a status of 400 or above surfaces as OpenAIError.statusError, which carries no body.

The single-object shape is Google's standard API error format, which the native Gemini API uses. Nobody has confirmed yet whether the OpenAI-compatible endpoint ever returns it.

Proposal

  • Check whether Gemini's OpenAI-compatible endpoint returns errors as a single object.
  • If it does, make JSONResponseErrorDecoder.decodeErrorResponse(data:) also try a single GeminiAPIErrorResponse, so the caller gets the message.
  • Update testAsyncChatsThrowsStatusErrorForSingleGeminiErrorObject (added in #471) to expect a GeminiAPIErrorResponse.
Lingua principale
Swift
Stelle
2.9k
Fork
519
Merge medio
3g 12h
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MacPaw/OpenAI

Tutte le issue di MacPaw/OpenAI

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.