Skip to content

Commit 4228faa

Browse files
authored
Some UI tweaks (#93)
* **Styling:** * The bottom action bar in [`src/lib/components/inference-playground/playground.svelte`](src/lib/components/inference-playground/playground.svelte:122) and its buttons were made more compact. * **User Experience:** * A welcome message is now displayed for new conversations in [`src/lib/components/inference-playground/conversation.svelte`](src/lib/components/inference-playground/conversation.svelte:59). * The validation preventing consecutive user messages was removed in [`src/lib/components/inference-playground/message-textarea.svelte`](src/lib/components/inference-playground/message-textarea.svelte:24), allowing for a more natural conversation flow. * **State Management:** * In [`src/lib/state/conversations.svelte.ts`](src/lib/state/conversations.svelte.ts:81), new conversations are now initialized with an empty message list, and so when you send the first message it's not spawning a 2nd user message.
1 parent a32010b commit 4228faa

File tree

5 files changed

+31
-39
lines changed

5 files changed

+31
-39
lines changed

src/app.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@
6464
}
6565

6666
@utility btn {
67-
@apply flex h-[39px] items-center justify-center gap-2 rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:ring-4 focus:ring-gray-100 focus:outline-hidden dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700;
67+
@apply flex h-[39px] items-center justify-center gap-2 rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:ring-4 focus:ring-gray-100 focus:outline-hidden dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-600 dark:hover:text-white dark:focus:ring-gray-700;
6868
}
6969

7070
@utility btn-sm {
71-
@apply flex h-[32px] items-center justify-center gap-1.5 rounded-md border border-gray-200 bg-white px-2.5 py-2 text-xs font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:ring-4 focus:ring-gray-100 focus:outline-hidden dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700;
71+
@apply flex h-[32px] items-center justify-center gap-1.5 rounded-md border border-gray-200 bg-white px-2.5 py-2 text-xs font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:ring-4 focus:ring-gray-100 focus:outline-hidden dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-600 dark:hover:text-white dark:focus:ring-gray-700;
7272
}
7373

7474
@utility btn-xs {
75-
@apply flex h-[28px] items-center justify-center gap-1 rounded border border-gray-200 bg-white px-2 py-1.5 text-xs font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:ring-4 focus:ring-gray-100 focus:outline-hidden dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700;
75+
@apply flex h-[28px] items-center justify-center gap-1 rounded border border-gray-200 bg-white px-2 py-1.5 text-xs font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:ring-4 focus:ring-gray-100 focus:outline-hidden dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-600 dark:hover:text-white dark:focus:ring-gray-700;
7676
}
7777

7878
@utility btn-mini {
79-
@apply flex h-[24px] items-center justify-center gap-0.5 rounded-sm border border-gray-200 bg-white px-1.5 py-1 text-[10px] font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:ring-2 focus:ring-gray-100 focus:outline-hidden dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700;
79+
@apply flex h-[24px] items-center justify-center gap-0.5 rounded-sm border border-gray-200 bg-white px-1.5 py-1 text-[10px] font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:ring-2 focus:ring-gray-100 focus:outline-hidden dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-600 dark:hover:text-white dark:focus:ring-gray-700;
8080
}
8181

