Skip to content

Commit

Permalink
Merge branch 'huggingface:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
itaybar authored Jan 9, 2024
2 parents 9a091b7 + cdb33a9 commit 2fe480d
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 58 deletions.
33 changes: 3 additions & 30 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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=`{
Expand Down
16 changes: 14 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chat-ui",
"version": "0.6.0",
"version": "0.7.0",
"private": true,
"packageManager": "[email protected]",
"scripts": {
Expand Down Expand Up @@ -55,6 +55,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",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/chat/ChatIntroduction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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[];
Expand All @@ -19,7 +20,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 }>();
Expand Down
38 changes: 33 additions & 5 deletions src/lib/components/chat/ChatWindow.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script lang="ts">
import type { Message } from "$lib/types/Message";
import { createEventDispatcher } from "svelte";
import { createEventDispatcher, onDestroy } from "svelte";
import CarbonSendAltFilled from "~icons/carbon/send-alt-filled";
import CarbonExport from "~icons/carbon/export";
import CarbonStopFilledAlt from "~icons/carbon/stop-filled-alt";
import CarbonClose from "~icons/carbon/close";
import CarbonCheckmark from "~icons/carbon/checkmark";
import EosIconsLoading from "~icons/eos-icons/loading";
Expand Down Expand Up @@ -38,6 +39,9 @@
let loginModalOpen = false;
let message: string;
let timeout: ReturnType<typeof setTimeout>;
let isSharedRecently = false;
$: $page.params.id && (isSharedRecently = false);
const dispatch = createEventDispatcher<{
message: string;
Expand Down Expand Up @@ -73,6 +77,23 @@
$: sources = files.map((file) => file2base64(file));
const settings = useSettingsStore();
function onShare() {
dispatch("share");
isSharedRecently = true;
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
isSharedRecently = false;
}, 2000);
}
onDestroy(() => {
if (timeout) {
clearTimeout(timeout);
}
});
</script>

<div class="relative min-h-0 min-w-0">
Expand Down Expand Up @@ -220,12 +241,19 @@
</p>
{#if messages.length}
<button
class="flex flex-none items-center hover:text-gray-400 hover:underline max-sm:rounded-lg max-sm:bg-gray-50 max-sm:px-2.5 dark:max-sm:bg-gray-800"
class="flex flex-none items-center hover:text-gray-400 max-sm:rounded-lg max-sm:bg-gray-50 max-sm:px-2.5 dark:max-sm:bg-gray-800"
type="button"
on:click={() => dispatch("share")}
class:hover:underline={!isSharedRecently}
on:click={onShare}
disabled={isSharedRecently}
>
<CarbonExport class="text-[.6rem] sm:mr-1.5 sm:text-primary-500" />
<div class="max-sm:hidden">Share this conversation</div>
{#if isSharedRecently}
<CarbonCheckmark class="text-[.6rem] sm:mr-1.5 sm:text-green-600" />
<div class="text-green-600 max-sm:hidden">Link copied to clipboard</div>
{:else}
<CarbonExport class="text-[.6rem] sm:mr-1.5 sm:text-primary-500" />
<div class="max-sm:hidden">Share this conversation</div>
{/if}
</button>
{/if}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/lib/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions src/lib/server/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

const modelConfig = z.object({
Expand Down Expand Up @@ -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<typeof modelConfig>) => ({
...m,
Expand Down Expand Up @@ -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 }))
: [];

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/lib/server/websearch/generateQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 9 additions & 3 deletions src/lib/server/websearch/runWebSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,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
Expand Down
4 changes: 2 additions & 2 deletions src/lib/shareConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/lib/stores/settings.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -53,6 +55,7 @@ export function createSettingsStore(initialValue: Omit<SettingsStore, "recentlyS
recentlySaved: false,
}));
}, 3000);
invalidate(UrlDependency.ConversationList);
}, 300);
// debounce server calls by 300ms
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/share.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
21 changes: 15 additions & 6 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
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: !!(
Expand Down

0 comments on commit 2fe480d

Please sign in to comment.