mishig HF staff commited on
Commit
b34b73b
1 Parent(s): af2caac
src/lib/components/InferencePlayground/InferencePlayground.svelte CHANGED
@@ -32,17 +32,12 @@
32
  }
33
  ];
34
 
35
- $: if (conversations.length > 1) {
36
- viewCode = false;
37
- }
38
-
39
  let systemMessage: ChatCompletionInputMessage = { role: 'system', content: '' };
40
  let hfToken: string | null = import.meta.env.VITE_HF_TOKEN;
41
  let viewCode = false;
42
  let showTokenModal = false;
43
  let showModelPickerModal = false;
44
  let loading = false;
45
- let tokens = 0;
46
  let latency = 0;
47
  let abortControllers: AbortController[] = [];
48
  let waitForNonStreaming = true;
@@ -96,11 +91,6 @@
96
  });
97
  }
98
 
99
- function deleteConversation(idx: number) {
100
- deleteAndGetItem(conversations, idx);
101
- conversations = conversations;
102
- }
103
-
104
  function reset() {
105
  systemMessage.content = '';
106
  conversations = conversations.map((conversation) => {
@@ -123,10 +113,6 @@
123
  async function runInference(conversation: Conversation) {
124
  const startTime = performance.now();
125
  const hf = createHfInference(hfToken);
126
- const requestMessages = [
127
- ...(systemPromptSupported && systemMessage?.content?.length ? [systemMessage] : []),
128
- ...conversation.messages
129
- ];
130
 
131
  if (conversation.streaming) {
132
  const streamingMessage = { role: 'assistant', content: '' };
@@ -262,22 +248,18 @@
262
  ? '*:w-1/3'
263
  : '*:w-full'} dark:divide-gray-800"
264
  >
265
- {#each conversations as conversation, index}
266
- <Conversation
267
- {loading}
268
- {conversation}
269
- {index}
270
- {viewCode}
271
- sideBySide={conversations.length > 1}
272
- on:addMessage={addMessage}
273
- on:messageValueChanged={(e) => {
274
- const { conversationIdx, messageIdx, value } = e.detail;
275
- updateMessage(value, conversationIdx, messageIdx);
276
- }}
277
- on:deleteMessage={(e) => deleteMessage(e.detail)}
278
- on:deleteConversation={(e) => deleteConversation(e.detail)}
279
- />
280
- {/each}
281
  </div>
282
  <div
283
  class="fixed inset-x-0 bottom-0 flex h-20 items-center gap-2 overflow-hidden whitespace-nowrap px-3 md:absolute"
 
32
  }
33
  ];
34
 
 
 
 
 
35
  let systemMessage: ChatCompletionInputMessage = { role: 'system', content: '' };
36
  let hfToken: string | null = import.meta.env.VITE_HF_TOKEN;
37
  let viewCode = false;
38
  let showTokenModal = false;
39
  let showModelPickerModal = false;
40
  let loading = false;
 
41
  let latency = 0;
42
  let abortControllers: AbortController[] = [];
43
  let waitForNonStreaming = true;
 
91
  });
92
  }
