Skip to content

Commit 4de5511

Browse files
committed
feat: add USE_UNSTRUCTURED_FOR_PDF environment variable to knowledge config
1 parent e8f0b03 commit 4de5511

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/config/knowledge.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { createEnv } from '@t3-oss/env-nextjs';
22
import { z } from 'zod';
33

4-
export const getKnowledgeConfig = () => {
5-
return createEnv({
6-
runtimeEnv: {
7-
DEFAULT_FILES_CONFIG: process.env.DEFAULT_FILES_CONFIG,
8-
UNSTRUCTURED_API_KEY: process.env.UNSTRUCTURED_API_KEY,
9-
UNSTRUCTURED_SERVER_URL: process.env.UNSTRUCTURED_SERVER_URL,
10-
},
11-
server: {
12-
DEFAULT_FILES_CONFIG: z.string().optional(),
13-
UNSTRUCTURED_API_KEY: z.string().optional(),
14-
UNSTRUCTURED_SERVER_URL: z.string().optional(),
15-
},
16-
});
17-
};
18-
19-
export const knowledgeEnv = getKnowledgeConfig();
4+
export const knowledgeEnv = createEnv({
5+
runtimeEnv: {
6+
DEFAULT_FILES_CONFIG: process.env.DEFAULT_FILES_CONFIG,
7+
UNSTRUCTURED_API_KEY: process.env.UNSTRUCTURED_API_KEY,
8+
UNSTRUCTURED_SERVER_URL: process.env.UNSTRUCTURED_SERVER_URL,
9+
USE_UNSTRUCTURED_FOR_PDF: process.env.USE_UNSTRUCTURED_FOR_PDF,
10+
},
11+
server: {
12+
DEFAULT_FILES_CONFIG: z.string().optional(),
13+
UNSTRUCTURED_API_KEY: z.string().optional(),
14+
UNSTRUCTURED_SERVER_URL: z.string().optional(),
15+
USE_UNSTRUCTURED_FOR_PDF: z.string().optional(),
16+
},
17+
});

src/server/modules/ContentChunk/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ import { Strategy } from 'unstructured-client/sdk/models/shared';
33

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

9-
// Get environment variable to control PDF processing method
10-
const USE_UNSTRUCTURED_FOR_PDF = getEnvironment('USE_UNSTRUCTURED_FOR_PDF') === 'true';
11-
128
export interface ChunkContentParams {
139
content: Uint8Array;
1410
fileType: string;
@@ -32,7 +28,7 @@ export class ContentChunk {
3228

3329
isUsingUnstructured(params: ChunkContentParams) {
3430
return params.fileType === 'application/pdf' &&
35-
USE_UNSTRUCTURED_FOR_PDF &&
31+
!!knowledgeEnv.USE_UNSTRUCTURED_FOR_PDF &&
3632
!!knowledgeEnv.UNSTRUCTURED_API_KEY &&
3733
!!knowledgeEnv.UNSTRUCTURED_SERVER_URL;
3834
}

0 commit comments

Comments
 (0)