feat: gravatar support added

This commit is contained in:
Timothy J. Baek 2023-11-05 13:25:23 -08:00
parent 201b5161f4
commit edd3aaeffe
4 changed files with 76 additions and 11 deletions

11
package-lock.json generated
View file

@ -13,6 +13,7 @@
"highlight.js": "^11.9.0", "highlight.js": "^11.9.0",
"http-server": "^14.1.1", "http-server": "^14.1.1",
"idb": "^7.1.1", "idb": "^7.1.1",
"js-sha256": "^0.10.1",
"katex": "^0.16.9", "katex": "^0.16.9",
"marked": "^9.1.0", "marked": "^9.1.0",
"svelte-french-toast": "^1.2.0", "svelte-french-toast": "^1.2.0",
@ -2527,6 +2528,11 @@
"jiti": "bin/jiti.js" "jiti": "bin/jiti.js"
} }
}, },
"node_modules/js-sha256": {
"version": "0.10.1",
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.10.1.tgz",
"integrity": "sha512-5obBtsz9301ULlsgggLg542s/jqtddfOpV5KJc4hajc9JV8GeY2gZHSVpYBn4nWqAUTJ9v+xwtbJ1mIBgIH5Vw=="
},
"node_modules/js-yaml": { "node_modules/js-yaml": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
@ -5910,6 +5916,11 @@
"integrity": "sha512-3TV69ZbrvV6U5DfQimop50jE9Dl6J8O1ja1dvBbMba/sZ3YBEQqJ2VZRoQPVnhlzjNtU1vaXRZVrVjU4qtm8yA==", "integrity": "sha512-3TV69ZbrvV6U5DfQimop50jE9Dl6J8O1ja1dvBbMba/sZ3YBEQqJ2VZRoQPVnhlzjNtU1vaXRZVrVjU4qtm8yA==",
"dev": true "dev": true
}, },
"js-sha256": {
"version": "0.10.1",
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.10.1.tgz",
"integrity": "sha512-5obBtsz9301ULlsgggLg542s/jqtddfOpV5KJc4hajc9JV8GeY2gZHSVpYBn4nWqAUTJ9v+xwtbJ1mIBgIH5Vw=="
},
"js-yaml": { "js-yaml": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",

View file

@ -44,6 +44,7 @@
"highlight.js": "^11.9.0", "highlight.js": "^11.9.0",
"http-server": "^14.1.1", "http-server": "^14.1.1",
"idb": "^7.1.1", "idb": "^7.1.1",
"js-sha256": "^0.10.1",
"katex": "^0.16.9", "katex": "^0.16.9",
"marked": "^9.1.0", "marked": "^9.1.0",
"svelte-french-toast": "^1.2.0", "svelte-french-toast": "^1.2.0",

View file

@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import sha256 from 'js-sha256';
import Modal from '../common/Modal.svelte'; import Modal from '../common/Modal.svelte';
import { API_BASE_URL as BUILD_TIME_API_BASE_URL } from '$lib/constants'; import { API_BASE_URL as BUILD_TIME_API_BASE_URL } from '$lib/constants';
@ -12,7 +13,6 @@
// General // General
let API_BASE_URL = BUILD_TIME_API_BASE_URL; let API_BASE_URL = BUILD_TIME_API_BASE_URL;
let OPENAI_API_KEY = '';
let system = ''; let system = '';
// Models // Models
@ -28,6 +28,23 @@
let top_k = 40; let top_k = 40;
let top_p = 0.9; let top_p = 0.9;
// Addons
let gravatarEmail = '';
let OPENAI_API_KEY = '';
function getGravatarURL(email) {
// Trim leading and trailing whitespace from
// an email address and force all characters
// to lower case
const address = String(email).trim().toLowerCase();
// Create a SHA256 hash of the final string
const hash = sha256(address);
// Grab the actual image URL
return `https://www.gravatar.com/avatar/${hash}`;
}
const splitStream = (splitOn) => { const splitStream = (splitOn) => {
let buffer = ''; let buffer = '';
return new TransformStream({ return new TransformStream({
@ -166,7 +183,6 @@
console.log(settings); console.log(settings);
API_BASE_URL = settings.API_BASE_URL ?? BUILD_TIME_API_BASE_URL; API_BASE_URL = settings.API_BASE_URL ?? BUILD_TIME_API_BASE_URL;
OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
system = settings.system ?? ''; system = settings.system ?? '';
seed = settings.seed ?? 0; seed = settings.seed ?? 0;
@ -174,6 +190,9 @@
repeat_penalty = settings.repeat_penalty ?? 1.1; repeat_penalty = settings.repeat_penalty ?? 1.1;
top_k = settings.top_k ?? 40; top_k = settings.top_k ?? 40;
top_p = settings.top_p ?? 0.9; top_p = settings.top_p ?? 0.9;
OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
gravatarEmail = settings.gravatarEmail ?? '';
} }
</script> </script>
@ -582,8 +601,43 @@
</div> </div>
</div> </div>
{:else if selectedTab === 'addons'} {:else if selectedTab === 'addons'}
<div class="flex flex-col h-full justify-between space-y-3 text-sm"> <form
class="flex flex-col h-full justify-between space-y-3 text-sm"
on:submit|preventDefault={() => {
saveSettings({
gravatarEmail: gravatarEmail !== '' ? gravatarEmail : undefined,
gravatarUrl: gravatarEmail !== '' ? getGravatarURL(gravatarEmail) : undefined,
OPENAI_API_KEY: OPENAI_API_KEY !== '' ? OPENAI_API_KEY : undefined
});
show = false;
}}
>
<div class=" space-y-3"> <div class=" space-y-3">
<div>
<div class=" mb-2.5 text-sm font-medium">
Gravatar Email <span class=" text-gray-400 text-sm">(optional)</span>
</div>
<div class="flex w-full">
<div class="flex-1">
<input
class="w-full rounded py-2 px-4 text-sm text-gray-300 bg-gray-800 outline-none"
placeholder="Enter Your Email"
bind:value={gravatarEmail}
autocomplete="off"
type="email"
/>
</div>
</div>
<div class="mt-2 text-xs text-gray-500">
Changes user profile image to match your <a
class=" text-gray-300 font-medium"
href="https://gravatar.com/"
target="_blank">Gravatar.</a
>
</div>
</div>
<hr class=" border-gray-700" />
<div> <div>
<div class=" mb-2.5 text-sm font-medium"> <div class=" mb-2.5 text-sm font-medium">
OpenAI API Key <span class=" text-gray-400 text-sm">(optional)</span> OpenAI API Key <span class=" text-gray-400 text-sm">(optional)</span>
@ -607,17 +661,12 @@
<div class="flex justify-end pt-3 text-sm font-medium"> <div class="flex justify-end pt-3 text-sm font-medium">
<button <button
class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 transition rounded" class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 transition rounded"
on:click={() => { type="submit"
saveSettings({
OPENAI_API_KEY: OPENAI_API_KEY !== '' ? OPENAI_API_KEY : undefined
});
show = false;
}}
> >
Save Save
</button> </button>
</div> </div>
</div> </form>
{/if} {/if}
</div> </div>
</div> </div>

View file

@ -871,7 +871,11 @@
<div class="space-x-7 flex w-full"> <div class="space-x-7 flex w-full">
<div class=""> <div class="">
<img <img
src="/{message.role == 'user' ? 'user' : 'favicon'}.png" src="{message.role == 'user'
? settings.gravatarUrl
? settings.gravatarUrl
: '/user'
: '/favicon'}.png"
class=" max-w-[32px] object-cover rounded" class=" max-w-[32px] object-cover rounded"
/> />
</div> </div>