From 7ef5aa520caa0fbb3394ef2531b371dac6d6a185 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 13 Aug 2024 11:12:35 +0100 Subject: [PATCH] chore: format --- docs/CONTRIBUTING.md | 1 - src/app.html | 2 +- src/lib/apis/openai/index.ts | 2 +- src/lib/components/ChangelogModal.svelte | 12 +- .../admin/Settings/Documents.svelte | 2 +- src/lib/components/chat/Chat.svelte | 32 ++--- .../chat/MessageInput/CallOverlay.svelte | 32 ++--- .../chat/MessageInput/Documents.svelte | 2 +- src/lib/components/chat/Messages.svelte | 8 +- .../chat/Messages/CitationsModal.svelte | 4 +- .../chat/Messages/ResponseMessage.svelte | 4 +- .../chat/Messages/UserMessage.svelte | 14 +- .../chat/ModelSelector/Selector.svelte | 2 +- src/lib/components/chat/Settings/About.svelte | 4 +- src/lib/components/common/Valves.svelte | 2 +- .../components/layout/Sidebar/ChatItem.svelte | 12 +- .../components/playground/Playground.svelte | 2 +- src/lib/components/workspace/Documents.svelte | 2 +- src/lib/components/workspace/Models.svelte | 4 +- .../Models/Knowledge/Selector.svelte | 2 +- src/lib/utils/index.ts | 4 +- src/lib/utils/katex-extension.ts | 127 +++++++++--------- .../(app)/workspace/models/edit/+page.svelte | 6 +- src/routes/auth/+page.svelte | 21 ++- 24 files changed, 160 insertions(+), 143 deletions(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 325964b1a..ec8a79bbc 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -22,7 +22,6 @@ Noticed something off? Have an idea? Check our [Issues tab](https://github.com/o > [!IMPORTANT] > > - **Template Compliance:** Please be aware that failure to follow the provided issue template, or not providing the requested information at all, will likely result in your issue being closed without further consideration. This approach is critical for maintaining the manageability and integrity of issue tracking. -> > - **Detail is Key:** To ensure your issue is understood and can be effectively addressed, it's imperative to include comprehensive details. Descriptions should be clear, including steps to reproduce, expected outcomes, and actual results. Lack of sufficient detail may hinder our ability to resolve your issue. ### 🧭 Scope of Support diff --git a/src/app.html b/src/app.html index 5d48e1d7e..718f7e194 100644 --- a/src/app.html +++ b/src/app.html @@ -1,4 +1,4 @@ - + diff --git a/src/lib/apis/openai/index.ts b/src/lib/apis/openai/index.ts index 2a52ebb32..b075d634b 100644 --- a/src/lib/apis/openai/index.ts +++ b/src/lib/apis/openai/index.ts @@ -260,7 +260,7 @@ export const getOpenAIModelsDirect = async ( throw error; } - const models = Array.isArray(res) ? res : res?.data ?? null; + const models = Array.isArray(res) ? res : (res?.data ?? null); return models .map((model) => ({ id: model.id, name: model.name ?? model.id, external: true })) diff --git a/src/lib/components/ChangelogModal.svelte b/src/lib/components/ChangelogModal.svelte index 48156f924..6a24ea5d9 100644 --- a/src/lib/components/ChangelogModal.svelte +++ b/src/lib/components/ChangelogModal.svelte @@ -75,12 +75,12 @@ class="font-semibold uppercase text-xs {section === 'added' ? 'text-white bg-blue-600' : section === 'fixed' - ? 'text-white bg-green-600' - : section === 'changed' - ? 'text-white bg-yellow-600' - : section === 'removed' - ? 'text-white bg-red-600' - : ''} w-fit px-3 rounded-full my-2.5" + ? 'text-white bg-green-600' + : section === 'changed' + ? 'text-white bg-yellow-600' + : section === 'removed' + ? 'text-white bg-red-600' + : ''} w-fit px-3 rounded-full my-2.5" > {section} diff --git a/src/lib/components/admin/Settings/Documents.svelte b/src/lib/components/admin/Settings/Documents.svelte index 1b0b2c3fa..bac84902f 100644 --- a/src/lib/components/admin/Settings/Documents.svelte +++ b/src/lib/components/admin/Settings/Documents.svelte @@ -112,7 +112,7 @@ url: OpenAIUrl, batch_size: OpenAIBatchSize } - } + } : {}) }).catch(async (error) => { toast.error(error); diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 2c42c2046..a290d5d3d 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -579,8 +579,8 @@ let selectedModelIds = modelId ? [modelId] : atSelectedModel !== undefined - ? [atSelectedModel.id] - : selectedModels; + ? [atSelectedModel.id] + : selectedModels; // Create response messages for each selected model const responseMessageIds = {}; @@ -739,11 +739,11 @@ ? await getAndUpdateUserLocation(localStorage.token) : undefined )}${ - responseMessage?.userContext ?? null + (responseMessage?.userContext ?? null) ? `\n\nUser Context:\n${responseMessage?.userContext ?? ''}` : '' }` - } + } : undefined, ...messages ] @@ -811,10 +811,10 @@ options: { ...(params ?? $settings.params ?? {}), stop: - params?.stop ?? $settings?.params?.stop ?? undefined + (params?.stop ?? $settings?.params?.stop ?? undefined) ? (params?.stop.split(',').map((token) => token.trim()) ?? $settings.params.stop).map( (str) => decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"')) - ) + ) : undefined, num_predict: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined, repeat_penalty: @@ -1056,10 +1056,10 @@ stream: true, model: model.id, stream_options: - model.info?.meta?.capabilities?.usage ?? false + (model.info?.meta?.capabilities?.usage ?? false) ? { include_usage: true - } + } : undefined, messages: [ params?.system || $settings.system || (responseMessage?.userContext ?? null) @@ -1072,11 +1072,11 @@ ? await getAndUpdateUserLocation(localStorage.token) : undefined )}${ - responseMessage?.userContext ?? null + (responseMessage?.userContext ?? null) ? `\n\nUser Context:\n${responseMessage?.userContext ?? ''}` : '' }` - } + } : undefined, ...messages ] @@ -1092,7 +1092,7 @@ text: arr.length - 1 !== idx ? message.content - : message?.raContent ?? message.content + : (message?.raContent ?? message.content) }, ...message.files .filter((file) => file.type === 'image') @@ -1103,20 +1103,20 @@ } })) ] - } + } : { content: arr.length - 1 !== idx ? message.content - : message?.raContent ?? message.content - }) + : (message?.raContent ?? message.content) + }) })), seed: params?.seed ?? $settings?.params?.seed ?? undefined, stop: - params?.stop ?? $settings?.params?.stop ?? undefined + (params?.stop ?? $settings?.params?.stop ?? undefined) ? (params?.stop.split(',').map((token) => token.trim()) ?? $settings.params.stop).map( (str) => decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"')) - ) + ) : undefined, temperature: params?.temperature ?? $settings?.params?.temperature ?? undefined, top_p: params?.top_p ?? $settings?.params?.top_p ?? undefined, diff --git a/src/lib/components/chat/MessageInput/CallOverlay.svelte b/src/lib/components/chat/MessageInput/CallOverlay.svelte index e28b4b5bd..ac14cc74e 100644 --- a/src/lib/components/chat/MessageInput/CallOverlay.svelte +++ b/src/lib/components/chat/MessageInput/CallOverlay.svelte @@ -609,10 +609,10 @@ style="font-size:{rmsLevel * 100 > 4 ? '4.5' : rmsLevel * 100 > 2 - ? '4.25' - : rmsLevel * 100 > 1 - ? '3.75' - : '3.5'}rem;width: 100%; text-align:center;" + ? '4.25' + : rmsLevel * 100 > 1 + ? '3.75' + : '3.5'}rem;width: 100%; text-align:center;" > {emoji} @@ -658,10 +658,10 @@ class=" {rmsLevel * 100 > 4 ? ' size-[4.5rem]' : rmsLevel * 100 > 2 - ? ' size-16' - : rmsLevel * 100 > 1 - ? 'size-14' - : 'size-12'} transition-all rounded-full {(model?.info?.meta + ? ' size-16' + : rmsLevel * 100 > 1 + ? 'size-14' + : 'size-12'} transition-all rounded-full {(model?.info?.meta ?.profile_image_url ?? '/static/favicon.png') !== '/static/favicon.png' ? ' bg-cover bg-center bg-no-repeat' : 'bg-black dark:bg-white'} bg-black dark:bg-white" @@ -691,10 +691,10 @@ style="font-size:{rmsLevel * 100 > 4 ? '13' : rmsLevel * 100 > 2 - ? '12' - : rmsLevel * 100 > 1 - ? '11.5' - : '11'}rem;width:100%;text-align:center;" + ? '12' + : rmsLevel * 100 > 1 + ? '11.5' + : '11'}rem;width:100%;text-align:center;" > {emoji} @@ -740,10 +740,10 @@ class=" {rmsLevel * 100 > 4 ? ' size-52' : rmsLevel * 100 > 2 - ? 'size-48' - : rmsLevel * 100 > 1 - ? 'size-[11.5rem]' - : 'size-44'} transition-all rounded-full {(model?.info?.meta + ? 'size-48' + : rmsLevel * 100 > 1 + ? 'size-[11.5rem]' + : 'size-44'} transition-all rounded-full {(model?.info?.meta ?.profile_image_url ?? '/static/favicon.png') !== '/static/favicon.png' ? ' bg-cover bg-center bg-no-repeat' : 'bg-black dark:bg-white'} " diff --git a/src/lib/components/chat/MessageInput/Documents.svelte b/src/lib/components/chat/MessageInput/Documents.svelte index 64c4bc458..50956e4c0 100644 --- a/src/lib/components/chat/MessageInput/Documents.svelte +++ b/src/lib/components/chat/MessageInput/Documents.svelte @@ -27,7 +27,7 @@ title: $i18n.t('All Documents'), collection_names: $documents.map((doc) => doc.collection_name) } - ] + ] : []), ...$documents .reduce((a, e, i, arr) => { diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 9e3c147b1..fb6754e86 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -305,7 +305,7 @@ {#each messages as message, messageIdx}
@@ -317,10 +317,10 @@ {message} isFirstMessage={messageIdx === 0} siblings={message.parentId !== null - ? history.messages[message.parentId]?.childrenIds ?? [] - : Object.values(history.messages) + ? (history.messages[message.parentId]?.childrenIds ?? []) + : (Object.values(history.messages) .filter((message) => message.parentId === null) - .map((message) => message.id) ?? []} + .map((message) => message.id) ?? [])} {confirmEditMessage} {showPreviousMessage} {showNextMessage} diff --git a/src/lib/components/chat/Messages/CitationsModal.svelte b/src/lib/components/chat/Messages/CitationsModal.svelte index 83b82f8f8..e8d63e080 100644 --- a/src/lib/components/chat/Messages/CitationsModal.svelte +++ b/src/lib/components/chat/Messages/CitationsModal.svelte @@ -60,8 +60,8 @@ href={document?.metadata?.file_id ? `/api/v1/files/${document?.metadata?.file_id}/content` : document.source.name.includes('http') - ? document.source.name - : `#`} + ? document.source.name + : `#`} target="_blank" > {document?.metadata?.name ?? document.source.name} diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 9621d67b0..150f26931 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -191,7 +191,7 @@ const res = await synthesizeOpenAISpeech( localStorage.token, $settings?.audio?.tts?.defaultVoice === $config.audio.tts.voice - ? $settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice + ? ($settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice) : $config?.audio?.tts?.voice, sentence ).catch((error) => { @@ -803,7 +803,7 @@ 100 ) / 100 } tokens` ?? 'N/A' - }
+ }
prompt_token/s: ${ Math.round( ((message.info.prompt_eval_count ?? 0) / diff --git a/src/lib/components/chat/Messages/UserMessage.svelte b/src/lib/components/chat/Messages/UserMessage.svelte index 22b7081d7..1dea97f11 100644 --- a/src/lib/components/chat/Messages/UserMessage.svelte +++ b/src/lib/components/chat/Messages/UserMessage.svelte @@ -62,8 +62,8 @@ {#if !($settings?.chatBubble ?? true)} m.id === message.user)?.info?.meta?.profile_image_url ?? '/user.png' - : user?.profile_image_url ?? '/user.png'} + ? ($models.find((m) => m.id === message.user)?.info?.meta?.profile_image_url ?? '/user.png') + : (user?.profile_image_url ?? '/user.png')} /> {/if}
@@ -96,7 +96,7 @@ {#if message.files}
{#each message.files as file} -
+
{#if file.type === 'image'} input {:else} @@ -162,12 +162,12 @@
{:else}
-
+
{message.content}
@@ -175,7 +175,7 @@
diff --git a/src/lib/components/chat/ModelSelector/Selector.svelte b/src/lib/components/chat/ModelSelector/Selector.svelte index d36f3aa72..3471d344a 100644 --- a/src/lib/components/chat/ModelSelector/Selector.svelte +++ b/src/lib/components/chat/ModelSelector/Selector.svelte @@ -66,7 +66,7 @@ $: filteredItems = searchValue ? fuse.search(searchValue).map((e) => { return e.item; - }) + }) : items.filter((item) => !item.model?.info?.meta?.hidden); const pullModelHandler = async () => { diff --git a/src/lib/components/chat/Settings/About.svelte b/src/lib/components/chat/Settings/About.svelte index 11177d45b..2c21e3926 100644 --- a/src/lib/components/chat/Settings/About.svelte +++ b/src/lib/components/chat/Settings/About.svelte @@ -65,8 +65,8 @@ {updateAvailable === null ? $i18n.t('Checking for updates...') : updateAvailable - ? `(v${version.latest} ${$i18n.t('available!')})` - : $i18n.t('(latest)')} + ? `(v${version.latest} ${$i18n.t('available!')})` + : $i18n.t('(latest)')}
diff --git a/src/lib/components/common/Valves.svelte b/src/lib/components/common/Valves.svelte index cf138082f..e88253f3f 100644 --- a/src/lib/components/common/Valves.svelte +++ b/src/lib/components/common/Valves.svelte @@ -27,7 +27,7 @@ on:click={() => { valves[property] = (valves[property] ?? null) === null - ? valvesSpec.properties[property]?.default ?? '' + ? (valvesSpec.properties[property]?.default ?? '') : null; dispatch('change'); diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index 859366949..5b2542d7d 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -83,8 +83,8 @@ class=" w-full flex justify-between rounded-xl px-3 py-2 {chat.id === $chatId || confirmEdit ? 'bg-gray-200 dark:bg-gray-900' : selected - ? 'bg-gray-100 dark:bg-gray-950' - : 'group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis" + ? 'bg-gray-100 dark:bg-gray-950' + : 'group-hover:bg-gray-100 dark:group-hover:bg-gray-950'} whitespace-nowrap text-ellipsis" > { dispatch('select'); @@ -134,8 +134,8 @@ {chat.id === $chatId || confirmEdit ? 'from-gray-200 dark:from-gray-900' : selected - ? 'from-gray-100 dark:from-gray-950' - : 'invisible group-hover:visible from-gray-100 dark:from-gray-950'} + ? 'from-gray-100 dark:from-gray-950' + : 'invisible group-hover:visible from-gray-100 dark:from-gray-950'} absolute right-[10px] top-[6px] py-1 pr-2 pl-5 bg-gradient-to-l from-80% to-transparent" diff --git a/src/lib/components/playground/Playground.svelte b/src/lib/components/playground/Playground.svelte index e99014cab..6b0513b00 100644 --- a/src/lib/components/playground/Playground.svelte +++ b/src/lib/components/playground/Playground.svelte @@ -121,7 +121,7 @@ ? { role: 'system', content: system - } + } : undefined, ...messages ].filter((message) => message) diff --git a/src/lib/components/workspace/Documents.svelte b/src/lib/components/workspace/Documents.svelte index 017034371..726a82d59 100644 --- a/src/lib/components/workspace/Documents.svelte +++ b/src/lib/components/workspace/Documents.svelte @@ -88,7 +88,7 @@ tags?.length > 0 ? { tags: tags - } + } : null ).catch((error) => { toast.error(error); diff --git a/src/lib/components/workspace/Models.svelte b/src/lib/components/workspace/Models.svelte index fde1e7710..0c31994bd 100644 --- a/src/lib/components/workspace/Models.svelte +++ b/src/lib/components/workspace/Models.svelte @@ -292,7 +292,7 @@ >
@@ -305,7 +305,7 @@
{model.name}
diff --git a/src/lib/components/workspace/Models/Knowledge/Selector.svelte b/src/lib/components/workspace/Models/Knowledge/Selector.svelte index a09eaf34f..52d73540e 100644 --- a/src/lib/components/workspace/Models/Knowledge/Selector.svelte +++ b/src/lib/components/workspace/Models/Knowledge/Selector.svelte @@ -25,7 +25,7 @@ title: $i18n.t('All Documents'), collection_names: $documents.map((doc) => doc.collection_name) } - ] + ] : []), ...$documents .reduce((a, e, i, arr) => { diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index de3a2ca2c..92c6acd8f 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -227,7 +227,7 @@ export const generateInitialsImage = (name) => { const initials = sanitizedName.length > 0 ? sanitizedName[0] + - (sanitizedName.split(' ').length > 1 + (sanitizedName.split(' ').length > 1 ? sanitizedName[sanitizedName.lastIndexOf(' ') + 1] : '') : ''; @@ -286,7 +286,7 @@ export const compareVersion = (latest, current) => { numeric: true, sensitivity: 'case', caseFirst: 'upper' - }) < 0; + }) < 0; }; export const findWordIndices = (text) => { diff --git a/src/lib/utils/katex-extension.ts b/src/lib/utils/katex-extension.ts index 4d0bd99e5..8db411b1b 100644 --- a/src/lib/utils/katex-extension.ts +++ b/src/lib/utils/katex-extension.ts @@ -1,80 +1,83 @@ import katex from 'katex'; -const inlineRule = /^(\${1,2})(?!\$)((?:\\.|[^\\\n])*?(?:\\.|[^\\\n\$]))\1(?=[\s?!\.,:?!。,:]|$)/; +const inlineRule = + /^(\${1,2})(?!\$)((?:\\.|[^\\\n])*?(?:\\.|[^\\\n\$]))\1(?=[\s?!\.,:?!。,:]|$)/; const inlineRuleNonStandard = /^(\${1,2})(?!\$)((?:\\.|[^\\\n])*?(?:\\.|[^\\\n\$]))\1/; // Non-standard, even if there are no spaces before and after $ or $$, try to parse const blockRule = /^(\${1,2})\n((?:\\[^]|[^\\])+?)\n\1(?:\n|$)/; -export default function(options = {}) { - return { - extensions: [ - inlineKatex(options, createRenderer(options, false)), - blockKatex(options, createRenderer(options, true)), - ], - }; +export default function (options = {}) { + return { + extensions: [ + inlineKatex(options, createRenderer(options, false)), + blockKatex(options, createRenderer(options, true)) + ] + }; } function createRenderer(options, newlineAfter) { - return (token) => katex.renderToString(token.text, { ...options, displayMode: token.displayMode }) + (newlineAfter ? '\n' : ''); + return (token) => + katex.renderToString(token.text, { ...options, displayMode: token.displayMode }) + + (newlineAfter ? '\n' : ''); } function inlineKatex(options, renderer) { - const nonStandard = options && options.nonStandard; - const ruleReg = nonStandard ? inlineRuleNonStandard : inlineRule; - return { - name: 'inlineKatex', - level: 'inline', - start(src) { - let index; - let indexSrc = src; + const nonStandard = options && options.nonStandard; + const ruleReg = nonStandard ? inlineRuleNonStandard : inlineRule; + return { + name: 'inlineKatex', + level: 'inline', + start(src) { + let index; + let indexSrc = src; - while (indexSrc) { - index = indexSrc.indexOf('$'); - if (index === -1) { - return; - } - const f = nonStandard ? index > -1 : index === 0 || indexSrc.charAt(index - 1) === ' '; - if (f) { - const possibleKatex = indexSrc.substring(index); + while (indexSrc) { + index = indexSrc.indexOf('$'); + if (index === -1) { + return; + } + const f = nonStandard ? index > -1 : index === 0 || indexSrc.charAt(index - 1) === ' '; + if (f) { + const possibleKatex = indexSrc.substring(index); - if (possibleKatex.match(ruleReg)) { - return index; - } - } + if (possibleKatex.match(ruleReg)) { + return index; + } + } - indexSrc = indexSrc.substring(index + 1).replace(/^\$+/, ''); - } - }, - tokenizer(src, tokens) { - const match = src.match(ruleReg); - if (match) { - return { - type: 'inlineKatex', - raw: match[0], - text: match[2].trim(), - displayMode: match[1].length === 2, - }; - } - }, - renderer, - }; + indexSrc = indexSrc.substring(index + 1).replace(/^\$+/, ''); + } + }, + tokenizer(src, tokens) { + const match = src.match(ruleReg); + if (match) { + return { + type: 'inlineKatex', + raw: match[0], + text: match[2].trim(), + displayMode: match[1].length === 2 + }; + } + }, + renderer + }; } function blockKatex(options, renderer) { - return { - name: 'blockKatex', - level: 'block', - tokenizer(src, tokens) { - const match = src.match(blockRule); - if (match) { - return { - type: 'blockKatex', - raw: match[0], - text: match[2].trim(), - displayMode: match[1].length === 2, - }; - } - }, - renderer, - }; -} \ No newline at end of file + return { + name: 'blockKatex', + level: 'block', + tokenizer(src, tokens) { + const match = src.match(blockRule); + if (match) { + return { + type: 'blockKatex', + raw: match[0], + text: match[2].trim(), + displayMode: match[1].length === 2 + }; + } + }, + renderer + }; +} diff --git a/src/routes/(app)/workspace/models/edit/+page.svelte b/src/routes/(app)/workspace/models/edit/+page.svelte index d05d9fc6d..22cd4ffd9 100644 --- a/src/routes/(app)/workspace/models/edit/+page.svelte +++ b/src/routes/(app)/workspace/models/edit/+page.svelte @@ -143,7 +143,7 @@ : { id: model.id, name: model.name - } + } ) ) }; @@ -154,9 +154,9 @@ params = { ...params, ...model?.info?.params }; params.stop = params?.stop - ? (typeof params.stop === 'string' ? params.stop.split(',') : params?.stop ?? []).join( + ? (typeof params.stop === 'string' ? params.stop.split(',') : (params?.stop ?? [])).join( ',' - ) + ) : null; if (model?.info?.meta?.knowledge) { diff --git a/src/routes/auth/+page.svelte b/src/routes/auth/+page.svelte index b0f13e386..a7db94c32 100644 --- a/src/routes/auth/+page.svelte +++ b/src/routes/auth/+page.svelte @@ -352,8 +352,23 @@