I want to send file from my disk to OpenAI prompt without actually using .read or converting it into bytes. Is there the way I can use that?
Actually I am using Streamlit to upload file and I can easily save it locally, but I want to handle several file types like: pdf, doc, docx, rtf, but if I will try to read it its impossible bcs every of this type has different encoding, and can’t be readed that easily.
file = st.file_uploader(label='Upload File')
with open(os.path.join("media", file.name), "wb") as f:
f.write(file.getbuffer())
// Thats how im saving file locally from streamlit
response = openai.Completion.create(
model="gpt-4",
prompt="Handle this file: {file}", // how can i send file here?
)
I am kinda stuck bcs, I can’t rely understand what should I do run? Try to read every type of file with different encoding or is there the way just to send file with prompt? Or should I just try to convert every type?
I actually saw from OpenAI GitHub that you can send files like that:
client.files.create(
file=Path("input.jsonl"),
purpose="fine-tune",
)
But its just sends file into gpt withour prompt.
1