Skip to content

Commit d24958f

Browse files
AceLamjosStorer
andauthored
Add ChatGLM API (#567)
* Add ChatGLM API * add minimal build * a small patch --------- Co-authored-by: josc146 <[email protected]>
1 parent 70d6b79 commit d24958f

File tree

9 files changed

+4582
-2343
lines changed

9 files changed

+4582
-2343
lines changed

build.mjs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function deleteOldDir() {
1818
await fs.rm(outdir, { recursive: true, force: true })
1919
}
2020

21-
async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
21+
async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, callback) {
2222
const shared = [
2323
'preact',
2424
'webextension-polyfill',
@@ -70,6 +70,12 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
7070
concatenateModules: !isAnalyzing,
7171
},
7272
plugins: [
73+
minimal
74+
? undefined
75+
: new webpack.ProvidePlugin({
76+
process: 'process/browser.js',
77+
Buffer: ['buffer', 'Buffer'],
78+
}),
7379
new ProgressBarPlugin({
7480
format: ' build [:bar] :percent (:elapsed seconds)',
7581
clear: false,
@@ -97,6 +103,14 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
97103
extensions: ['.jsx', '.mjs', '.js'],
98104
alias: {
99105
parse5: path.resolve(__dirname, 'node_modules/parse5'),
106+
...(minimal
107+
? {}
108+
: {
109+
util: path.resolve(__dirname, 'node_modules/util'),
110+
buffer: path.resolve(__dirname, 'node_modules/buffer'),
111+
stream: 'stream-browserify',
112+
crypto: 'crypto-browserify',
113+
}),
100114
},
101115
},
102116
module: {
@@ -206,7 +220,7 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
206220
},
207221
}
208222
: {},
209-
isWithoutKatex && isWithoutTiktoken
223+
minimal
210224
? {
211225
test: /styles\.scss$/,
212226
loader: 'string-replace-loader',
@@ -220,6 +234,32 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
220234
},
221235
}
222236
: {},
237+
minimal
238+
? {
239+
test: /index\.mjs$/,
240+
loader: 'string-replace-loader',
241+
options: {
242+
multiple: [
243+
{
244+
search: 'import { generateAnswersWithChatGLMApi }',
245+
replace: '//',
246+
},
247+
{
248+
search: 'await generateAnswersWithChatGLMApi',
249+
replace: '//',
250+
},
251+
{
252+
search: 'chatglmTurbo',
253+
replace: '//',
254+
},
255+
{
256+
search: "'chatglmTurbo",
257+
replace: '//',
258+
},
259+
],
260+
},
261+
}
262+
: {},
223263
],
224264
},
225265
})
@@ -305,13 +345,15 @@ async function build() {
305345
// )
306346
// await new Promise((r) => setTimeout(r, 5000))
307347
await runWebpack(
348+
true,
308349
true,
309350
true,
310351
generateWebpackCallback(() => finishOutput('-without-katex-and-tiktoken')),
311352
)
312353
await new Promise((r) => setTimeout(r, 10000))
313354
}
314355
await runWebpack(
356+
false,
315357
false,
316358
false,
317359
generateWebpackCallback(() => finishOutput('')),

0 commit comments

Comments
 (0)