Hello everyone! Currently I am working on a school project which is using the OpenAI-API. Basically I am working on a website where you can upload files that are then used to generate a quiz about the file’s content.
At the moment, the users can upload files to a NodeJS server. Now I would like to call the API with an URL linked to a file, so that the API can use the file to generate JSON with Questions & Answers to the file’s content.
Summarized:
Users uploads files to NodeJS-Server
API-Call with an URL that leads to the uploaded files
API returns JSON with Questions & Answers about the file’s content
Using the chat/completion endpoint is much, much simpler if your documents fit into the context window. You’d just extract the text from your document, and send them to the endpoint as part of the context.
However, json mode is not really necessary and ocasionally bugs out for unknowable reasons. It’s often enough just telling the model something like this:
You are part of a bigger system.
You must generate a pure json output. No chatter. Anything other than json with the provided schema will crash the system.
Format your response using this schema:
{
question: string, // the question
answer: string, // a true answer to the question
traps: string[] // 3 wrong answers that sound plausible
}[]
And IF you use chat completion and embed your documents into a vector store, you can then add the file URLs to these embeddings (in the metadata), so that each time a document is returned in your cosine similarity search, it also contains it’s URL link.