Skip to content

Generate text from video and getting NSPOSIXErrorDomain Code=40 "Message too long" #14124

New issue

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

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

Already on GitHub? Sign in to your account

Closed
silvgabriel opened this issue Nov 14, 2024 · 5 comments

Comments

@silvgabriel
Copy link

silvgabriel commented Nov 14, 2024

Description

I'm trying to generate text from video but I always get an error from network layer.
Maybe it's in the request response.

Error: NSPOSIXErrorDomain Code=40 "Message too long"
Video size: 4.6MB
Video time: 16 seconds

Reproducing the issue

Task {
    let model = vertex.generativeModel(modelName: "gemini-1.5-flash")

    // Provide the video as `Data` with the appropriate MIME type
    let video = InlineDataPart(data: try Data(contentsOf: URL(string: "https://i.imgur.com/V6oNWVs.mp4")!), mimeType: "video/mp4")

    // Provide a text prompt to include with the video
    let prompt = "What is in the video?"

    // To stream generated text output, call generateContentStream with the text and video
    let contentStream = try model.generateContentStream(video, prompt)
    for try await chunk in contentStream {
      if let text = chunk.text {
        print(text)
      }
    }
}

Firebase SDK Version

11.5

Xcode Version

16.1

Installation Method

Swift Package Manager

Firebase Product(s)

VertexAI

Targeted Platforms

iOS

Relevant Log Output

Task <DD4086E8-A620-418B-A74D-5AB3E51EC012>.<1> finished with error [40] Error Domain=NSPOSIXErrorDomain Code=40 "Message too long" UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <DD4086E8-A620-418B-A74D-5AB3E51EC012>.<1>, _kCFStreamErrorDomainKey=1, NSErrorPeerAddressKey=<CFData 0x60000261c2a0 [0x1e006f658]>{length = 28, capacity = 28, bytes = 0x1c1e01bb00000000280003f040010809 ... 0000200a00000000}, _kCFStreamErrorCodeKey=40, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <DD4086E8-A620-418B-A74D-5AB3E51EC012>.<1>"
)}

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
{
  "originHash" : "c63c63846d9c539229e96de38d6af51417e28c0ee9a0bc48bd0f0f19d923c329",
  "pins" : [
    {
      "identity" : "abseil-cpp-binary",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/abseil-cpp-binary.git",
      "state" : {
        "revision" : "194a6706acbd25e4ef639bcaddea16e8758a3e27",
        "version" : "1.2024011602.0"
      }
    },
    {
      "identity" : "app-check",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/app-check.git",
      "state" : {
        "revision" : "61b85103a1aeed8218f17c794687781505fbbef5",
        "version" : "11.2.0"
      }
    },
    {
      "identity" : "firebase-ios-sdk",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/firebase/firebase-ios-sdk",
      "state" : {
        "revision" : "dbdfdc44bee8b8e4eaa5ec27eb12b9338f3f2bc1",
        "version" : "11.5.0"
      }
    },
    {
      "identity" : "googleappmeasurement",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/GoogleAppMeasurement.git",
      "state" : {
        "revision" : "4f234bcbdae841d7015258fbbf8e7743a39b8200",
        "version" : "11.4.0"
      }
    },
    {
      "identity" : "googledatatransport",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/GoogleDataTransport.git",
      "state" : {
        "revision" : "617af071af9aa1d6a091d59a202910ac482128f9",
        "version" : "10.1.0"
      }
    },
    {
      "identity" : "googleutilities",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/GoogleUtilities.git",
      "state" : {
        "revision" : "53156c7ec267db846e6b64c9f4c4e31ba4cf75eb",
        "version" : "8.0.2"
      }
    },
    {
      "identity" : "grpc-binary",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/grpc-binary.git",
      "state" : {
        "revision" : "f56d8fc3162de9a498377c7b6cea43431f4f5083",
        "version" : "1.65.1"
      }
    },
    {
      "identity" : "gtm-session-fetcher",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/gtm-session-fetcher.git",
      "state" : {
        "revision" : "5cfe5f090c982de9c58605d2a82a4fc77b774fbd",
        "version" : "4.1.0"
      }
    },
    {
      "identity" : "interop-ios-for-google-sdks",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/interop-ios-for-google-sdks.git",
      "state" : {
        "revision" : "2d12673670417654f08f5f90fdd62926dc3a2648",
        "version" : "100.0.0"
      }
    },
    {
      "identity" : "leveldb",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/firebase/leveldb.git",
      "state" : {
        "revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1",
        "version" : "1.22.5"
      }
    },
    {
      "identity" : "nanopb",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/firebase/nanopb.git",
      "state" : {
        "revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1",
        "version" : "2.30910.0"
      }
    },
    {
      "identity" : "promises",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/google/promises.git",
      "state" : {
        "revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac",
        "version" : "2.4.0"
      }
    },
    {
      "identity" : "swift-protobuf",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/apple/swift-protobuf.git",
      "state" : {
        "revision" : "ebc7251dd5b37f627c93698e4374084d98409633",
        "version" : "1.28.2"
      }
    }
  ],
  "version" : 3
}

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
Replace this line with the contents of your Podfile.lock!
@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@andrewheard
Copy link
Contributor

Hi @silvgabriel, is this error occurring in the simulator, on a real device, or both?

@andrewheard
Copy link
Contributor

I'm not sure whether your request was just an example but for public videos, like the one you linked, you can now use a FileDataPart and pass the URL directly, e.g.:

let model = vertex.generativeModel(modelName: "gemini-1.5-flash")

// Provide the video as a public URL with the appropriate MIME type
let video = FileDataPart(uri: "https://i.imgur.com/V6oNWVs.mp4", mimeType: "video/mp4")

// Provide a text prompt to include with the video
let prompt = "What is in the video?"

// To stream generated text output, call generateContentStream with the text and video
let contentStream = try model.generateContentStream(video, prompt)
for try await chunk in contentStream {
  if let text = chunk.text {
    print(text)
  }
}

The video shows a person opening a door to a room and then panning around the room, showing off various items in it. The room is brightly lit with colorful LED lights. The person is in a gaming room.

This is a new feature in the backend, no need to update your SDK.

@andrewheard
Copy link
Contributor

I have been able to reproduce the NSPOSIXErrorDomain Code=40 "Message too long" error on the iOS simulator but not consistently. It seems to go away after restarting my Mac, switching networks (Ethernet to WiFi) or running Device -> Erase All Content And Settings in the Simulator. Unfortunately I don't have an answer for how to resolve it since it seems to be an underlying OS issue, rather than an issue with the Vertex AI in Firebase SDK.

cc: @paulb777 This has also been reported in the past with the Storage SDK (#13415) and the Crashlytics upload-symbols executable (#9864).

Also seeing reports for other SDKs (and even Safari) like Alamofire/Alamofire#3774, Apple forums (example), StackOverflow (example) and Reddit (example).

@silvgabriel
Copy link
Author

Hello @andrewheard

Thanks for your quickly response!

The problem only happens when I use InlineDataPart, I tested it with FileDataPart and it's working now!
Furthermore, the problem happened to me on both the simulator and the real device and I haven't tried restarting to see if it resolves.

@firebase firebase locked and limited conversation to collaborators Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants