Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ChatGLM API #567

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function deleteOldDir() {
await fs.rm(outdir, { recursive: true, force: true })
}

async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, callback) {
const shared = [
'preact',
'webextension-polyfill',
Expand Down Expand Up @@ -70,6 +70,12 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
concatenateModules: !isAnalyzing,
},
plugins: [
minimal
? undefined
: new webpack.ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
}),
new ProgressBarPlugin({
format: ' build [:bar] :percent (:elapsed seconds)',
clear: false,
Expand Down Expand Up @@ -97,6 +103,14 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
extensions: ['.jsx', '.mjs', '.js'],
alias: {
parse5: path.resolve(__dirname, 'node_modules/parse5'),
...(minimal
? {}
: {
util: path.resolve(__dirname, 'node_modules/util'),
buffer: path.resolve(__dirname, 'node_modules/buffer'),
stream: 'stream-browserify',
crypto: 'crypto-browserify',
}),
},
},
module: {
Expand Down Expand Up @@ -206,7 +220,7 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
},
}
: {},
isWithoutKatex && isWithoutTiktoken
minimal
? {
test: /styles\.scss$/,
loader: 'string-replace-loader',
Expand All @@ -220,6 +234,32 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, callback) {
},
}
: {},
minimal
? {
test: /index\.mjs$/,
loader: 'string-replace-loader',
options: {
multiple: [
{
search: 'import { generateAnswersWithChatGLMApi }',
replace: '//',
},
{
search: 'await generateAnswersWithChatGLMApi',
replace: '//',
},
{
search: 'chatglmTurbo',
replace: '//',
},
{
search: "'chatglmTurbo",
replace: '//',
},
],
},
}
: {},
],
},
})
Expand Down Expand Up @@ -305,13 +345,15 @@ async function build() {
// )
// await new Promise((r) => setTimeout(r, 5000))
await runWebpack(
true,
true,
true,
generateWebpackCallback(() => finishOutput('-without-katex-and-tiktoken')),
)
await new Promise((r) => setTimeout(r, 10000))
}
await runWebpack(
false,
false,
false,
generateWebpackCallback(() => finishOutput('')),
Expand Down
Loading