ex_openai icon indicating copy to clipboard operation
ex_openai copied to clipboard

Invalid Request for `Files.create_file`

Open bdtky opened this issue 1 year ago • 3 comments

Hello :wave: and thank you for this neat library.

I ran into the issue below:

ExOpenAI.Files.create_file({"Test Document.pdf", testfile}, "assistants", openai_api_key: api_key)

{:error,
 %{
   "error" => %{
     "code" => nil,
     "message" => "Additional properties are not allowed ('openai_api_key' was unexpected)",
     "param" => nil,
     "type" => "invalid_request_error"
   }
 }}

I was able to fix locally with a modification to client.ex:

    multipart_body =
      {:multipart,
       params
+      |> Enum.into(%{})
+      |> Map.delete(:openai_organization_key)
+      |> Map.delete(:openai_api_key)
+      |> Map.to_list()
       |> Enum.map(&multipart_param/1)}

I'm happy to test further and contribute if appropriate.

bdtky avatar Jul 17 '24 04:07 bdtky

Thanks for spotting this. Can you create a PR to fix this issue?

The behaviour of stripping the args should probably be aligned with the other methods so we can just re-use the same thing

dvcrn avatar Jul 17 '24 06:07 dvcrn

Sure! Giving it a try now

bdtky avatar Jul 18 '24 04:07 bdtky

Released in https://github.com/dvcrn/ex_openai/releases/tag/1.6.0

dvcrn avatar Jul 18 '24 13:07 dvcrn