forked from cogentapps/chat-with-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create-react-app seems to struggle a bit [1] and many folks are recommending vite as an alternative, as that project is more active. For me the reason to switch to vite is to reduce dependencies and speed up the build process. Replacing create-react-app with vite reduce the number of dependencies from 1762 to 444. I was also quite surprised, by how small the actual diff in this commit is. From that perspective there is almost no discernible difference between the two tools. [1]: reactjs/react.dev#5487 (comment)
- Loading branch information
1 parent
9a69273
commit a3da33d
Showing
11 changed files
with
79 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,19 @@ | ||
import { OpenAIMessage } from "../chat/types"; | ||
import type { ChatHistoryTrimmerOptions } from "./chat-history-trimmer"; | ||
// @ts-ignore | ||
import tokenizer from 'workerize-loader!./worker'; | ||
import tokenizer from "./worker?worker&url"; | ||
|
||
let worker: any; | ||
const worker = new ComlinkWorker<typeof import("./worker")>( | ||
new URL(tokenizer, import.meta.url) | ||
); | ||
|
||
async function getWorker() { | ||
if (!worker) { | ||
worker = await tokenizer(); | ||
} | ||
return worker; | ||
} | ||
|
||
export async function runChatTrimmer(messages: OpenAIMessage[], options: ChatHistoryTrimmerOptions): Promise<OpenAIMessage[]> { | ||
const worker = await getWorker(); | ||
return worker.runChatTrimmer(messages, options); | ||
export async function runChatTrimmer( | ||
messages: OpenAIMessage[], | ||
options: ChatHistoryTrimmerOptions | ||
): Promise<OpenAIMessage[]> { | ||
return worker.runChatTrimmer(messages, options); | ||
} | ||
|
||
export async function countTokens(messages: OpenAIMessage[]) { | ||
const worker = await getWorker(); | ||
return await worker.countTokensForMessages(messages); | ||
return await worker.countTokensForMessages(messages); | ||
} | ||
|
||
// preload the worker | ||
getWorker().then(w => { | ||
(window as any).worker = w; | ||
}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite-plugin-comlink/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import react from "@vitejs/plugin-react"; | ||
import { defineConfig } from "vite"; | ||
import { comlink } from "vite-plugin-comlink"; | ||
|
||
export default defineConfig(() => { | ||
return { | ||
build: { | ||
outDir: "build", | ||
}, | ||
resolve: { | ||
alias: { | ||
"@ffmpeg/ffmpeg": "./src/stub.js", | ||
}, | ||
}, | ||
plugins: [ | ||
react({ | ||
babel: { | ||
plugins: [ | ||
[ | ||
"formatjs", | ||
{ | ||
idInterpolationPattern: "[sha512:contenthash:base64:6]", | ||
ast: true, | ||
}, | ||
], | ||
], | ||
}, | ||
}), | ||
comlink(), | ||
], | ||
worker: { | ||
plugins: [comlink()], | ||
}, | ||
}; | ||
}); |