I am trying to upload a PDF file and ask GPT to give me a Json object containing it’s data by what GPT understood.
here is my code:
app.get("/", async (req: Request, res: Response) => {
if (!openai) {
res.status(500).send("OpenAI object not created");
return;
}
// Step 1: Upload the PDF file
const response = await openai.files.create({
purpose: "assistants",
file: fs.createReadStream("./test.pdf"),
});
// Step 2: Ask OpenAI to convert the PDF to JSON and extract data
const completion = await openai.chat.completions.create({
model: "gpt-4o",
messages: [
{
role: "assistant",
content: "get all the datafrom the pdf file I uploaded",
},
],
temperature: 0.7,
});
// Step 3: Handle the response and extract the data
const data = completion; // Adjust this based on the actual response structure
res.send(data);
});
I also need to get data out of an image (jpg)
the output I get is:
{
"id": "chatcmpl-9sodJtcgf7l5sDTbzY0yHJ7o9jd6u",
"object": "chat.completion",
"created": 1722851373,
"model": "gpt-4o-2024-05-13",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "I'm sorry, but I cannot access or retrieve data from the PDF file you mentioned. However, if you can provide the text or specific details from the document, I'd be happy to help you interpret or analyze the information. Please let me know how you would like to proceed!"
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 19,
"completion_tokens": 55,
"total_tokens": 74
},
"system_fingerprint": "fp_4e2b2da518" }
Let me how can I link the document to the question because Im using Node JS with Typescript with the offical openai library and Im struggeling with that