Skip to content

Commit

Permalink
feat: add USE_UNSTRUCTURED_FOR_PDF environment variable to knowledge …
Browse files Browse the repository at this point in the history
…config
  • Loading branch information
fzlzjerry committed Feb 13, 2025
1 parent e8f0b03 commit 4de5511
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
30 changes: 14 additions & 16 deletions src/config/knowledge.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const getKnowledgeConfig = () => {
return createEnv({
runtimeEnv: {
DEFAULT_FILES_CONFIG: process.env.DEFAULT_FILES_CONFIG,
UNSTRUCTURED_API_KEY: process.env.UNSTRUCTURED_API_KEY,
UNSTRUCTURED_SERVER_URL: process.env.UNSTRUCTURED_SERVER_URL,
},
server: {
DEFAULT_FILES_CONFIG: z.string().optional(),
UNSTRUCTURED_API_KEY: z.string().optional(),
UNSTRUCTURED_SERVER_URL: z.string().optional(),
},
});
};

export const knowledgeEnv = getKnowledgeConfig();
export const knowledgeEnv = createEnv({
runtimeEnv: {
DEFAULT_FILES_CONFIG: process.env.DEFAULT_FILES_CONFIG,
UNSTRUCTURED_API_KEY: process.env.UNSTRUCTURED_API_KEY,
UNSTRUCTURED_SERVER_URL: process.env.UNSTRUCTURED_SERVER_URL,
USE_UNSTRUCTURED_FOR_PDF: process.env.USE_UNSTRUCTURED_FOR_PDF,
},
server: {
DEFAULT_FILES_CONFIG: z.string().optional(),
UNSTRUCTURED_API_KEY: z.string().optional(),
UNSTRUCTURED_SERVER_URL: z.string().optional(),
USE_UNSTRUCTURED_FOR_PDF: z.string().optional(),
},
});
6 changes: 1 addition & 5 deletions src/server/modules/ContentChunk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import { Strategy } from 'unstructured-client/sdk/models/shared';

import { NewChunkItem, NewUnstructuredChunkItem } from '@/database/schemas';
import { ChunkingStrategy, Unstructured } from '@/libs/unstructured';
import { getEnvironment } from '../../utils/env';
import { knowledgeEnv } from '@/config/knowledge';

// Get environment variable to control PDF processing method
const USE_UNSTRUCTURED_FOR_PDF = getEnvironment('USE_UNSTRUCTURED_FOR_PDF') === 'true';

export interface ChunkContentParams {
content: Uint8Array;
fileType: string;
Expand All @@ -32,7 +28,7 @@ export class ContentChunk {

isUsingUnstructured(params: ChunkContentParams) {
return params.fileType === 'application/pdf' &&
USE_UNSTRUCTURED_FOR_PDF &&
!!knowledgeEnv.USE_UNSTRUCTURED_FOR_PDF &&
!!knowledgeEnv.UNSTRUCTURED_API_KEY &&
!!knowledgeEnv.UNSTRUCTURED_SERVER_URL;
}
Expand Down

0 comments on commit 4de5511

Please sign in to comment.