openai / openai-dotnet

The official .NET library for the OpenAI API
https://www.nuget.org/packages/OpenAI
MIT License
707 stars 60 forks source link

Stream a PDF into a File #86

Closed Clive321A closed 6 days ago

Clive321A commented 1 week ago

Hi, I'm trying to upload a file and then use it in an Assistant, the UploadFileAsync() throws a Object reference exception, document is loading ok, size in stream looks correct.

I tried with or without seeking the stream back to the beginning, just wondering if I'm doing this correctly, or off track.

                    FileStream document = File.Open(@"c:\temp\sample.pdf", FileMode.Open);
                    document.Seek(0, SeekOrigin.Begin);
                    OpenAIClient openAIClient = new("12345");

                    FileClient fileClient = openAIClient.GetFileClient();
                    OpenAIFileInfo pdfFile = await fileClient.UploadFileAsync(
                        document,
                        "sample.pdf",
                        FileUploadPurpose.Assistants);
   at OpenAI.OpenAIClient.<>c__DisplayClass21_0.<CreateAddCustomHeadersPolicy>b__0(PipelineMessage message)
   at OpenAI.GenericActionPipelinePolicy.<ProcessAsync>d__3.MoveNext()
   at OpenAI.GenericActionPipelinePolicy.<ProcessAsync>d__3.MoveNext()
   at System.ClientModel.Primitives.ClientPipeline.<SendAsync>d__14.MoveNext()
   at OpenAI.ClientPipelineExtensions.<ProcessMessageAsync>d__0.MoveNext()
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at OpenAI.Files.FileClient.<UploadFileAsync>d__21.MoveNext()
   at OpenAI.Files.FileClient.<UploadFileAsync>d__3.MoveNext()
joseharriaga commented 1 week ago

Thank you for reporting this issue, @Clive321A ! Based on the callstack, this is likely a duplicate of the following: 🔗 https://github.com/openai/openai-dotnet/issues/84. As a workaround, try using version 2.0.0-beta.5 for now.

I have a PR to fix this issue here: 🔗 https://github.com/openai/openai-dotnet/pull/85. We will push an updated package soon.

trrwilson commented 6 days ago

@Clive321A, the fix @joseharriaga described is published now as 2.0.0-beta.7. Thank you again for reporting this!