93
 
 
 
 
 
 
94
  function reset() {
95
  systemMessage.content = '';
96
  conversations = conversations.map((conversation) => {
 
113
  async function runInference(conversation: Conversation) {
114
  const startTime = performance.now();
115
  const hf = createHfInference(hfToken);
 
 
 
 
116
 
117
  if (conversation.streaming) {
118
  const streamingMessage = { role: 'assistant', content: '' };
 
248
  ? '*:w-1/3'
249
  : '*:w-full'} dark:divide-gray-800"
250
  >
251
+ <Conversation
252
+ {loading}
253
+ conversation={conversations[0]}
254
+ index={0}
255
+ {viewCode}
256
+ on:addMessage={addMessage}
257
+ on:messageValueChanged={(e) => {
258
+ const { conversationIdx, messageIdx, value } = e.detail;
259
+ updateMessage(value, conversationIdx, messageIdx);
260
+ }}
261
+ on:deleteMessage={(e) => deleteMessage(e.detail)}
262
+ />
 
 
 
 
263
  </div>
264
  <div
265
  class="fixed inset-x-0 bottom-0 flex h-20 items-center gap-2 overflow-hidden whitespace-nowrap px-3 md:absolute"
src/lib/components/InferencePlayground/InferencePlaygroundConversation.svelte CHANGED
@@ -2,20 +2,16 @@
2
  import { createEventDispatcher } from 'svelte';
3
  import CodeSnippets from './InferencePlaygroundCodeSnippets.svelte';
4
  import Message from './InferencePlaygroundMessage.svelte';
5
- import PlaygroundOptions from './InferencePlaygroundGenerationConfig.svelte';
6
  import IconPlus from '../Icons/IconPlus.svelte';
7
  import type { Conversation } from '$lib/types';
8
 
9
  export let loading;
10
  export let conversation: Conversation;
11
- export let index;
12
  export let viewCode;
13
- export let sideBySide = false;
14
 
15
  const dispatch = createEventDispatcher<{
16
  addMessage: void;
17
  deleteMessage: number;
18
- deleteConversation: number;
19
  }>();
20
 
21
  let messageContainer: HTMLDivElement | null = null;
@@ -39,49 +35,15 @@
39
  class:animate-pulse={loading && !conversation.streaming}
40
  bind:this={messageContainer}
41
  >
42
- {#if sideBySide}
43
- <div
44
- class="sticky top-0 flex h-11 flex-none items-center gap-2 whitespace-nowrap rounded-lg border border-gray-200/80 bg-white pl-3 pr-2 text-sm leading-none shadow-sm *:flex-none dark:border-gray-800 dark:bg-gray-800/70 dark:hover:bg-gray-800"
45
- class:mr-3={index === 0}
46
- class:mx-3={index === 1}
47
- >
48
- <div class="size-3.5 rounded bg-black dark:bg-gray-400"></div>
49
- <div>{conversation.model}</div>
50
- <button
51
- class="ml-auto flex size-6 items-center justify-center rounded bg-gray-50 text-xs hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700"
52
- on:click={() => dispatch('deleteConversation', index)}
53
- >
54
-
55
- </button>
56
- <button
57
- class="group relative flex size-6 items-center justify-center rounded bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700"
58
- >
59
- <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32"
60
- ><path
61
- fill="currentColor"
62
- d="M27 16.76v-1.53l1.92-1.68A2 2 0 0 0 29.3 11l-2.36-4a2 2 0 0 0-1.73-1a2 2 0 0 0-.64.1l-2.43.82a11.35 11.35 0 0 0-1.31-.75l-.51-2.52a2 2 0 0 0-2-1.61h-4.68a2 2 0 0 0-2 1.61l-.51 2.52a11.48 11.48 0 0 0-1.32.75l-2.38-.86A2 2 0 0 0 6.79 6a2 2 0 0 0-1.73 1L2.7 11a2 2 0 0 0 .41 2.51L5 15.24v1.53l-1.89 1.68A2 2 0 0 0 2.7 21l2.36 4a2 2 0 0 0 1.73 1a2 2 0 0 0 .64-.1l2.43-.82a11.35 11.35 0 0 0 1.31.75l.51 2.52a2 2 0 0 0 2 1.61h4.72a2 2 0 0 0 2-1.61l.51-2.52a11.48 11.48 0 0 0 1.32-.75l2.42.82a2 2 0 0 0 .64.1a2 2 0 0 0 1.73-1l2.28-4a2 2 0 0 0-.41-2.51ZM25.21 24l-3.43-1.16a8.86 8.86 0 0 1-2.71 1.57L18.36 28h-4.72l-.71-3.55a9.36 9.36 0 0 1-2.7-1.57L6.79 24l-2.36-4l2.72-2.4a8.9 8.9 0 0 1 0-3.13L4.43 12l2.36-4l3.43 1.16a8.86 8.86 0 0 1 2.71-1.57L13.64 4h4.72l.71 3.55a9.36 9.36 0 0 1 2.7 1.57L25.21 8l2.36 4l-2.72 2.4a8.9 8.9 0 0 1 0 3.13L27.57 20Z"
63
- /><path
64
- fill="currentColor"
65
- d="M16 22a6 6 0 1 1 6-6a5.94 5.94 0 0 1-6 6Zm0-10a3.91 3.91 0 0 0-4 4a3.91 3.91 0 0 0 4 4a3.91 3.91 0 0 0 4-4a3.91 3.91 0 0 0-4-4Z"
66
- /></svg
67
- >
68
- <PlaygroundOptions
69
- bind:conversation
70
- classNames="absolute top-8 right-0 w-56 invisible group-focus:visible hover:visible border border-gray-200/80 bg-white z-10 px-4 py-6 text-sm shadow-sm dark:border-gray-800 dark:bg-gray-800 rounded-xl"
71
- />
72
- </button>
73
- </div>
74
- {/if}
75
  {#if !viewCode}
76
  {#each conversation.messages as message, messageIdx}
77
  <Message
78
  class="border-b"
79
  {message}
80
- conversationIdx={index}
81
  {messageIdx}
82
  on:messageValueChanged
83
  on:delete={() => dispatch('deleteMessage', messageIdx)}
84
- autofocus={!sideBySide && !loading && messageIdx === conversation.messages.length - 1}
85
  />
86
  {/each}
87
 
 
2
  import { createEventDispatcher } from 'svelte';
3
  import CodeSnippets from './InferencePlaygroundCodeSnippets.svelte';
4
  import Message from './InferencePlaygroundMessage.svelte';
 
5
  import IconPlus from '../Icons/IconPlus.svelte';
6
  import type { Conversation } from '$lib/types';
7
 
8
  export let loading;
9
  export let conversation: Conversation;
 
10
  export let viewCode;
 
11
 
12
  const dispatch = createEventDispatcher<{
13
  addMessage: void;
14
  deleteMessage: number;
 
15
  }>();
16
 
17
  let messageContainer: HTMLDivElement | null = null;
 
35
  class:animate-pulse={loading && !conversation.streaming}
36
  bind:this={messageContainer}
37
  >
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  {#if !viewCode}
39
  {#each conversation.messages as message, messageIdx}
40
  <Message
41
  class="border-b"
42
  {message}
 
43
  {messageIdx}
44
  on:messageValueChanged
45
  on:delete={() => dispatch('deleteMessage', messageIdx)}
46
+ autofocus={!loading && messageIdx === conversation.messages.length - 1}
47
  />
48
  {/each}
49
 
src/lib/components/InferencePlayground/InferencePlaygroundMessage.svelte CHANGED
@@ -3,13 +3,12 @@
3
  import { type ChatCompletionInputMessage } from '@huggingface/tasks';
4
 
5
  export let message: ChatCompletionInputMessage;
6
- export let conversationIdx: number;
7
  export let messageIdx: number;
8
  export let autofocus: boolean = false;
9
 
10
  const dispatch = createEventDispatcher<{
11
  delete: void;
12
- messageValueChanged: { conversationIdx: number; messageIdx: number; value: string };
13
  }>();
14
  </script>
15
 
@@ -22,8 +21,7 @@
22
  <textarea
23
  {autofocus}
24
  value={message.content}
25
- on:input={(e) =>
26
- dispatch('messageValueChanged', { conversationIdx, messageIdx, value: e.target.value })}
27
  placeholder="Enter {message.role} message"
28
  class="resize-none rounded bg-transparent px-2 py-2.5 ring-gray-100 [field-sizing:content] hover:resize-y hover:bg-white focus:resize-y focus:bg-white focus:ring group-hover/message:ring @2xl:px-3 dark:ring-gray-600 dark:hover:bg-gray-900 dark:focus:bg-gray-900"
29
  rows="1"
 
3
  import { type ChatCompletionInputMessage } from '@huggingface/tasks';
4
 
5
  export let message: ChatCompletionInputMessage;
 
6
  export let messageIdx: number;
7
  export let autofocus: boolean = false;
8
 
9
  const dispatch = createEventDispatcher<{
10
  delete: void;
11
+ messageValueChanged: { messageIdx: number; value: string };
12
  }>();
13
  </script>
14
 
 
21
  <textarea
22
  {autofocus}
23
  value={message.content}
24
+ on:input={(e) => dispatch('messageValueChanged', { messageIdx, value: e.target.value })}
 
25
  placeholder="Enter {message.role} message"
26
  class="resize-none rounded bg-transparent px-2 py-2.5 ring-gray-100 [field-sizing:content] hover:resize-y hover:bg-white focus:resize-y focus:bg-white focus:ring group-hover/message:ring @2xl:px-3 dark:ring-gray-600 dark:hover:bg-gray-900 dark:focus:bg-gray-900"
27
  rows="1"