Hello there, I wanted to upload documents (PDF,docx,xml...) for some context and be able to create assistants that could retrieve some context and reply as a chatbot in Ruby on Rails.
I found a similar post here #1207906187803107369 (Python)
But wanted some help with ror.
Currently using
I'm directly calling the APIs using HTTP request handlers. But there are a few issues with the file handling where the file gets uploaded and I get a file-id. But when I try to use the same with an assistant I just get a response saying
Thank you for uploading the file. Currently, the file is not accessible
with the `myfiles_browser` tool, which I would typically use to review the content. However, you can either upload the file again ensuring it is in a supported format such as PDF, DOCX, or TXT,
A test-bed code for the file upload
uri = "https://api.openai.com/v1/files"
headers = {
'Authorization' => "Bearer #{ENV['OPENAI_API_KEY']}",
'Content-Type' => 'multipart/form-data'
}
file_path = 'tmp/testing_file.pdf'
file_content = File.open(file_path, "rb")
# puts "#{file_content}"
data = {
'purpose' => 'assistants',
'file' => file_content
}
response = HTTParty.post(uri, headers: headers, body: data)
puts "#{response}"
This is a smaller part of the entire workflow.
model-used: gpt-4-1106-preview
necessity: Building a chatbot