aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers/AssistantManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/ApiManagers/AssistantManager.ts')
-rw-r--r--src/server/ApiManagers/AssistantManager.ts69
1 files changed, 1 insertions, 68 deletions
diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts
index 063ba193a..d98d32d30 100644
--- a/src/server/ApiManagers/AssistantManager.ts
+++ b/src/server/ApiManagers/AssistantManager.ts
@@ -13,7 +13,6 @@ import { UnstructuredClient } from 'unstructured-client';
import { PartitionResponse } from 'unstructured-client/sdk/models/operations';
import { ChunkingStrategy, Strategy } from 'unstructured-client/sdk/models/shared';
import * as cheerio from 'cheerio';
-import { ScrapflyClient, ScrapeConfig } from 'scrapfly-sdk';
import { google } from 'googleapis';
import * as puppeteer from 'puppeteer';
import { JSDOM } from 'jsdom';
@@ -72,7 +71,7 @@ const readFileAsync = promisify(fs.readFile);
*/
export default class AssistantManager extends ApiManager {
/**
- * Registers all API routes and initializes necessary services like OpenAI, Scrapfly, and UnstructuredClient.
+ * Registers all API routes and initializes necessary services like OpenAI and Google Custom Search.
* @param register The registration method to register routes and handlers.
*/
protected initialize(register: Registration): void {
@@ -82,16 +81,6 @@ export default class AssistantManager extends ApiManager {
dangerouslyAllowBrowser: true,
});
- // Initialize UnstructuredClient for document processing
- const unstructuredClient = new UnstructuredClient({
- security: {
- apiKeyAuth: process.env._CLIENT_UNSTRUCTURED_API_KEY!,
- },
- });
-
- // Initialize ScrapflyClient for scraping purposes
- const scrapflyClient = new ScrapflyClient({ key: process.env._CLIENT_SCRAPFLY_API_KEY! });
-
// Initialize Google Custom Search API
const customsearch = google.customsearch('v1');
@@ -467,61 +456,5 @@ export default class AssistantManager extends ApiManager {
}
},
});
-
- // Register an API route to chunk a document using the UnstructuredClient
- register({
- method: Method.POST,
- subscription: '/chunkDocument',
- secureHandler: async ({ req, res }) => {
- const { file_path } = req.body; // Get the file path from the request body
- const public_path = path.join(publicDirectory, file_path); // Resolve the full path in the public directory
- const file_name = path.basename(file_path); // Extract the file name from the path
-
- try {
- // Read the file content as a Buffer
- const file_data = await fs.promises.readFile(public_path);
-
- try {
- // Use UnstructuredClient to partition the document into chunks
- const result = await unstructuredClient.general.partition({
- partitionParameters: {
- files: {
- content: file_data,
- fileName: file_name,
- },
- strategy: Strategy.Auto, // Automatically determine the chunking strategy
- chunkingStrategy: ChunkingStrategy.ByTitle, // Chunk by title
- extractImageBlockTypes: ['Image', 'Table'], // Extract images and tables
- },
- });
-
- if (result.statusCode === 200) {
- console.log(result.elements);
- const jsonElements = JSON.stringify(result.elements, null, 2);
- console.log(jsonElements); // Log the JSON result of the partitioned elements
- res.send({ document_json: jsonElements }); // Send the partitioned data as a JSON response
- } else {
- console.error(`Unexpected status code: ${result.statusCode}`);
- res.status(result.statusCode).send({
- error: 'Failed to process the document',
- details: result,
- });
- }
- } catch (e: any) {
- console.error('Error during partitioning:', e);
- res.status(500).send({
- error: 'Failed to partition the document',
- details: e.message,
- });
- }
- } catch (error: any) {
- console.error('Error reading file:', error);
- res.status(500).send({
- error: 'Failed to read the file',
- details: error.message,
- });
- }
- },
- });
}
}