8282
@utility custom-outline {

src/lib/components/inference-playground/conversation.svelte

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,22 @@
5757
bind:this={messageContainer}
5858
>
5959
{#if !viewCode}
60-
{#each conversation.data.messages || [] as message, index}
61-
<Message
62-
{message}
63-
{index}
64-
{conversation}
65-
onDelete={() => conversation.deleteMessage(index)}
66-
onRegen={() => regenMessage(index)}
67-
/>
68-
{/each}
60+
{#if conversation.data.messages?.length}
61+
{#each conversation.data.messages as message, index}
62+
<Message
63+
{message}
64+
{index}
65+
{conversation}
66+
onDelete={() => conversation.deleteMessage(index)}
67+
onRegen={() => regenMessage(index)}
68+
/>
69+
{:else}
70+
<div class="m-auto flex flex-col items-center gap-2 text-center px-4 text-balance">
71+
<h1 class="text-2xl font-semibold">Welcome to Hugging Face Inference Playground</h1>
72+
<p class="text-lg text-gray-500">Try hundreds of models on different providers</p>
73+
</div>
74+
{/each}
75+
{/if}
6976
{:else}
7077
<CodeSnippets {conversation} {onCloseCode} />
7178
{/if}

src/lib/components/inference-playground/message-textarea.svelte

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,19 @@
2121
2222
async function sendMessage() {
2323
const c = conversations.active;
24-
const isValid = c.every(c => c.data.messages?.at(-1)?.role !== "user");
25-
26-
if (!isValid) {
27-
addToast({
28-
title: "Cannot add message",
29-
description: "Cannot have multiple user messages in a row",
30-
31-
variant: "error",
32-
});
33-
} else {
34-
await Promise.all(c.map(c => c.addMessage({ role: "user", content: input })));
35-
c.forEach(c => c.genNextMessage());
36-
input = "";
37-
}
24+
await Promise.all(c.map(c => c.addMessage({ role: "user", content: input })));
25+
c.forEach(c => c.genNextMessage());
26+
input = "";
3827
}
3928
4029
const autosized = new TextareaAutosize();
4130
</script>
4231

4332
<svelte:window onkeydown={onKeydown} />
4433

45-
<div class="mt-auto p-2">
34+
<div class="mt-auto px-2">
4635
<label
47-
class="flex w-full items-end rounded-[32px] bg-gray-200 p-2 pl-8 outline-offset-2 outline-blue-500 focus-within:outline-2 dark:bg-gray-800"
36+
class="flex w-full items-end rounded-[32px] bg-gray-200 p-2 pl-6 outline-gray-500 focus-within:outline-2 dark:bg-gray-800"
4837
>
4938
<textarea
5039
placeholder="Enter your message"

src/lib/components/inference-playground/playground.svelte

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,16 @@
119119

120120
<!-- Bottom bar -->
121121
<div
122-
class="relative mt-auto flex h-20 shrink-0 items-center justify-center gap-2 overflow-hidden border-t border-gray-200 px-3 whitespace-nowrap dark:border-gray-800"
122+
class="relative mt-auto flex h-14 shrink-0 items-center justify-center gap-2 overflow-hidden px-3 whitespace-nowrap"
123123
>
124124
<div class="flex flex-1 justify-start gap-x-2">
125125
{#if !compareActive}
126126
<button
127127
type="button"
128128
onclick={() => (viewSettings = !viewSettings)}
129-
class="flex h-[39px] items-center gap-1 rounded-lg border border-gray-200 bg-white px-3 py-2.5 text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 focus:outline-hidden md:hidden dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
129+
class="flex h-[28px]! px-2 items-center gap-1 rounded-lg border border-gray-200 bg-white py-2.5 text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 focus:outline-hidden md:hidden dark:border-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700"
130130
>
131-
<div class="text-black dark:text-white">
132-
<IconSettings />
133-
</div>
131+
<IconSettings />
134132
{!viewSettings ? "Settings" : "Hide"}
135133
</button>
136134
{/if}
@@ -139,7 +137,7 @@
139137
<button
140138
type="button"
141139
onclick={conversations.reset}
142-
class="btn size-[39px]"
140+
class="btn size-[28px]! p-0!"
143141
{...tooltip.trigger}
144142
data-test-id={TEST_IDS.reset}
145143
>
@@ -170,7 +168,7 @@
170168
<button
171169
type="button"
172170
onclick={() => (viewCode = !viewCode)}
173-
class="btn"
171+
class="btn h-[28px]! px-2!"
174172
{@attach observe({ name: ObservedElements.BottomActions, useRaf: true })}
175173
>
176174
<IconCode />

src/lib/state/conversations.svelte.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ export type ConversationEntityMembers = MembersOnly<ConversationEntity>;
5757

5858
const conversationsRepo = repo(ConversationEntity, idb);
5959

60-
const startMessageUser: ConversationMessage = { role: "user", content: "" };
61-
6260
export const emptyModel: Model = {
6361
_id: "",
6462
inferenceProviderMapping: [],
@@ -78,7 +76,7 @@ function getDefaultConversation(projectId: string) {
7876
projectId,
7977
modelId: models.trending[0]?.id ?? models.remote[0]?.id ?? emptyModel.id,
8078
config: { ...defaultGenerationConfig },
81-
messages: [{ ...startMessageUser }],
79+
messages: [],
8280
streaming: true,
8381
createdAt: new Date(),
8482
} satisfies Partial<ConversationEntityMembers>;

0 commit comments

Comments
 (0)