I am trying to upload a file to OpenAI per the instructions here:
I have been trying to use the OpenAI library as an example and have made this code:
The log shows:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
JSON Parameters: [
{
"file": "D:\\Downloads\\Anne Business Plan.pdf",
"purpose": "assistants"
}
]
Parameters = (ArrayList) [{purpose=assistants, file=D:\Downloads\Anne Business Plan.pdf}]
ResponseError. Reason: , Response: {
"error": {
"message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
What am I missing about getting the JSON format right?
I have been trying to use the OpenAI library as an example and have made this code:
B4J code:
Sub Process_Globals
Private fx As JFX
'Private MainForm As Form
Dim apiKey As String = "MyApiKey"
End Sub
Sub AppStart (Form1 As Form, Args() As String)
' MainForm = Form1
' MainForm.Show
UploadFile
End Sub
Sub UploadFile
Dim j As HttpJob
j.Initialize("", Me)
Private parameters As List
parameters.Initialize
' Path to the file you want to upload
Dim filePath As String = File.Combine("D:\Downloads", "Anne Business Plan.pdf")
parameters.Add(CreateMap("purpose" : "assistants", "file": filePath))
Dim JSONGenerator As JSONGenerator
JSONGenerator.Initialize2(parameters)
Log("JSON Parameters: " & JSONGenerator.ToPrettyString(4))
Dim chat_string As String
chat_string = JSONGenerator.ToString
Log("Parameters = " & parameters)
j.PostString("https://api.openai.com/v1/chat/completions", chat_string)
j.GetRequest.SetContentType("application/json")
j.GetRequest.SetHeader("Authorization", "Bearer " & apiKey)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log("OpenAI: ChatResponse ready!")
Dim response As String = j.GetString
Log("OpenAI File Upload Response: " & response)
'ParseJson(response))
End If
j.Release
End Sub
The log shows:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
JSON Parameters: [
{
"file": "D:\\Downloads\\Anne Business Plan.pdf",
"purpose": "assistants"
}
]
Parameters = (ArrayList) [{purpose=assistants, file=D:\Downloads\Anne Business Plan.pdf}]
ResponseError. Reason: , Response: {
"error": {
"message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please contact us through our help center at help.openai.com.)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
What am I missing about getting the JSON format right?