diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 48305381..38e12eb1 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -1,7 +1,7 @@ import path from 'node:path'; import fs from 'fs'; import { Config, ConfigModelProvider, UIConfigSections } from './types'; -import { hashObj } from '../serverUtils'; +import { hashObj } from '../utils/hash'; import { getModelProvidersUIConfigSection } from '../models/providers'; class ConfigManager { diff --git a/src/lib/uploads/store.ts b/src/lib/uploads/store.ts index 29afeb02..711ff523 100644 --- a/src/lib/uploads/store.ts +++ b/src/lib/uploads/store.ts @@ -2,8 +2,7 @@ import BaseEmbedding from "../models/base/embedding"; import UploadManager from "./manager"; import computeSimilarity from "../utils/computeSimilarity"; import { Chunk } from "../types"; -import { hashObj } from "../serverUtils"; -import fs from 'fs'; +import { hashObj } from '../utils/hash'; type UploadStoreParams = { embeddingModel: BaseEmbedding; diff --git a/src/lib/utils/hash.ts b/src/lib/utils/hash.ts new file mode 100644 index 00000000..9dca22f8 --- /dev/null +++ b/src/lib/utils/hash.ts @@ -0,0 +1,7 @@ +import crypto from 'crypto'; + +export const hashObj = (obj: { [key: string]: any }) => { + const json = JSON.stringify(obj, Object.keys(obj).sort()); + const hash = crypto.createHash('sha256').update(json).digest('hex'); + return hash; +};