Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Log server error responses without -GoogleGenerativeAIDebugLogEnabled #177

Merged
merged 1 commit into from
May 29, 2024

Conversation

andrewheard
Copy link
Collaborator

Updated logging to print response payloads even when -GoogleGenerativeAIDebugLogEnabled is not enabled. This is a port of firebase/firebase-ios-sdk#13009.

Example Error Response Log

If a responseMIMEType of application/json (JSON mode) is specified for a model that doesn't support it (e.g., gemini-1.0-pro):

[GoogleGenerativeAI] Response payload: {
  "error": {
    "code": 400,
    "message": "Json mode is not enabled for models/gemini-1.0-pro",
    "status": "INVALID_ARGUMENT"
  }
}

Updated logging to only print the NSHTTPURLResponse if -GoogleGenerativeAIDebugLogEnabled is enabled.

Example NSHTTPURLResponse Log
[GoogleGenerativeAI] The server responded with an error: <NSHTTPURLResponse: 0x600002abc760> { URL: https://generativelanguage.googleapis.com/v1beta/models/gemini-1.0-pro:generateContent } { Status Code: 400, Headers {
    "Alt-Svc" =     (
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
    );
    "Cache-Control" =     (
        private
    );
    "Content-Encoding" =     (
        gzip
    );
    "Content-Length" =     (
        138
    );
    "Content-Type" =     (
        "application/json; charset=UTF-8"
    );
    Date =     (
        "Wed, 29 May 2024 14:35:12 GMT"
    );
    Server =     (
        "scaffolding on HTTPServer2"
    );
    Vary =     (
        Origin,
        "X-Origin",
        Referer
    );
    "server-timing" =     (
        "gfet4t7; dur=250"
    );
    "x-content-type-options" =     (
        nosniff
    );
    "x-frame-options" =     (
        SAMEORIGIN
    );
    "x-xss-protection" =     (
        0
    );
} }

These were swapped because the NSHTTPURLResponse is rarely useful for understanding an error on its own, whereas the response payload contains details to fix the problem.

@github-actions github-actions bot added component:swift sdk Issue/PR related to Swift SDK status:awaiting review PR awaiting review from a maintainer labels May 29, 2024
@andrewheard andrewheard requested a review from paulb777 May 29, 2024 14:38
@andrewheard andrewheard merged commit 5478400 into main May 29, 2024
9 checks passed
@andrewheard andrewheard deleted the ah/log-error-payloads branch May 29, 2024 14:46
@github-actions github-actions bot removed the status:awaiting review PR awaiting review from a maintainer label May 29, 2024
enefry added a commit to enefry/generative-ai-swift that referenced this pull request Jun 12, 2024
* commit '54784005b57c2235a7669e0c12e8dafa68f0ca5f':
  Log server error responses without `-GoogleGenerativeAIDebugLogEnabled` (google-gemini#177)
  Send `GenerateContentRequest` in `CountTokensRequest` (google-gemini#175)
  Add `responseSchema` to `GenerationConfig` (google-gemini#176)
  Update models in samples and README to `gemini-1.5-flash-latest` (google-gemini#173)
  Sync UI from VertexAI for Firebase (google-gemini#172)
  Increment SDK version to `0.5.4` (google-gemini#171)
  Add default `RequestOptions.timeout` of 300 seconds (google-gemini#170)
  Delete repo specific Issue Template (google-gemini#169)
  Increment SDK version to `0.5.3` (google-gemini#167)
  Make `text` computed property handle mixed-parts responses (google-gemini#165)
  update doc comments (google-gemini#166)
SsomsakTH pushed a commit to SsomsakTH/generative-ai-swift that referenced this pull request Jun 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
component:swift sdk Issue/PR related to Swift SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants