I was able to do this pretty easily with âvisionâ in the Assistants API. I have not done it with chat completions though. The Assistant was pretty cranky about the image format when trying to pass it in context.
My workaround was to give the image as a file to GPT, then attach that file to the thread and run the assistant query on it. I tried several different methods of attaching the file, but this seemed the most reliable. When uploading the file to GPT, make sure you give it âvisionâ and not âassistantsâ as the purpose.
Here are some snippets. Just make sure to use the file id of the uploaded file in the message add API call. You can also make this more compact by creating the thread with the initial message, but I find it easier to break out the steps when debugging and learning.
1. add the file to openai.
let file = fileCreate(pathToImage, 'vision');
2. create the thread
let c_thread = createThread();
3. put a message on the thread - just give the payload the file.id
let messageid = addImageFile(c_thread, file.id);
content: [
{
"type": "image_file",
"image_file": {
"file_id": file.id, //file id from the reponse object of the upload
"detail": "auto"
}
}
],
4. run the assistant on the thread with whatever your query is.
const run = runAssistant (c_thread);