Skip to content

Commit

Permalink
Add ChatGLM API (#567)
Browse files Browse the repository at this point in the history
* Add ChatGLM API

* add minimal build

* a small patch

---------

Co-authored-by: josc146 <josStorer@outlook.com>
  • Loading branch information
AceLam and josStorer committed Dec 3, 2023
1 parent 70d6b79 commit d24958f
Show file tree
Hide file tree
Showing 9 changed files with 4,582 additions and 2,343 deletions.
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

0 comments on commit d24958f

Please sign in to comment.