Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assistants feature #639

Merged
merged 72 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
e85d1e1
First push on assistants
nsarrazin Dec 15, 2023
3ba2eea
push fixes
nsarrazin Dec 20, 2023
40a6a96
fix add assistant
nsarrazin Dec 20, 2023
20cfabf
Sign up works
nsarrazin Dec 20, 2023
835874b
lint
nsarrazin Dec 20, 2023
0240db1
mobile layout fixes
nsarrazin Dec 20, 2023
78be831
design fixes
nsarrazin Dec 20, 2023
2a8821c
Merge branch 'main' into feature/assistants
nsarrazin Dec 20, 2023
7dc10ab
fix copy button
nsarrazin Dec 20, 2023
0eea54c
Merge branch 'main' into feature/assistants
nsarrazin Dec 20, 2023
3ad46cb
add error feedback
nsarrazin Dec 21, 2023
5b3ee70
hide duplicate feature
nsarrazin Dec 21, 2023
128c5a3
remove wrong comments
nsarrazin Dec 21, 2023
1be810e
add autoredirect if assistant is missing
nsarrazin Dec 22, 2023
6b8d089
latest changes:
nsarrazin Dec 22, 2023
f90dfc4
Update src/routes/conversation/+server.ts
nsarrazin Dec 22, 2023
626ba66
reused type more cleanly
nsarrazin Dec 22, 2023
41a5971
fix type in shared conversation
nsarrazin Dec 22, 2023
f84c86a
fixed feature
nsarrazin Dec 22, 2023
f6f24a5
fix: share conv with an assistant
nsarrazin Dec 26, 2023
6ec25e8
delete assistant avatars in db when deleting avatar
nsarrazin Dec 26, 2023
efdff6c
affordance on avatar upload
nsarrazin Dec 26, 2023
c52766e
improve assistant conv start on mobile
nsarrazin Dec 26, 2023
a34b9eb
settings modal fly in
nsarrazin Dec 26, 2023
ed87314
better mobile intro
nsarrazin Dec 26, 2023
7439d95
mobile padding
nsarrazin Dec 26, 2023
9d40d31
link affordance
nsarrazin Dec 26, 2023
31a4941
Make assistants disabled by default, but enabled in huggingchat
nsarrazin Dec 27, 2023
b8fe23b
Merge branch 'main' into feature/assistants
nsarrazin Dec 27, 2023
0c91f2d
lint
nsarrazin Dec 27, 2023
0d83189
Fix bottom model name
nsarrazin Dec 28, 2023
a27e1c8
ui tweaks
gary149 Dec 29, 2023
ea18583
Initial work on chat thumbnails
nsarrazin Dec 29, 2023
e09eefa
fix build
nsarrazin Dec 29, 2023
4ebedfe
Get rid of deps
nsarrazin Dec 30, 2023
9499dec
Update src/routes/settings/assistants/[assistantId]/avatar/+server.ts
nsarrazin Jan 8, 2024
3db13f4
add comment to app_base
nsarrazin Jan 8, 2024
8eb6cb4
Use event modifiers
nsarrazin Jan 8, 2024
e7b4bad
Use CSS uppercase instead everywhere
nsarrazin Jan 8, 2024
58ac13e
Update src/lib/components/NavMenu.svelte
nsarrazin Jan 8, 2024
092ff0a
Update src/routes/+layout.server.ts
nsarrazin Jan 8, 2024
51b4354
Clearer error message for avatar size check
nsarrazin Jan 8, 2024
a15c24c
Merge branch 'main' into feature/assistants
nsarrazin Jan 8, 2024
ae1e38b
one less op on flag check
nsarrazin Jan 9, 2024
bb3d452
revert back preventDefault change in LoginModal
nsarrazin Jan 9, 2024
88b18a0
Merge branch 'main' into feature/assistants
nsarrazin Jan 9, 2024
363653f
Update src/routes/settings/+layout.svelte
nsarrazin Jan 9, 2024
048c441
Update src/routes/+layout.server.ts
nsarrazin Jan 9, 2024
bd40c7b
Update src/routes/+layout.server.ts
nsarrazin Jan 9, 2024
35fe5fe
Added app logo in corner of thumbnail and clamped description length
nsarrazin Jan 9, 2024
a2cd7d8
improved thumbnails
nsarrazin Jan 10, 2024
3ba0f51
Remove warnings
nsarrazin Jan 10, 2024
e4c0aea
Reuse Assisntants settings component (#678)
Jan 10, 2024
8eb6b5b
Merge branch 'main' into feature/assistants
nsarrazin Jan 10, 2024
f6c61eb
[Assistants] Use textToImage task for avatar generation (#662)
nsarrazin Jan 15, 2024
69c223d
layout
gary149 Jan 18, 2024
1900083
small fixes
gary149 Jan 18, 2024
744d4a0
hint
gary149 Jan 18, 2024
003cd30
Show feature if login is not required
nsarrazin Jan 18, 2024
7652355
Merge branch 'main' into feature/assistants
nsarrazin Jan 18, 2024
c89c620
lint
nsarrazin Jan 18, 2024
285050f
Only show creator name if it's defined
nsarrazin Jan 18, 2024
5165490
tweaks
gary149 Jan 18, 2024
b672fb7
thumbnail update
gary149 Jan 18, 2024
732e338
thumbnail font-size
gary149 Jan 18, 2024
52834ce
Always display model at the bottom
nsarrazin Jan 22, 2024
11fe137
Bottom links now go to settings
nsarrazin Jan 22, 2024
6da1347
fix lint
nsarrazin Jan 22, 2024
4a12786
silent release
nsarrazin Jan 23, 2024
0ede716
Merge branch 'main' into feature/assistants
nsarrazin Jan 23, 2024
cf00c70
fix bg on share link
nsarrazin Jan 23, 2024
f3114ae
[Assistant] Delete avatar button instead of reset (#725)
nsarrazin Jan 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ LLM_SUMMERIZATION=true
# PUBLIC_APP_COLOR=yellow
# PUBLIC_APP_DESCRIPTION="Making the community's best AI chat models available to everyone."
# PUBLIC_APP_DATA_SHARING=1
# PUBLIC_APP_DISCLAIMER=1
# PUBLIC_APP_DISCLAIMER=1

DISABLE_ASSISTANTS=false # set to true to disable assistants feature
nsarrazin marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion src/lib/components/DisclaimerModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
class:text-gray-800={$page.data.loginEnabled}
class:hover:bg-slate-100={$page.data.loginEnabled}
on:click={(e) => {
e.preventDefault();
e.stopPropagation();
nsarrazin marked this conversation as resolved.
Show resolved Hide resolved
if (!cookiesAreEnabled()) {
e.preventDefault();
window.open(window.location.href, "_blank");
}

Expand Down
16 changes: 14 additions & 2 deletions src/lib/components/NavConversationItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
import CarbonTrashCan from "~icons/carbon/trash-can";
import CarbonClose from "~icons/carbon/close";
import CarbonEdit from "~icons/carbon/edit";
import { useSettingsStore } from "$lib/stores/settings";

export let conv: { id: string; title: string };
export let conv: { id: string; title: string; avatarId?: string };

nsarrazin marked this conversation as resolved.
Show resolved Hide resolved
let confirmDelete = false;

const dispatch = createEventDispatcher<{
deleteConversation: string;
editConversationTitle: { id: string; title: string };
}>();

const settings = useSettingsStore();
</script>

<a
Expand All @@ -33,7 +36,16 @@
{#if confirmDelete}
<span class="font-semibold"> Delete </span>
{/if}
{conv.title}
{#if conv.avatarId && !$settings.hideEmojiOnSidebar}
<img
src="{base}/settings/assistants/{conv.avatarId}/avatar"
alt="Assistant avatar"
class="mr-1 inline h-4 w-4 rounded-full"
/>
{conv.title.replace(/\p{Emoji}/gu, "")}
{:else}
{conv.title}
{/if}
</div>

{#if confirmDelete}
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/NavMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
id: string;
title: string;
updatedAt: Date;
avatarId?: string;
}

export let conversations: Array<Conv> = [];
Expand Down
83 changes: 83 additions & 0 deletions src/lib/components/chat/AssistantIntroduction.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import IconGear from "~icons/bi/gear-fill";
import { base } from "$app/paths";
import type { Assistant } from "$lib/types/Assistant";

export let assistant: Pick<
Assistant,
"avatar" | "name" | "modelId" | "createdByName" | "exampleInputs" | "_id" | "description"
>;

const dispatch = createEventDispatcher<{ message: string }>();
</script>

<div class="flex h-full w-full flex-col content-center items-center justify-center">
<div
class="relative mt-auto rounded-xl bg-gray-100 text-gray-600 dark:border-gray-800 dark:bg-gray-800 dark:text-gray-300"
>
<div class="flex items-center gap-4 p-8 pr-10 pt-10">
{#if assistant.avatar}
<img
src={`${base}/settings/assistants/${assistant._id.toString()}/avatar`}
alt="avatar"
class="mr-4 h-32 w-32 rounded-full object-cover"
/>
{:else}
<div
class="mr-4 flex h-32 w-32 items-center justify-center rounded-full bg-gray-300 object-cover text-4xl font-bold text-gray-500"
>
{assistant?.name[0].toLocaleUpperCase()}
</div>
{/if}

<div class="flex flex-col">
<p
class="mb-4 w-fit rounded-full bg-gray-200 px-4 py-2 text-xs text-gray-600 dark:bg-gray-700 dark:text-gray-400"
>
{assistant.modelId}
</p>
<p class="text-2xl font-bold">{assistant.name}</p>
<p class="text-sm text-gray-500 dark:text-gray-400">
{assistant.description}
</p>

<p class="pt-2 text-sm text-gray-400 dark:text-gray-500">
Created by <a
class="hover:underline"
href="https://hf.co/{assistant.createdByName}"
target="_blank"
>
{assistant.createdByName}
</a>
</p>
</div>
</div>
<a
href="{base}/settings/assistants/{assistant._id.toString()}"
class="absolute right-3 top-3
inline text-gray-400 hover:text-gray-600
dark:text-gray-500 dark:hover:text-gray-400
"
>
<IconGear class="h-5 w-5" />
</a>
</div>
{#if assistant.exampleInputs}
<div class="mx-auto mt-auto w-full gap-8">
<div class="lg:col-span-2 lg:mt-6">
<div class="grid gap-3 lg:grid-cols-2 lg:gap-5">
{#each assistant.exampleInputs as example}
<button
type="button"
class="rounded-xl border bg-gray-50 p-2.5 text-left text-gray-600 hover:bg-gray-100 dark:border-gray-800 dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700 sm:p-4"
on:click={() => dispatch("message", example)}
>
{example}
</button>
{/each}
</div>
</div>
</div>
{/if}
</div>
34 changes: 32 additions & 2 deletions src/lib/components/chat/ChatMessages.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
import type { WebSearchUpdate } from "$lib/types/MessageUpdate";
import { browser } from "$app/environment";
import SystemPromptModal from "../SystemPromptModal.svelte";
import type { Assistant } from "$lib/types/Assistant";
import AssistantIntroduction from "./AssistantIntroduction.svelte";
import { page } from "$app/stores";
import { base } from "$app/paths";

export let messages: Message[];
export let loading: boolean;
export let pending: boolean;
export let isAuthor: boolean;
export let currentModel: Model;
export let assistant: Assistant | undefined;
export let models: Model[];
export let preprompt: string | undefined;
export let readOnly: boolean;
Expand All @@ -42,7 +47,28 @@
>
<div class="mx-auto flex h-full max-w-3xl flex-col gap-6 px-5 pt-6 sm:gap-8 xl:max-w-4xl">
{#each messages as message, i}
{#if i === 0 && preprompt && preprompt != currentModel.preprompt}
{#if i === 0 && $page.data?.assistant}
<a
class="text-md mx-auto flex items-center gap-1.5 rounded-full border border-gray-100 bg-gray-50 py-1 pl-1 pr-3 font-semibold text-gray-800 hover:bg-gray-100 dark:border-gray-800 dark:bg-gray-800 dark:text-gray-200 dark:hover:bg-gray-700"
href="{base}/settings/assistants/{$page.data.assistant._id}"
>
{#if $page.data?.assistant.avatar}
<img
src="{base}/settings/assistants/{$page.data?.assistant._id.toString()}/avatar"
alt="Avatar"
class="h-6 w-6 rounded-full object-cover"
/>
{:else}
<div
class="flex h-6 w-6 items-center justify-center rounded-full bg-gray-300 font-bold text-gray-500"
>
{$page.data?.assistant.name[0].toLocaleUpperCase()}
</div>
{/if}

{$page.data.assistant.name}
</a>
{:else if i === 0 && preprompt && preprompt != currentModel.preprompt}
<SystemPromptModal preprompt={preprompt ?? ""} />
{/if}
<ChatMessage
Expand All @@ -56,7 +82,11 @@
on:vote
/>
{:else}
<ChatIntroduction {models} {currentModel} on:message />
{#if !assistant}
<ChatIntroduction {models} {currentModel} on:message />
{:else}
<AssistantIntroduction {assistant} on:message />
{/if}
{/each}
{#if pending}
<ChatMessage
Expand Down
11 changes: 4 additions & 7 deletions src/lib/components/chat/ChatWindow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
import LoginModal from "../LoginModal.svelte";
import type { WebSearchUpdate } from "$lib/types/MessageUpdate";
import { page } from "$app/stores";
import DisclaimerModal from "../DisclaimerModal.svelte";
import FileDropzone from "./FileDropzone.svelte";
import RetryBtn from "../RetryBtn.svelte";
import UploadBtn from "../UploadBtn.svelte";
import file2base64 from "$lib/utils/file2base64";
import { useSettingsStore } from "$lib/stores/settings";
import type { Assistant } from "$lib/types/Assistant";

export let messages: Message[] = [];
export let loading = false;
export let pending = false;
export let shared = false;
export let currentModel: Model;
export let models: Model[];
export let assistant: Assistant | undefined = undefined;
export let webSearchMessages: WebSearchUpdate[] = [];
export let preprompt: string | undefined = undefined;
export let files: File[] = [];
Expand Down Expand Up @@ -71,14 +71,10 @@
$: lastIsError = messages[messages.length - 1]?.from === "user" && !loading;

$: sources = files.map((file) => file2base64(file));

const settings = useSettingsStore();
</script>

<div class="relative min-h-0 min-w-0">
{#if !$settings.ethicsModalAccepted}
<DisclaimerModal />
{:else if loginModalOpen}
{#if loginModalOpen}
<LoginModal
on:close={() => {
loginModalOpen = false;
Expand All @@ -90,6 +86,7 @@
{pending}
{currentModel}
{models}
{assistant}
{messages}
readOnly={isReadOnly}
isAuthor={!shared}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/server/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { Settings } from "$lib/types/Settings";
import type { User } from "$lib/types/User";
import type { MessageEvent } from "$lib/types/MessageEvent";
import type { Session } from "$lib/types/Session";
import type { Assistant } from "$lib/types/Assistant";
import type { Report } from "$lib/types/Report";

if (!MONGODB_URL) {
throw new Error(
Expand All @@ -23,6 +25,8 @@ export const connectPromise = client.connect().catch(console.error);
const db = client.db(MONGODB_DB_NAME + (import.meta.env.MODE === "test" ? "-test" : ""));

const conversations = db.collection<Conversation>("conversations");
const assistants = db.collection<Assistant>("assistants");
const reports = db.collection<Report>("reports");
const sharedConversations = db.collection<SharedConversation>("sharedConversations");
const abortedGenerations = db.collection<AbortedGeneration>("abortedGenerations");
const settings = db.collection<Settings>("settings");
Expand All @@ -34,6 +38,8 @@ const bucket = new GridFSBucket(db, { bucketName: "files" });
export { client, db };
export const collections = {
conversations,
assistants,
reports,
sharedConversations,
abortedGenerations,
settings,
Expand Down Expand Up @@ -66,4 +72,6 @@ client.on("open", () => {
messageEvents.createIndex({ createdAt: 1 }, { expireAfterSeconds: 60 }).catch(console.error);
sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 }).catch(console.error);
sessions.createIndex({ sessionId: 1 }, { unique: true }).catch(console.error);
assistants.createIndex({ createdBy: 1 }).catch(console.error);
reports.createIndex({ assistantId: 1 }).catch(console.error);
});
6 changes: 6 additions & 0 deletions src/lib/stores/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { browser } from "$app/environment";
import { invalidate } from "$app/navigation";
import { base } from "$app/paths";
import { UrlDependency } from "$lib/types/UrlDependency";
import type { ObjectId } from "mongodb";
import { getContext, setContext } from "svelte";
import { type Writable, writable, get } from "svelte/store";

Expand All @@ -11,7 +14,9 @@ type SettingsStore = {
activeModel: string;
customPrompts: Record<string, string>;
recentlySaved: boolean;
assistants: Array<ObjectId | string>;
};

export function useSettingsStore() {
return getContext<Writable<SettingsStore>>("settings");
}
Expand Down Expand Up @@ -42,6 +47,7 @@ export function createSettingsStore(initialValue: Omit<SettingsStore, "recentlyS
}),
});

invalidate(UrlDependency.ConversationList);
// set savedRecently to true for 3s
baseStore.update((s) => ({
...s,
Expand Down
15 changes: 15 additions & 0 deletions src/lib/types/Assistant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ObjectId } from "mongodb";
import type { User } from "./User";
import type { Timestamps } from "./Timestamps";

export interface Assistant extends Timestamps {
_id: ObjectId;
createdById: User["_id"] | string; // user id or session
createdByName?: User["username"];
avatar?: boolean;
name: string;
description?: string;
modelId: string;
exampleInputs: string[];
preprompt: string;
}
2 changes: 2 additions & 0 deletions src/lib/types/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ObjectId } from "mongodb";
import type { Message } from "./Message";
import type { Timestamps } from "./Timestamps";
import type { User } from "./User";
import type { Assistant } from "./Assistant";

export interface Conversation extends Timestamps {
_id: ObjectId;
Expand All @@ -19,4 +20,5 @@ export interface Conversation extends Timestamps {
};

preprompt?: string;
assistantId?: Assistant["_id"];
}
10 changes: 10 additions & 0 deletions src/lib/types/Report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ObjectId } from "mongodb";
import type { User } from "./User";
import type { Assistant } from "./Assistant";
import type { Timestamps } from "./Timestamps";

export interface Report extends Timestamps {
_id: ObjectId;
createdBy: User["_id"] | string;
assistantId: Assistant["_id"];
}
5 changes: 5 additions & 0 deletions src/lib/types/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defaultModel } from "$lib/server/models";
import type { Assistant } from "./Assistant";
import type { Timestamps } from "./Timestamps";
import type { User } from "./User";

Expand All @@ -18,11 +19,15 @@ export interface Settings extends Timestamps {

// model name and system prompts
customPrompts?: Record<string, string>;

assistants?: Assistant["_id"][];
}

// TODO: move this to a constant file along with other constants
export const DEFAULT_SETTINGS = {
shareConversationsWithModelAuthors: true,
activeModel: defaultModel.id,
hideEmojiOnSidebar: false,
customPrompts: {},
assistants: [],
};
1 change: 1 addition & 0 deletions src/lib/types/SharedConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface SharedConversation extends Timestamps {
title: string;
messages: Message[];
preprompt?: string;
assistantId?: string;
nsarrazin marked this conversation as resolved.
Show resolved Hide resolved
}
Loading