diff --git a/api/app/clients/tools/structured/DALLE3.js b/api/app/clients/tools/structured/DALLE3.js index 5f6e335a17..db6b4e63e4 100644 --- a/api/app/clients/tools/structured/DALLE3.js +++ b/api/app/clients/tools/structured/DALLE3.js @@ -5,10 +5,10 @@ const fetch = require('node-fetch'); const { v4: uuidv4 } = require('uuid'); const { ProxyAgent } = require('undici'); const { Tool } = require('@langchain/core/tools'); +const { logger } = require('@librechat/data-schemas'); +const { getImageBasename } = require('@librechat/api'); const { FileContext, ContentTypes } = require('librechat-data-provider'); -const { getImageBasename } = require('~/server/services/Files/images'); const extractBaseURL = require('~/utils/extractBaseURL'); -const logger = require('~/config/winston'); const displayMessage = "DALL-E displayed an image. All generated images are already plainly visible, so don't repeat the descriptions in detail. Do not list download links as they are available in the UI already. The user may download the images by clicking on them, but do not mention anything about downloading to the user."; diff --git a/api/server/services/Files/images/index.js b/api/server/services/Files/images/index.js index 889b19f206..d72a80690b 100644 --- a/api/server/services/Files/images/index.js +++ b/api/server/services/Files/images/index.js @@ -1,13 +1,11 @@ const avatar = require('./avatar'); const convert = require('./convert'); const encode = require('./encode'); -const parse = require('./parse'); const resize = require('./resize'); module.exports = { ...convert, ...encode, - ...parse, ...resize, avatar, }; diff --git a/packages/api/src/files/index.ts b/packages/api/src/files/index.ts index 77feb9f154..1c43619fed 100644 --- a/packages/api/src/files/index.ts +++ b/packages/api/src/files/index.ts @@ -1 +1,2 @@ export * from './mistral/crud'; +export * from './parse'; diff --git a/api/server/services/Files/images/parse.js b/packages/api/src/files/parse.ts similarity index 56% rename from api/server/services/Files/images/parse.js rename to packages/api/src/files/parse.ts index 1b0f7e4738..f782f7e5e7 100644 --- a/api/server/services/Files/images/parse.js +++ b/packages/api/src/files/parse.ts @@ -1,22 +1,22 @@ -const URL = require('url').URL; -const path = require('path'); +import path from 'path'; +import { URL } from 'url'; const imageExtensionRegex = /\.(jpg|jpeg|png|gif|bmp|tiff|svg|webp)$/i; /** * Extracts the image basename from a given URL. * - * @param {string} urlString - The URL string from which the image basename is to be extracted. - * @returns {string} The basename of the image file from the URL. + * @param urlString - The URL string from which the image basename is to be extracted. + * @returns The basename of the image file from the URL. * Returns an empty string if the URL does not contain a valid image basename. */ -function getImageBasename(urlString) { +export function getImageBasename(urlString: string) { try { const url = new URL(urlString); const basename = path.basename(url.pathname); return imageExtensionRegex.test(basename) ? basename : ''; - } catch (error) { + } catch { // If URL parsing fails, return an empty string return ''; } @@ -25,21 +25,16 @@ function getImageBasename(urlString) { /** * Extracts the basename of a file from a given URL. * - * @param {string} urlString - The URL string from which the file basename is to be extracted. - * @returns {string} The basename of the file from the URL. + * @param urlString - The URL string from which the file basename is to be extracted. + * @returns The basename of the file from the URL. * Returns an empty string if the URL parsing fails. */ -function getFileBasename(urlString) { +export function getFileBasename(urlString: string) { try { const url = new URL(urlString); return path.basename(url.pathname); - } catch (error) { + } catch { // If URL parsing fails, return an empty string return ''; } } - -module.exports = { - getImageBasename, - getFileBasename, -};