mkht / PSOpenAI

PowerShell module for OpenAI API.
MIT License
30 stars 10 forks source link

Invalid file for Batch API. Must be utf-8 encoded #19

Open lollolman opened 2 months ago

lollolman commented 2 months ago

When I try to use Add-OpeAIFile with the purpuse "batch" like this for example:

$upload = Add-OpenAIFile -File $file.FullName -Purpose "batch"

I receive this error:

Invoke-OpenAIAPIRequest: C:\Program Files\WindowsPowerShell\Modules\PSOpenAI\3.14.0\Public\Files\Add-OpenAIFile.ps1:95:21
Line |
  95 |          $Response = Invoke-OpenAIAPIRequest @params
     |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | OpenAI API returned an 400 (Bad Request) Error: Invalid file for Batch API. Must be utf-8 encoded

Any suggestions? Many thanks!

L.

mkht commented 2 months ago

Make sure the file you are about to upload is encoded in UTF-8. If you try to upload a file saved in a different encoding, such as UTF-16 or UTF-7, you will receive that error.

potatoqualitee commented 2 months ago

In my own wrappers, I convert to UTF-8 before uploading and it takes care of this restriction by OpenAI.