Issue with File Upload API. I need an url file to send to chat API
Context
I am encountering an issue when uploading a PDF file via the API. Initially, the API required UTF-8 encoding.
Initial Error
{
"detail": "Failed to decode data, please encode your file using UTF-8."
}
My solution
const fileContent = fs.readFileSync(
"./public/uploads/Invoice.pdf",
"utf-8"
);
const blob = new Blob([fileContent], {
type: "application/json",
});
createdFile = await mistralAI.files.upload({ file: blob });
Data send to chat API
aiEngine : "mistral-large-latest"
// stream for MISTRAL
await mistralAI.chat
.stream({
model: aiEngine,
messages: {
role: "user",
content: [
{
type: "text",
text: "What's the content of this file ?",
},
{
type: "document_url",
documentUrl: createdFile,
// documentUrl: "https://www.soundczech.cz/temp/lorem-ipsum.pdf",
},
],
},
// temperature: 0.2,
topP: 0.1,
})
.then(async stream => {
for await (const part of stream) {
if (stream === null) break;
// Add each token to the encoded array
encodedOutput.push(
...encode((part.data.choices[0]?.delta?.content as string) || "")
);
messageOutput.push(
(part.data.choices[0]?.delta?.content as string) || ""
);
// Stream each token to the client
res.write(`data: ${part.data.choices[0]?.delta?.content || ""} \n\n`);
}
})
.catch(err => {
return err;
});
The next Error
{"detail": "Invalid file format.", "description": "Found 2 errors in this file. You can view supported formats here: https://docs.mistral.ai/capabilities/finetuning. ", "errors": [{"message": "line contains invalid json: unexpected character: line 1 column 1", "line_number": 1}, {"message": "line contains invalid json: unexpected character: line 1 column 1", "line_number": 1220}]}
I dont find a solution for this on mistral API doc..
If i used a public url like 'lorem-ipsum', the chat api run correctly
A solution ?
Issue with File Upload API. I need an url file to send to chat API
Context
I am encountering an issue when uploading a PDF file via the API. Initially, the API required UTF-8 encoding.
Initial Error
{ "detail": "Failed to decode data, please encode your file using UTF-8." }My solution
Data send to chat API
aiEngine : "mistral-large-latest"
The next Error
{"detail": "Invalid file format.", "description": "Found 2 errors in this file. You can view supported formats here: https://docs.mistral.ai/capabilities/finetuning. ", "errors": [{"message": "line contains invalid json: unexpected character: line 1 column 1", "line_number": 1}, {"message": "line contains invalid json: unexpected character: line 1 column 1", "line_number": 1220}]}I dont find a solution for this on mistral API doc..
If i used a public url like 'lorem-ipsum', the chat api run correctly
A solution ?