Skip to content

Commit

Permalink
Merge branch 'main' into service-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
cogentapps authored Jul 9, 2023
2 parents d5131d1 + 4f5e7fb commit f9122c5
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 163 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ COPY ./app/tsconfig.json ./
# Install Node.js dependencies
RUN npm install

# Copy craco.config.js, public, and src directories
COPY ./app/craco.config.js ./craco.config.js
# Copy public, and src directories
COPY ./app/public ./public
COPY ./app/src ./src

Expand Down
43 changes: 0 additions & 43 deletions app/craco.config.js

This file was deleted.

12 changes: 7 additions & 5 deletions app/public/index.html → app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="/favicon.ico" />
<!-- mobile app viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="An open source ChatGPT app with a voice." />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="apple-touch-icon" href="/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="manifest" href="/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
Notice the use of in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
Expand Down Expand Up @@ -86,6 +86,8 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->

<script type="module" src="/src/index.tsx"></script>
</body>

</html>
34 changes: 9 additions & 25 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.2.3",
"dependencies": {
"@chengsokdara/use-whisper": "^0.2.0",
"@emotion/css": "^11.10.6",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@mantine/core": "^5.10.5",
Expand All @@ -13,9 +12,8 @@
"@mantine/spotlight": "^5.10.5",
"@msgpack/msgpack": "^3.0.0-beta2",
"@reduxjs/toolkit": "^1.9.3",
"@svgr/webpack": "^6.5.1",
"broadcast-channel": "^4.20.2",
"buffer": "^6.0.3",
"comlink": "^4.4.1",
"events": "^3.3.0",
"idb-keyval": "^6.2.0",
"jshashes": "^1.0.8",
Expand All @@ -30,34 +28,24 @@
"react-redux": "^8.0.5",
"react-router-dom": "^6.8.2",
"react-syntax-highlighter": "^15.5.0",
"redux": "4.2.1",
"redux-persist": "^6.0.0",
"rehype-katex": "^6.0.2",
"remark-gfm": "^3.0.1",
"remark-math": "^5.1.1",
"sentence-splitter": "^4.2.0",
"slugify": "^1.6.5",
"uuid": "^9.0.0",
"workerize-loader": "^2.0.2",
"y-indexeddb": "^9.0.9",
"y-protocols": "^1.0.5",
"yjs": "^13.5.50"
},
"overrides": {
"@svgr/webpack": "$@svgr/webpack"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "craco eject",
"start": "vite",
"build": "vite build",
"serve": "vite preview",
"extract": "formatjs extract 'src/**/*.ts*' --ignore='**/*.d.ts' --out-file public/lang/en-us.json --id-interpolation-pattern '[sha512:contenthash:base64:6]'"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand All @@ -71,20 +59,16 @@
]
},
"devDependencies": {
"@craco/craco": "^7.1.0",
"@formatjs/cli": "^6.0.4",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.13",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/react-helmet": "^6.1.6",
"@types/react-syntax-highlighter": "^15.5.6",
"@types/uuid": "^9.0.1",
"babel-plugin-formatjs": "^10.4.0",
"craco-wasm": "^0.0.1",
"http-proxy-middleware": "^2.0.6",
"react-scripts": "^5.0.1",
"sass": "^1.58.3",
"typescript": "^4.9.5"
"@vitejs/plugin-react": "^4.0.2",
"babel-plugin-formatjs": "^10.5.3",
"typescript": "^4.9.5",
"vite": "^4.4.1"
}
}
50 changes: 14 additions & 36 deletions app/public/lang/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"+G35mR": {
"defaultMessage": "Open sidebar"
},
"+H2Qtw": {
"defaultMessage": "Show quick settings below message input"
},
"+LMWDJ": {
"defaultMessage": "Chat History",
"description": "Heading for the chat history screen"
Expand Down Expand Up @@ -56,8 +53,8 @@
"defaultMessage": "Save changes",
"description": "Label for a button that appears when the user is editing the text of one of their messages, to save the changes"
},
"E4+fv5": {
"defaultMessage": "Auto-scroll to the bottom of the page when opening a chat"
"CIe3Dt": {
"defaultMessage": "Note: This model will only work if your OpenAI account has been granted you have been given access to it. <a>Request access here.</a>"
},
"FEzBCd": {
"defaultMessage": "Untitled",
Expand All @@ -73,22 +70,19 @@
"KKa5Br": {
"defaultMessage": "Give ChatGPT a realisic human voice by connecting your ElevenLabs account (preview the available voices below). <a>Click here to sign up.</a>"
},
"KbUcBc": {
"defaultMessage": "Your ElevenLabs API Key"
},
"L5s+z7": {
"defaultMessage": "OpenAI API key usage is billed at a pay-as-you-go rate, separate from your ChatGPT subscription."
},
"LHOuNA": {
"defaultMessage": "Auto-scroll while generating a response"
},
"MI5gZ+": {
"defaultMessage": "Download SVG"
},
"N2NGTf": {
"defaultMessage": "Chat with GPT",
"description": "app name"
},
"NRJ4IQ": {
"defaultMessage": "Note: GPT-4 will only work if your OpenAI account has been granted access to the new model. <a>Request access here.</a>"
},
"NgCT/u": {
"defaultMessage": "Enter your email address"
},
Expand All @@ -105,17 +99,17 @@
"SQJto2": {
"defaultMessage": "Sign in"
},
"SQh9En": {
"defaultMessage": "Sign in <h>to sync</h>",
"description": "Label for sign in button, indicating the purpose of signing in is to sync your data between devices"
},
"T8gKkC": {
"defaultMessage": "Delete this chat"
},
"Tgo3vj": {
"defaultMessage": "Edit",
"description": "Label for the button the user can click to edit the text of one of their messages"
},
"UbN3HK": {
"defaultMessage": "Sign in <h>to sync</h>",
"description": "Label for sign in button, which indicates that the purpose of signing in is to sync your data between devices. Less important text inside <h> tags is hidden on small screens."
},
"VL24Xt": {
"defaultMessage": "Search your chats"
},
Expand All @@ -126,10 +120,6 @@
"defaultMessage": "Or sign in to an existing account",
"description": "Label for a button on the Create Account page that lets the user sign into their existing account instead"
},
"aR9WsJ": {
"defaultMessage": "UI Settings",
"description": "Heading for the setting that lets users customize various UI elements"
},
"bIacvz": {
"defaultMessage": "Chat with GPT - Unofficial ChatGPT app",
"description": "HTML title tag"
Expand All @@ -138,9 +128,6 @@
"defaultMessage": "Hello, how can I help you today?",
"description": "A friendly message that appears at the start of new chat sessions"
},
"gNu/AE": {
"defaultMessage": "Show microphone button in message input"
},
"gzJlXS": {
"defaultMessage": "Share",
"description": "Label for a button which shares the text of a chat message using the user device's share functionality"
Expand All @@ -155,16 +142,18 @@
"defaultMessage": "Save and Close",
"description": "Label for the button that closes the Settings screen, saving any changes"
},
"jU4MQH": {
"defaultMessage": "Rename this chat"
},
"jtu3jt": {
"defaultMessage": "You can find your API key by clicking your avatar or initials in the top right of the ElevenLabs website, then clicking Profile. Your API key is stored only on this device and never transmitted to anyone except ElevenLabs."
},
"ljHOzQ": {
"defaultMessage": "Copied",
"description": "Label for copy-to-clipboard button after a successful copy"
},
"pv41j8": {
"defaultMessage": "Temperature: {temperature, number, ::.0}",
"description": "Label for the button that opens a modal for setting the 'temperature' (randomness) of AI responses"
"mL4Q28": {
"defaultMessage": "Custom Voice ID"
},
"raQMIg": {
"defaultMessage": "Cancel",
Expand Down Expand Up @@ -196,20 +185,9 @@
"defaultMessage": "Copy",
"description": "Label for copy-to-clipboard button"
},
"w5Dmuu": {
"defaultMessage": "Customize system prompt",
"description": "Label for the button that opens a modal for customizing the 'system prompt', a message used to customize and influence how the AI responds."
},
"xXbJso": {
"defaultMessage": "Sign out"
},
"xqpqZE": {
"defaultMessage": "Your Elevenlabs API Key"
},
"y1F8Hs": {
"defaultMessage": "Your OpenAI API Key",
"description": "Heading for the OpenAI API key setting on the settings screen"
},
"zBmup+": {
"defaultMessage": "Regenerate",
"description": "Label for the button used to ask the AI to regenerate one of its messages. Since message generations are stochastic, the resulting message will be different."
Expand Down
23 changes: 14 additions & 9 deletions app/src/core/tokenizer/bpe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { compareUint8Array } from "../utils";

const MAX_NUM_THREADS = 128;

type MergeRange = { start: number, end: number };

const textDecoder = new TextDecoder();
const textEncoder = new TextEncoder();

export class RankMap {
private values = new Map<string, number>();

Expand All @@ -14,23 +19,23 @@ export class RankMap {
}

public set(bytes: Uint8Array, rank: number) {
const key = Buffer.from(bytes).toString();
const key = textDecoder.decode(bytes);
this.values.set(key, rank);
}

public get(bytes: Uint8Array) {
const key = Buffer.from(bytes).toString();
const key = textDecoder.decode(bytes);
return this.values.get(key);
}

public keys() {
return Array.from(this.values.keys()).map(k => Buffer.from(k));
return Array.from(this.values.keys()).map(k => textEncoder.encode(k));
}

public inverted() {
const inverted = new Map<number, Uint8Array>();
for (const [key, value] of Array.from(this.values.entries())) {
inverted.set(value, new Uint8Array(Buffer.from(key)));
inverted.set(value, textEncoder.encode(key));
}
return inverted;
}
Expand Down Expand Up @@ -100,10 +105,10 @@ export class CoreBPE {
const decoder: Map<number, Uint8Array> = encoder.inverted();

const specialTokensDecoder: Map<number, Uint8Array> = new Map(
Array.from(specialTokensEncoder.entries()).map(([k, v]) => [v, new Uint8Array(Buffer.from(k))])
Array.from(specialTokensEncoder.entries()).map(([k, v]) => [v, textEncoder.encode(k)])
);
const sortedTokenBytes: Uint8Array[] = Array.from(encoder.keys());
sortedTokenBytes.sort((a, b) => Buffer.compare(a, b));
sortedTokenBytes.sort((a, b) => compareUint8Array(a, b));

this.encoder = encoder;
this.specialTokensEncoder = specialTokensEncoder;
Expand Down Expand Up @@ -136,7 +141,7 @@ export class CoreBPE {
const ret: number[] = [];
let match: RegExpExecArray | null;
while ((match = regex.exec(text)) !== null) {
const piece = new Uint8Array(Buffer.from(match[0]));
const piece = textEncoder.encode(match[0]);
const token = this.encoder.get(piece);
if (token !== undefined) {
ret.push(token);
Expand Down Expand Up @@ -167,7 +172,7 @@ export class CoreBPE {
const end = nextSpecial === null ? text.length : nextSpecial.index;
let match: RegExpExecArray | null;
while ((match = regex.exec(text.slice(start, end))) !== null) {
const piece = new Uint8Array(Buffer.from(match[0]));
const piece = textEncoder.encode(match[0]);
const token = this.encoder.get(piece);
if (token !== undefined) {
lastPieceTokenLen = 1;
Expand Down Expand Up @@ -208,7 +213,7 @@ export class CoreBPE {
if (token !== undefined) {
return token;
}
const pieceStr = Buffer.from(piece).toString("utf-8");
const pieceStr = textDecoder.decode(piece);
if (this.specialTokensEncoder.has(pieceStr)) {
return this.specialTokensEncoder.get(pieceStr)!;
}
Expand Down
Loading

0 comments on commit f9122c5

Please sign in to comment.