mscraftsman / generative-ai

Gemini AI SDK for .NET and ASP.NET Core enables developers to use Google's state-of-the-art generative AI models to build AI-powered features and applications.
https://mscraftsman.github.io/generative-ai/
Apache License 2.0
55 stars 11 forks source link

GenerativeModel.UploadFile locks the uploaded file. #35

Closed rsmithsa closed 1 month ago

rsmithsa commented 1 month ago

Thanks for a great library! One minor issue I've picked up is that "UploadFile" doesn't dispose of the FileStream it uses. This means that it tends to keep the file open after upload.

It makes a workflow like this more or less impossible to implement cleanly:

  1. Fetch file to a temporary location
  2. GenerativeModel.UploadFile
  3. Delete the file from temp

Just wrapping the FileStream you create in a using block would probably do the trick.

Additionally if possible having an UploadFile overload which supports streams rather than files would be amazing - happy to log this as another ticket if you'd like.

jochenkirstaetter commented 1 month ago

Hello @rsmithsa Thanks for looking into this and providing a solution. Yes, you're right on the dispose and overload. Would be happy to merge those changes.

Cheers, JoKi

rsmithsa commented 1 month ago

Thanks, I'll create a PR for the stream based overload as well.

jochenkirstaetter commented 1 month ago

New issue #38 has been created. Thanks

jochenkirstaetter commented 1 month ago

Released in https://github.com/mscraftsman/generative-ai/releases/tag/v1.6.5