openai / openai-dotnet

The official .NET library for the OpenAI API
https://www.nuget.org/packages/OpenAI/AbsoluteLatest
MIT License
1.03k stars 97 forks source link

Unable to upload files, error saying invalid 'purpose' value #131

Closed bc3tech closed 1 month ago

bc3tech commented 1 month ago

https://github.com/openai/openai-dotnet/blob/3e12a623b0b4fd3b62abb0d7915422a4291b65c9/src/Custom/Files/Internal/InternalFileUploadOptions.cs#L38

when uploading files, it doesn't matter what upload purpose I choose, I get an "invalid purpose" HTTP 400 error. The OpenAI specs show these values in all lower-case, but the code here simply takes the Enum Value and ToString's it which would result in case like Assistants and not assistants

I'm hypothesizing this is the reason none of my uploads work.

joseharriaga commented 1 month ago

Thank you for reaching out, @bc3tech ! Could you share the code that is failing with this error?

bc3tech commented 1 month ago

Yes I am merely doing

        var files = _azureOpenAiClient.Value.GetFileClient();
        try
        {
            var gptFile = files.UploadFile(fileName, OpenAI.Files.FileUploadPurpose.Vision);
bc3tech commented 1 month ago

So the problem isn't in the .ToString() now that I see that FileUploadPurpose is a struct & not an enum as I assumed.

However, there's still something going awry here as I cannot seem to use any file uploading capabilities, despite the MultiPart Form Data entry for purpose having the correct value (vision in my case)

joseharriaga commented 1 month ago

Ah, I think this might be problem: I see your client is called _azureOpenAiClient which makes me think you're using the Azure.AI.OpenAI library with the Azure OpenAI service? If so, the Azure OpenAI service (as of version 2024-06-01) does not yet support "vision" as a file purpose. That's probably what's causing the error that you're getting. Could you try uploading files with other purposes, e.g., "assistants"?

bc3tech commented 1 month ago

Yes I also tried assistants and got the same error.

joseharriaga commented 1 month ago

What version of the Azure OpenAI service are you targeting?

bc3tech commented 1 month ago

I assume you're referring to the api_version passed in the querystring. I've no idea; I'm simply using the Azure SDK, which internally uses this library, which is failing. I'm not specifying any version in my calls.

joseharriaga commented 1 month ago

Thank you, @bc3tech . I suspect the issue that you are seeing is specific to the Azure service. Since this about the Azure.AI.OpenAI library, could you file this issue in the Azure repo here: 🔗 https://github.com/Azure/azure-sdk-for-net