From c208e392ab206aee1717ffa08524613055a80a2c Mon Sep 17 00:00:00 2001 From: Mishig Date: Sat, 30 Dec 2023 22:39:47 +0100 Subject: [PATCH 1/6] Update share behaviour (#645) * Update share behaviour * Simplify * format * wording * lint --------- Co-authored-by: Victor Mustar Co-authored-by: Nathan Sarrazin --- src/lib/components/chat/ChatWindow.svelte | 38 ++++++++++++++++++++--- src/lib/shareConversation.ts | 4 +-- src/lib/utils/share.ts | 4 +-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/lib/components/chat/ChatWindow.svelte b/src/lib/components/chat/ChatWindow.svelte index 6b2b3d9b234..949602cf37d 100644 --- a/src/lib/components/chat/ChatWindow.svelte +++ b/src/lib/components/chat/ChatWindow.svelte @@ -1,11 +1,12 @@
@@ -226,12 +247,19 @@

{#if messages.length} {/if}
diff --git a/src/lib/shareConversation.ts b/src/lib/shareConversation.ts index 0086fcaf5d4..064a586a596 100644 --- a/src/lib/shareConversation.ts +++ b/src/lib/shareConversation.ts @@ -8,7 +8,7 @@ export async function shareConversation(id: string, title: string) { try { if (id.length === 7) { const url = get(page).url; - share(getShareUrl(url, id), title); + await share(getShareUrl(url, id), title); } else { const res = await fetch(`${base}/conversation/${id}/share`, { method: "POST", @@ -24,7 +24,7 @@ export async function shareConversation(id: string, title: string) { } const { url } = await res.json(); - share(url, title); + await share(url, title); } } catch (err) { error.set(ERROR_MESSAGES.default); diff --git a/src/lib/utils/share.ts b/src/lib/utils/share.ts index 4587669a101..f0ddb2f1191 100644 --- a/src/lib/utils/share.ts +++ b/src/lib/utils/share.ts @@ -1,7 +1,7 @@ -export function share(url: string, title: string) { +export async function share(url: string, title: string) { if (navigator.share) { navigator.share({ url, title }); } else { - prompt("Copy this public url to share:", url); + await navigator.clipboard.writeText(url); } } From f09c5f3bbb68923b900ff94b8af50c5c9c3149a7 Mon Sep 17 00:00:00 2001 From: Nathan Sarrazin Date: Mon, 8 Jan 2024 09:00:52 +0100 Subject: [PATCH 2/6] Use JSON5 for parsing all config vars (#671) --- package-lock.json | 12 ++++++++++++ package.json | 1 + src/lib/components/chat/ChatIntroduction.svelte | 3 ++- src/lib/server/auth.ts | 3 ++- src/lib/server/models.ts | 8 +++++--- src/lib/server/websearch/generateQuery.ts | 5 +++-- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index e3f4c44b7ce..a89949a1f1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "highlight.js": "^11.7.0", "image-size": "^1.0.2", "jsdom": "^22.0.0", + "json5": "^2.2.3", "marked": "^4.3.0", "mongodb": "^5.8.0", "nanoid": "^4.0.2", @@ -3597,6 +3598,17 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/jsonc-parser": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz", diff --git a/package.json b/package.json index 4fb71d007be..99b9515707c 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "highlight.js": "^11.7.0", "image-size": "^1.0.2", "jsdom": "^22.0.0", + "json5": "^2.2.3", "marked": "^4.3.0", "mongodb": "^5.8.0", "nanoid": "^4.0.2", diff --git a/src/lib/components/chat/ChatIntroduction.svelte b/src/lib/components/chat/ChatIntroduction.svelte index 8a055ef214e..a46e529f6c9 100644 --- a/src/lib/components/chat/ChatIntroduction.svelte +++ b/src/lib/components/chat/ChatIntroduction.svelte @@ -12,6 +12,7 @@ import { findCurrentModel } from "$lib/utils/models"; import { base } from "$app/paths"; import { useSettingsStore } from "$lib/stores/settings"; + import JSON5 from "json5"; export let currentModel: Model; export let models: Model[]; @@ -21,7 +22,7 @@ $: currentModelMetadata = findCurrentModel(models, $settings.activeModel); const announcementBanners = PUBLIC_ANNOUNCEMENT_BANNERS - ? JSON.parse(PUBLIC_ANNOUNCEMENT_BANNERS) + ? JSON5.parse(PUBLIC_ANNOUNCEMENT_BANNERS) : []; const dispatch = createEventDispatcher<{ message: string }>(); diff --git a/src/lib/server/auth.ts b/src/lib/server/auth.ts index df2a089b8c2..e4eec9885b3 100644 --- a/src/lib/server/auth.ts +++ b/src/lib/server/auth.ts @@ -15,6 +15,7 @@ import { z } from "zod"; import { dev } from "$app/environment"; import type { Cookies } from "@sveltejs/kit"; import { collections } from "./database"; +import JSON5 from "json5"; export interface OIDCSettings { redirectURI: string; @@ -40,7 +41,7 @@ const OIDConfig = z TOLERANCE: stringWithDefault(OPENID_TOLERANCE), RESOURCE: stringWithDefault(OPENID_RESOURCE), }) - .parse(JSON.parse(OPENID_CONFIG)); + .parse(JSON5.parse(OPENID_CONFIG)); export const requiresUser = !!OIDConfig.CLIENT_ID && !!OIDConfig.CLIENT_SECRET; diff --git a/src/lib/server/models.ts b/src/lib/server/models.ts index 58d05bd7a9b..0e6e5320b68 100644 --- a/src/lib/server/models.ts +++ b/src/lib/server/models.ts @@ -13,6 +13,8 @@ import endpoints, { endpointSchema, type Endpoint } from "./endpoints/endpoints" import endpointTgi from "./endpoints/tgi/endpointTgi"; import { sum } from "$lib/utils/sum"; +import JSON5 from "json5"; + type Optional = Pick, K> & Omit; const modelConfig = z.object({ @@ -68,7 +70,7 @@ const modelConfig = z.object({ unlisted: z.boolean().default(false), }); -const modelsRaw = z.array(modelConfig).parse(JSON.parse(MODELS)); +const modelsRaw = z.array(modelConfig).parse(JSON5.parse(MODELS)); const processModel = async (m: z.infer) => ({ ...m, @@ -138,7 +140,7 @@ export const oldModels = OLD_MODELS displayName: z.string().min(1).optional(), }) ) - .parse(JSON.parse(OLD_MODELS)) + .parse(JSON5.parse(OLD_MODELS)) .map((m) => ({ ...m, id: m.id || m.name, displayName: m.displayName || m.name })) : []; @@ -151,7 +153,7 @@ export const validateModel = (_models: BackendModel[]) => { export const smallModel = TASK_MODEL ? (models.find((m) => m.name === TASK_MODEL) || - (await processModel(modelConfig.parse(JSON.parse(TASK_MODEL))).then((m) => + (await processModel(modelConfig.parse(JSON5.parse(TASK_MODEL))).then((m) => addEndpoint(m) ))) ?? defaultModel diff --git a/src/lib/server/websearch/generateQuery.ts b/src/lib/server/websearch/generateQuery.ts index 69d0c1ce40b..cdff0c7b937 100644 --- a/src/lib/server/websearch/generateQuery.ts +++ b/src/lib/server/websearch/generateQuery.ts @@ -3,11 +3,12 @@ import { format } from "date-fns"; import { generateFromDefaultEndpoint } from "../generateFromDefaultEndpoint"; import { WEBSEARCH_ALLOWLIST, WEBSEARCH_BLOCKLIST } from "$env/static/private"; import { z } from "zod"; +import JSON5 from "json5"; const listSchema = z.array(z.string()).default([]); -const allowList = listSchema.parse(JSON.parse(WEBSEARCH_ALLOWLIST)); -const blockList = listSchema.parse(JSON.parse(WEBSEARCH_BLOCKLIST)); +const allowList = listSchema.parse(JSON5.parse(WEBSEARCH_ALLOWLIST)); +const blockList = listSchema.parse(JSON5.parse(WEBSEARCH_BLOCKLIST)); const queryModifier = [ ...allowList.map((item) => "site:" + item), From e63c1d7cfc0ce3fbc9ed39e78b0b872dc2787e55 Mon Sep 17 00:00:00 2001 From: Muhammad Baqir Date: Mon, 8 Jan 2024 13:10:48 +0500 Subject: [PATCH 3/6] Fixes "invalid url" error in websearch (#675) * Fixed #656 * lint --------- Co-authored-by: muhammadbaqir1327 Co-authored-by: Nathan Sarrazin --- src/lib/server/websearch/runWebSearch.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/server/websearch/runWebSearch.ts b/src/lib/server/websearch/runWebSearch.ts index 0869ea8b494..041946bb16b 100644 --- a/src/lib/server/websearch/runWebSearch.ts +++ b/src/lib/server/websearch/runWebSearch.ts @@ -48,11 +48,17 @@ export async function runWebSearch( webSearch.results = (results.organic_results && results.organic_results.map((el: { title?: string; link: string; text?: string }) => { - const { title, link, text } = el; - const { hostname } = new URL(link); - return { title, link, hostname, text }; + try { + const { title, link, text } = el; + const { hostname } = new URL(link); + return { title, link, hostname, text }; + } catch (e) { + // Ignore Errors + return null; + } })) ?? []; + webSearch.results = webSearch.results.filter((value) => value !== null); webSearch.results = webSearch.results .filter(({ link }) => !DOMAIN_BLOCKLIST.some((el) => link.includes(el))) // filter out blocklist links .slice(0, MAX_N_PAGES_SCRAPE); // limit to first 10 links only From 9540b25dbcccf68828a75a57018a5dc25e60f084 Mon Sep 17 00:00:00 2001 From: Nathan Sarrazin Date: Mon, 8 Jan 2024 11:11:14 +0100 Subject: [PATCH 4/6] fix: npm package version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a89949a1f1d..371731efac3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "chat-ui", - "version": "0.6.0", + "version": "0.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "chat-ui", - "version": "0.6.0", + "version": "0.7.0", "dependencies": { "@huggingface/hub": "^0.5.1", "@huggingface/inference": "^2.6.3", diff --git a/package.json b/package.json index 99b9515707c..cf65cabaeb7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chat-ui", - "version": "0.6.0", + "version": "0.7.0", "private": true, "packageManager": "npm@9.5.0", "scripts": { From 884fe738469028efcd6c2a59c581cead26314850 Mon Sep 17 00:00:00 2001 From: Nathan Sarrazin Date: Mon, 8 Jan 2024 12:21:51 +0100 Subject: [PATCH 5/6] Deprecate Falcon 180B (#680) --- .env.template | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/.env.template b/.env.template index 09c63f50d47..a7e33c0b8ff 100644 --- a/.env.template +++ b/.env.template @@ -92,35 +92,6 @@ MODELS=`[ "max_new_tokens": 4096 } }, - { - "name": "tiiuae/falcon-180B-chat", - "displayName": "tiiuae/falcon-180B-chat", - "description": "Falcon-180B is a 180B parameters causal decoder-only model built by TII and trained on 3,500B tokens.", - "websiteUrl": "https://www.tii.ae/news/technology-innovation-institute-introduces-worlds-most-powerful-open-llm-falcon-180b", - "preprompt": " ", - "chatPromptTemplate": "System: {{preprompt}}\nUser:{{#each messages}}{{#ifUser}}{{content}}\nFalcon:{{/ifUser}}{{#ifAssistant}}{{content}}\nUser:{{/ifAssistant}}{{/each}}", - "parameters": { - "temperature": 0.1, - "top_p": 0.95, - "repetition_penalty": 1.2, - "top_k": 50, - "truncate": 1024, - "max_new_tokens": 1024, - "stop": ["User:"] - }, - "promptExamples": [ - { - "title": "Write an email from bullet list", - "prompt": "As a restaurant owner, write a professional email to the supplier to get these products every week: \n\n- Wine (x10)\n- Eggs (x24)\n- Bread (x12)" - }, { - "title": "Code a snake game", - "prompt": "Code a basic snake game in python, give explanations for each step." - }, { - "title": "Assist in a task", - "prompt": "How do I make a delicious lemon cheesecake?" - } - ] - }, { "name": "mistralai/Mistral-7B-Instruct-v0.1", "displayName": "mistralai/Mistral-7B-Instruct-v0.1", @@ -215,7 +186,9 @@ OLD_MODELS=`[ {"name":"bigcode/starcoder"}, {"name":"OpenAssistant/oasst-sft-6-llama-30b-xor"}, {"name":"HuggingFaceH4/zephyr-7b-alpha"}, - {"name":"openchat/openchat_3.5"}]` + {"name":"openchat/openchat_3.5"}, + {"name": "tiiuae/falcon-180B-chat"} +]` TASK_MODEL='mistralai/Mistral-7B-Instruct-v0.2' # TASK_MODEL=`{ From cdb33a9583f5339ade724db615347393ef48f5cd Mon Sep 17 00:00:00 2001 From: Nathan Sarrazin Date: Mon, 8 Jan 2024 14:38:11 +0100 Subject: [PATCH 6/6] Apply settings without reloading the page (#682) * Invalidate conversation list when settings update * improve trimming on conv titles * Update src/routes/+layout.server.ts Co-authored-by: Mishig --------- Co-authored-by: Mishig --- src/lib/stores/settings.ts | 3 +++ src/routes/+layout.server.ts | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lib/stores/settings.ts b/src/lib/stores/settings.ts index 51dab38dda2..18c55ce6e54 100644 --- a/src/lib/stores/settings.ts +++ b/src/lib/stores/settings.ts @@ -1,5 +1,7 @@ import { browser } from "$app/environment"; +import { invalidate } from "$app/navigation"; import { base } from "$app/paths"; +import { UrlDependency } from "$lib/types/UrlDependency"; import { getContext, setContext } from "svelte"; import { type Writable, writable, get } from "svelte/store"; @@ -53,6 +55,7 @@ export function createSettingsStore(initialValue: Omit { updatedAt: 1, createdAt: 1, }) - .map((conv) => ({ - id: conv._id.toString(), - title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title, - model: conv.model ?? defaultModel, - updatedAt: conv.updatedAt, - })) + .map((conv) => { + // remove emojis if settings say so + if (settings?.hideEmojiOnSidebar) { + conv.title = conv.title.replace(/\p{Emoji}/gu, ""); + } + + // remove invalid unicode and trim whitespaces + conv.title = conv.title.replace(/\uFFFD/gu, "").trimStart(); + return { + id: conv._id.toString(), + title: settings?.hideEmojiOnSidebar ? conv.title.replace(/\p{Emoji}/gu, "") : conv.title, + model: conv.model ?? defaultModel, + updatedAt: conv.updatedAt, + }; + }) .toArray(), settings: { searchEnabled: !!(