When I upload Java file from my project, it always failed. The only one succeed is a very simple java file without any meaningful code in it, it only had an empty class definition. The file was encoded in UTF-8, and no BOM in it. Looking for help with this. Thanks.
which API endpoint are you calling, what are you trying to do, and what error are you getting?
curl https://api.openai.com/v1/assistants/asst_*****/files \
-H "Authorization: Bearer ****" \
-H 'Content-Type: application/json' \
-H 'OpenAI-Beta: assistants=v1' \
-F file="@Parameters.java"
or , I upload java file from the assistant’s page, it always failed.
I’m trying to upload java file as context for assistant to understand what I’m doing.
Error is like this: {
“error”: {
“message”: “1 validation error for Request\nbody → 0\n Expecting value: line 1 column 1 (char 0) (type=value_error.jsondecode; msg=Expecting value; doc=--------------------------b59698eeaa58cf8c\r\nContent-Disposition: attachment; name="file"; filename="Parameters.java"\r\nContent-Type: application/octet-stream\r\n\r\npackage org.assistant.actions;\n\nimport com.intellij.openapi.project.Project;\n\nimport java.nio.file.Path;\n\npublic class Parameters {\n p*****ject() {\n return project;\n }\n\n public void setProject(Project project) {\n this.project = project;\n }\n}\n\r\n--------------------------b59698eeaa58cf8c–\r\n; pos=0; lineno=1; colno=1)”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}
Looking for help.
I haven’t used the assistant myself, but it looks like you need the right Content-Type. I think that -H (header) argument that you have as JSON should be the one for Java instead.
https://platform.openai.com/docs/assistants/tools/supported-files
Thanks for your help. I tried the below commands, but still failed with assistant.
curl https://api.openai.com/v1/assistants/asst_***/files \
-H "Authorization: Bearer ***" \
-H 'Content-Type: text/x-java' \
-H 'OpenAI-Beta: assistants=v1' \
-F file="@./Test.java"
{
"error": {
"message": "1 validation error for Request\nbody\n value is not a valid dict (type=type_error.dict)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}%
curl https://api.openai.com/v1/assistants/asst_***/files \
-H "Authorization: Bearer ***" \
-H 'Content-Type: application/zip' \
-H 'OpenAI-Beta: assistants=v1' \
-F purpose="assistants" \
-F file="@context.zip"
{
"error": {
"message": "1 validation error for Request\nbody\n value is not a valid dict (type=type_error.dict)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}%
–this one is not directly with assistant, it can upload successfully
curl https://api.openai.com/v1/files \
-H "Authorization: Bearer ***" \
-F purpose="assistants" \
-F file="@context.zip"
Meh, I gave up and asked GPT how to do this and it says this:
Certainly! To upload a file to an OpenAI assistant using the provided endpoint via curl
, you would use a command similar to the one below. Please replace asst_***
with your actual assistant ID and ensure that you also substitute YOUR_API_KEY
with your actual OpenAI API key.
curl -X POST "https://api.openai.com/v1/assistants/asst_***/files" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/file.json;type=application/json" \
-F "purpose=answers"
Here’s what each part of the command does:
-X POST
: Specifies the HTTP method, which is POST for uploading a file.https://api.openai.com/v1/assistants/asst_***/files
: The URL where you are sending the POST request. Replaceasst_***
with your assistant’s specific ID.-H "Authorization: Bearer YOUR_API_KEY"
: Adds a header for authorization with your API key.-H "Content-Type: multipart/form-data"
: Sets the content type tomultipart/form-data
which is required for uploading files.-F "file=@/path/to/your/file.json;type=application/json"
: The-F
flag is used to specify each multipart field. Thefile=
part is followed by the path to the file you want to upload. Replace/path/to/your/file.json
with the actual file path. Thetype=
part specifies the content type of the file being uploaded.-F "purpose=answers"
: Specifies the purpose of the file upload. It should beanswers
for files that will be used to provide answers.
Please ensure that the file you are uploading is in the format expected by the API and that it conforms to the requirements for the purpose you specify (e.g., answers
).
Remember to replace asst_***
with your actual assistant ID and /path/to/your/file.json
with the path to the JSON file you want to upload. Also, remember to replace YOUR_API_KEY
with your actual OpenAI API key. Keep your API key secure and do not expose it in public forums or code repositories.
Thanks mate.
I’m wondering if it’s an internal issue in uploading java file in assistant. This command still can’t work with the same error feedback. Thanks anyway. I learned a lot from the commands you gave me.
I’d try different files of different types, and different Java files too, to see where the fail starts happening. Maybe there’s some bizarre hidden character in your java file that’s corrupt.
I have a 99% success ratio in solving peoples problems, so if I’ve failed to solve your problem, this is a devastating blow to my ego.
Hey, mate, thank you for your help. I think I found the problem.
When the line separator is set to LF, java file always failed to upload. When I change it to CRLF, (although I’m using Mac OS), then the upload is successful.
Happy to find the hidden character
You saved me hours of trial and error. Thanks!!