Issue with Inconsistent Text Extraction using Azure OpenAI Code Interpreter

I’m currently using the Azure OpenAI Code Interpreter (Assistant API) with Gpt-4o to summarize file content, including PDFs, Excel files, and other document types. However, I am encountering intermittent issues with text extraction. The error message I receive is:

*”Text extraction from the file is failing intermittently, causing issues with the overall text extraction process.”
*

Sometimes the extraction works perfectly, but at other times, it fails without any clear pattern. This inconsistency is affecting our workflow, and I’m looking for advice on how to troubleshoot or resolve this issue.

Has anyone else experienced similar problems, and if so, how did you address them? Any insights or suggestions would be greatly appreciated.

Thank you!

This is my implementation.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>app.post('/createAssistant', (req, res) => {
// Use the multer middleware to handle the file upload
uploadmul(req, res, async (err) => {
if (err) {
console.error('Error uploading file:', err);
return res.status(500).json({ error: err.message });
}
// Extract form data from the request body
const { name, model, instructions } = req.body;
const files = req.files;
if (!files) {
return res.status(400).json({ error: 'No file uploaded.' });
}
try {
const fileUploadPromises = files.map(async (file) => {
// Read the content from the uploaded file in binary mode
const fileContent = await fs.promises.readFile(file.path);
// Define the filename for the upload
const filename = Buffer.from(file.originalname, 'latin1').toString('utf8');
// Upload the binary file content using Assistants SDK
const uploadAssistantFile = await assistantsClient.uploadFile(fileContent, "assistants", { filename });
// Return file id and filename as an object
return { fileId: uploadAssistantFile.id, filename: filename };
});
// Wait for all file uploads to complete
const fileIdsWithNames = await Promise.all(fileUploadPromises);
// Extract fileIds and filenames separately
const fileIds = fileIdsWithNames.map(file => file.fileId);
// Create an assistant using Assistants SDK
const assistantResponse = await assistantsClient.createAssistant({
model: model,
name: name,
instructions: instructions,
tools: [{ type: "code_interpreter" }],
fileIds: fileIds,
});
console.log("Assistant created:", assistantResponse);
// Create a thread using Assistants SDK
const assistantThread = await assistantsClient.createThread({});
console.log("Assistant thread created:", assistantThread);
// Respond with success message
res.json({
success: true,
message: 'Assistant created successfully!',
assistant: assistantResponse,
});
} catch (error) {
console.error('Error creating assistant:', error);
res.status(500).json({ error: 'Error creating assistant.' });
}
});
});
app.post('/ChatWithAssistant', async (req, res) => {
try {
const name = decodeURIComponent(req.headers['x-user-name']);
const userQuestion = decodeURIComponent(req.headers['x-user-question']);
const assistantID = decodeURIComponent(req.headers['x-assistant-id']);
const threadID = decodeURIComponent(req.headers['x-thread-id']);
console.log("== Chat With Assistant ==");
const colonIndex = assistantID.indexOf(':');
const assistantId = assistantID.substring(colonIndex + 2);
console.log("assistantID", assistantId);
console.log("userQuestion", userQuestion);
// Send user's question to OpenAI API
const threadResponse = await assistantsClient.createMessage(threadID, "user", userQuestion);
const response = await assistantsClient.createRun(threadID, { assistantId });
console.log("response", response);
// Poll for run completion
let runResponse;
do {
await new Promise((r) => setTimeout(r, 500));
runResponse = await assistantsClient.getRun(threadID, response.id);
} while (runResponse.status === "queued" || runResponse.status === "in_progress");
// List run messages and output the first message only
let botResponse = '';
const runMessages = await assistantsClient.listMessages(threadID);
for (const runMessageDatum of runMessages.data) {
for (const item of runMessageDatum.content) {
if (item.type === "text") {
botResponse = item.text?.value || '';
break;
}
}
if (botResponse) {
break;
}
}
// Log and send the response back to the client
console.log("Bot Response:", botResponse);
res.json({ botResponse });
} catch (error) {
console.error('Error:', error);
res.status(500).json({ error: error.message });
}
});
</code>
<code>app.post('/createAssistant', (req, res) => { // Use the multer middleware to handle the file upload uploadmul(req, res, async (err) => { if (err) { console.error('Error uploading file:', err); return res.status(500).json({ error: err.message }); } // Extract form data from the request body const { name, model, instructions } = req.body; const files = req.files; if (!files) { return res.status(400).json({ error: 'No file uploaded.' }); } try { const fileUploadPromises = files.map(async (file) => { // Read the content from the uploaded file in binary mode const fileContent = await fs.promises.readFile(file.path); // Define the filename for the upload const filename = Buffer.from(file.originalname, 'latin1').toString('utf8'); // Upload the binary file content using Assistants SDK const uploadAssistantFile = await assistantsClient.uploadFile(fileContent, "assistants", { filename }); // Return file id and filename as an object return { fileId: uploadAssistantFile.id, filename: filename }; }); // Wait for all file uploads to complete const fileIdsWithNames = await Promise.all(fileUploadPromises); // Extract fileIds and filenames separately const fileIds = fileIdsWithNames.map(file => file.fileId); // Create an assistant using Assistants SDK const assistantResponse = await assistantsClient.createAssistant({ model: model, name: name, instructions: instructions, tools: [{ type: "code_interpreter" }], fileIds: fileIds, }); console.log("Assistant created:", assistantResponse); // Create a thread using Assistants SDK const assistantThread = await assistantsClient.createThread({}); console.log("Assistant thread created:", assistantThread); // Respond with success message res.json({ success: true, message: 'Assistant created successfully!', assistant: assistantResponse, }); } catch (error) { console.error('Error creating assistant:', error); res.status(500).json({ error: 'Error creating assistant.' }); } }); }); app.post('/ChatWithAssistant', async (req, res) => { try { const name = decodeURIComponent(req.headers['x-user-name']); const userQuestion = decodeURIComponent(req.headers['x-user-question']); const assistantID = decodeURIComponent(req.headers['x-assistant-id']); const threadID = decodeURIComponent(req.headers['x-thread-id']); console.log("== Chat With Assistant =="); const colonIndex = assistantID.indexOf(':'); const assistantId = assistantID.substring(colonIndex + 2); console.log("assistantID", assistantId); console.log("userQuestion", userQuestion); // Send user's question to OpenAI API const threadResponse = await assistantsClient.createMessage(threadID, "user", userQuestion); const response = await assistantsClient.createRun(threadID, { assistantId }); console.log("response", response); // Poll for run completion let runResponse; do { await new Promise((r) => setTimeout(r, 500)); runResponse = await assistantsClient.getRun(threadID, response.id); } while (runResponse.status === "queued" || runResponse.status === "in_progress"); // List run messages and output the first message only let botResponse = ''; const runMessages = await assistantsClient.listMessages(threadID); for (const runMessageDatum of runMessages.data) { for (const item of runMessageDatum.content) { if (item.type === "text") { botResponse = item.text?.value || ''; break; } } if (botResponse) { break; } } // Log and send the response back to the client console.log("Bot Response:", botResponse); res.json({ botResponse }); } catch (error) { console.error('Error:', error); res.status(500).json({ error: error.message }); } }); </code>
app.post('/createAssistant', (req, res) => {
  // Use the multer middleware to handle the file upload
  uploadmul(req, res, async (err) => {
      if (err) {
          console.error('Error uploading file:', err);
          return res.status(500).json({ error: err.message });
      }

      // Extract form data from the request body
      const { name, model, instructions } = req.body;
      const files = req.files;

      if (!files) {
          return res.status(400).json({ error: 'No file uploaded.' });
      }

      try {
          const fileUploadPromises = files.map(async (file) => {
              // Read the content from the uploaded file in binary mode
              const fileContent = await fs.promises.readFile(file.path);
              // Define the filename for the upload
              const filename = Buffer.from(file.originalname, 'latin1').toString('utf8');
              // Upload the binary file content using Assistants SDK
              const uploadAssistantFile = await assistantsClient.uploadFile(fileContent, "assistants", { filename });
              // Return file id and filename as an object
              return { fileId: uploadAssistantFile.id, filename: filename };
          });

          // Wait for all file uploads to complete
          const fileIdsWithNames = await Promise.all(fileUploadPromises);
          // Extract fileIds and filenames separately
          const fileIds = fileIdsWithNames.map(file => file.fileId);

          // Create an assistant using Assistants SDK
          const assistantResponse = await assistantsClient.createAssistant({
              model: model,
              name: name,
              instructions: instructions,
              tools: [{ type: "code_interpreter" }],
              fileIds: fileIds,
          });

          console.log("Assistant created:", assistantResponse);

          // Create a thread using Assistants SDK
          const assistantThread = await assistantsClient.createThread({});
          console.log("Assistant thread created:", assistantThread);

          // Respond with success message
          res.json({
              success: true,
              message: 'Assistant created successfully!',
              assistant: assistantResponse,
          });

      } catch (error) {
          console.error('Error creating assistant:', error);
          res.status(500).json({ error: 'Error creating assistant.' });
      }
  });
});

app.post('/ChatWithAssistant', async (req, res) => {
  try {
    const name = decodeURIComponent(req.headers['x-user-name']);
    const userQuestion = decodeURIComponent(req.headers['x-user-question']);
    const assistantID = decodeURIComponent(req.headers['x-assistant-id']);
    const threadID = decodeURIComponent(req.headers['x-thread-id']);
    console.log("== Chat With Assistant ==");

    const colonIndex = assistantID.indexOf(':');
    const assistantId = assistantID.substring(colonIndex + 2);

    console.log("assistantID", assistantId);
    console.log("userQuestion", userQuestion);

    // Send user's question to OpenAI API
    const threadResponse = await assistantsClient.createMessage(threadID, "user", userQuestion);
    const response = await assistantsClient.createRun(threadID, { assistantId });
    console.log("response", response);

    // Poll for run completion
    let runResponse;
    do {
      await new Promise((r) => setTimeout(r, 500));
      runResponse = await assistantsClient.getRun(threadID, response.id);
    } while (runResponse.status === "queued" || runResponse.status === "in_progress");

    // List run messages and output the first message only
    let botResponse = '';
    const runMessages = await assistantsClient.listMessages(threadID);
    for (const runMessageDatum of runMessages.data) {
      for (const item of runMessageDatum.content) {
        if (item.type === "text") {
          botResponse = item.text?.value || '';
          break;
        }
      }
      if (botResponse) {
        break;
      }
    }

    // Log and send the response back to the client
    console.log("Bot Response:", botResponse);
    res.json({ botResponse });

  } catch (error) {
    console.error('Error:', error);
    res.status(500).json({ error: error.message });
  }
});

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật