-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.ts
160 lines (151 loc) · 3.15 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import convict, { Config, InternalSchema, Schema } from "convict";
import fs from "node:fs";
import path from "node:path";
const PATH_USER_CONFIG = path.join(process.cwd(), "config.json");
interface GptConfig {
temperature: number;
maxNewTokens: number;
}
interface VectorDatabaseConfig {
maxDocs: number;
docSearchDistance: number;
answerSearchDistance: number;
}
interface FileType {
enabled: boolean;
extensions: string[];
ignorePaths: string[];
chunkSize: number;
chunkOverlap: number;
}
interface MyConfig {
gpt: GptConfig;
vectorDatabase: VectorDatabaseConfig;
dataType: {
[key: string]: FileType;
};
}
const schema: Schema<MyConfig> = {
gpt: {
temperature: {
default: 0.2,
format: "Number",
},
maxNewTokens: {
default: 3048,
format: "nat",
},
},
vectorDatabase: {
maxDocs: {
default: 6,
format: "nat",
},
docSearchDistance: {
default: 0.24,
format: "Number",
},
answerSearchDistance: {
default: 0.24,
format: "Number",
},
},
dataType: {
markdown: {
enabled: {
doc: "Whether the markdown type is enabled",
format: Boolean,
default: true,
env: "DOC_ENABLED",
},
extensions: {
doc: "File extensions for the markdown type",
format: Array,
default: [".md", ".mdx"],
},
ignorePaths: {
doc: "Paths to ignore for the markdown type",
format: Array,
default: ["node_modules", "dist", ".github"],
},
chunkSize: {
doc: "Chunk size for the markdown type",
format: "nat",
default: 1000,
},
chunkOverlap: {
doc: "Chunk overlap for the markdown type",
format: "nat",
default: 0,
},
},
js: {
enabled: {
doc: "Whether the js type is enabled",
format: Boolean,
default: true,
env: "JS_ENABLED",
},
extensions: {
doc: "File extensions for the js type",
format: Array,
default: [".js"],
},
ignorePaths: {
doc: "Paths to ignore for the js type",
format: Array,
default: ["node_modules", "dist", ".github"],
},
chunkSize: {
doc: "Chunk size for the js type",
format: "nat",
default: 1000,
},
chunkOverlap: {
doc: "Chunk overlap for the js type",
format: "nat",
default: 0,
},
},
ts: {
enabled: {
doc: "Whether the ts type is enabled",
format: Boolean,
default: true,
env: "TS_ENABLED",
},
extensions: {
doc: "File extensions for the ts type",
format: Array,
default: [".ts"],
},
ignorePaths: {
doc: "Paths to ignore for the ts type",
format: Array,
default: ["node_modules", "dist", ".github", ".d.ts"],
},
chunkSize: {
doc: "Chunk size for the ts type",
format: "nat",
default: 1000,
},
chunkOverlap: {
doc: "Chunk overlap for the ts type",
format: "nat",
default: 0,
},
},
},
};
export const config: Config<MyConfig> = convict(schema);
// Check if user configuration exists and load it
if (fs.existsSync(PATH_USER_CONFIG)) {
try {
config.loadFile(PATH_USER_CONFIG);
} catch (error) {
console.error("There was a problem reading the config file, are you sure it's valid JSON?");
throw error;
}
}
// Perform validation
config.validate({ allowed: "strict" });