dongri / openai-api-rs

OpenAI API client library for Rust (unofficial)
https://docs.rs/openai-api-rs
MIT License
309 stars 53 forks source link

content-type header api error on file_upload function #51

Closed abhinavdalal closed 10 months ago

abhinavdalal commented 11 months ago

Describe the bug

I am trying to upload a file using file_upload function but i get error below

APIError { message: "415: {\n  \"error\": {\n    \"message\": \"Invalid Content-Type header (application/json; charset=UTF-8), expected multipart/form-data. (HINT: If you're using curl, you can pass -H 'Content-Type: multipart/form-data')\",\n    \"type\": \"invalid_request_error\",\n    \"param\": null,\n    \"code\": null\n  }\n}\n" }

To Reproduce

try to do a file upload using the file_upload function it gives api error.

I think as the error says we need to pass the correct header for file.. cant be the common header in content-type

Code snippets

client.file_upload(FileUploadRequest::new(
            FILE_PATH.to_string(),
            "assistants".to_string(),
        ))

OS

ubuntu

Rust version

Rust v1.73

Library version

openai-api-rs v2.1.4

dongri commented 10 months ago

@abhinavdalal Thank you for the report I use minreq, but I'm having trouble using multipart. reqwest is an option, but the library is too heavy. Consider other openai crates. Sorry.