victor HF staff commited on
Commit
6f87481
1 Parent(s): 1cb6f6c

conversations

Browse files
src/lib/components/Playground/Playground.svelte CHANGED
@@ -38,45 +38,55 @@
38
 
39
  const startMessages: Message[] = [{ role: 'user', content: '' }];
40
 
41
- const conversations: Conversation[] = [
42
  {
43
  id: String(Math.random()),
44
  model: '01-ai/Yi-1.5-34B-Chat',
45
  config: { temperature: 0.5, maxTokens: 2048, streaming: true, jsonMode: false },
46
  messages: startMessages
 
 
 
 
 
 
47
  }
48
  ];
49
 
 
50
  let systemMessage: Message = { role: 'system', content: '' };
51
- let messages = startMessages;
52
- let currentModel = conversations[0].model;
53
- let temperature = 0.5;
54
- let maxTokens = 2048;
55
- let streaming = true;
56
- let jsonMode = false;
57
 
58
  let hfToken: string | null = '';
59
  let viewCode = false;
60
  let showTokenModal = false;
61
  let loading = false;
62
  let streamingMessage: Message | null = null;
 
63
  let latency = 0;
64
  let messageContainer: HTMLDivElement | null = null;
65
 
66
  function addMessage() {
67
- messages = [
68
- ...messages,
69
- { role: messages.at(-1)?.role === 'user' ? 'assistant' : 'user', content: '' }
 
 
 
70
  ];
 
71
  }
72
 
73
  function deleteMessage(i: number) {
74
- messages = messages.filter((_, j) => j !== i);
 
75
  }
76
 
77
  function reset() {
78
- messages = [...startMessages];
79
  systemMessage.content = '';
 
80
  }
81
 
82
  async function submit() {
@@ -92,21 +102,22 @@
92
  const hf = createHfInference(hfToken);
93
  const requestMessages = prepareRequestMessages(systemMessage, messages);
94
 
95
- if (streaming) {
96
  streamingMessage = { role: 'assistant', content: '' };
97
- messages = [...messages, streamingMessage];
98
 
99
  await handleStreamingResponse(
100
  hf,
101
- currentModel,
102
  requestMessages,
103
- temperature,
104
- maxTokens,
105
- jsonMode,
106
  (content) => {
107
  if (streamingMessage) {
108
  streamingMessage.content = content;
109
- messages = [...messages];
 
110
  scrollToBottom();
111
  }
112
  }
@@ -114,13 +125,14 @@
114
  } else {
115
  const newMessage = await handleNonStreamingResponse(
116
  hf,
117
- currentModel,
118
  requestMessages,
119
- temperature,
120
- maxTokens,
121
- jsonMode
122
  );
123
- messages = [...messages, newMessage];
 
124
  scrollToBottom();
125
  }
126
  } catch (error) {
@@ -203,7 +215,7 @@
203
  </div>
204
  </button>
205
  {:else}
206
- <PlaygroundCode model={currentModel} {streaming} {temperature} {maxTokens} />
207
  {/if}
208
  </div>
209
 
@@ -279,15 +291,15 @@
279
  {#if loading}
280
  <div class="flex flex-none items-center gap-[3px]">
281
  <div
282
- class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-400"
283
  style="animation-delay: 0.25s;"
284
  />
285
  <div
286
- class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-400"
287
  style="animation-delay: 0.5s;"
288
  />
289
  <div
290
- class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-400"
291
  style="animation-delay: 0.75s;"
292
  />
293
  </div>
@@ -302,7 +314,12 @@
302
  </div>
303
  <div class="flex flex-col gap-6 overflow-y-hidden p-5">
304
  <PlaygroundModelSelector {compatibleModels} bind:currentModel />
305
- <PlaygroundOptions bind:temperature bind:maxTokens bind:jsonMode bind:streaming />
 
 
 
 
 
306
  <!-- <div
307
  class="mt-auto flex max-w-xs flex-col items-start gap-2.5 rounded-lg border bg-white p-4 text-gray-500 shadow dark:border-gray-800 dark:bg-gray-800/50 dark:text-gray-400"
308
  role="alert"
 
38
 
39
  const startMessages: Message[] = [{ role: 'user', content: '' }];
40
 
41
+ let conversations: Conversation[] = [
42
  {
43
  id: String(Math.random()),
44
  model: '01-ai/Yi-1.5-34B-Chat',
45
  config: { temperature: 0.5, maxTokens: 2048, streaming: true, jsonMode: false },
46
  messages: startMessages
47
+ },
48
+ {
49
+ id: String(Math.random()),
50
+ model: 'google/gemma-1.1-2b-it',
51
+ config: { temperature: 0.1, maxTokens: 2048, streaming: true, jsonMode: false },
52
+ messages: startMessages
53
  }
54
  ];
55
 
56
+ let currentConversation = conversations[0];
57
  let systemMessage: Message = { role: 'system', content: '' };
58
+ $: messages = currentConversation.messages;
59
+ $: currentModel = currentConversation.model;
 
 
 
 
60
 
61
  let hfToken: string | null = '';
62
  let viewCode = false;
63
  let showTokenModal = false;
64
  let loading = false;
65
  let streamingMessage: Message | null = null;
66
+ let tokens = 0;
67
  let latency = 0;
68
  let messageContainer: HTMLDivElement | null = null;
69
 
70
  function addMessage() {
71
+ currentConversation.messages = [
72
+ ...currentConversation.messages,
73
+ {
74
+ role: currentConversation.messages.at(-1)?.role === 'user' ? 'assistant' : 'user',
75
+ content: ''
76
+ }
77
  ];
78
+ conversations = conversations;
79
  }
80
 
81
  function deleteMessage(i: number) {
82
+ currentConversation.messages = currentConversation.messages.filter((_, j) => j !== i);
83
+ conversations = conversations;
84
  }
85
 
86
  function reset() {
87
+ currentConversation.messages = [...startMessages];
88
  systemMessage.content = '';
89
+ conversations = conversations;
90
  }
91
 
92
  async function submit() {
 
102
  const hf = createHfInference(hfToken);
103
  const requestMessages = prepareRequestMessages(systemMessage, messages);
104
 
105
+ if (currentConversation.config.streaming) {
106
  streamingMessage = { role: 'assistant', content: '' };
107
+ currentConversation.messages = [...currentConversation.messages, streamingMessage];
108
 
109
  await handleStreamingResponse(
110
  hf,
111
+ currentConversation.model,
112
  requestMessages,
113
+ currentConversation.config.temperature,
114
+ currentConversation.config.maxTokens,
115
+ currentConversation.config.jsonMode,
116
  (content) => {
117
  if (streamingMessage) {
118
  streamingMessage.content = content;
119
+ currentConversation.messages = [...currentConversation.messages];
120
+ conversations = conversations;
121
  scrollToBottom();
122
  }
123
  }
 
125
  } else {
126
  const newMessage = await handleNonStreamingResponse(
127
  hf,
128
+ currentConversation.model,
129
  requestMessages,
130
+ currentConversation.config.temperature,
131
+ currentConversation.config.maxTokens,
132
+ currentConversation.config.jsonMode
133
  );
134
+ currentConversation.messages = [...currentConversation.messages, newMessage];
135
+ conversations = conversations;
136
  scrollToBottom();
137
  }
138
  } catch (error) {
 
215
  </div>
216
  </button>
217
  {:else}
218
+ <PlaygroundCode model={currentModel} {...currentConversation.config} />
219
  {/if}
220
  </div>
221
 
 
291
  {#if loading}
292
  <div class="flex flex-none items-center gap-[3px]">
293
  <div
294
+ class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-200"
295
  style="animation-delay: 0.25s;"
296
  />
297
  <div
298
+ class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-200"
299
  style="animation-delay: 0.5s;"
300
  />
301
  <div
302
+ class="h-1 w-1 flex-none animate-bounce rounded-full bg-gray-500 dark:bg-gray-200"
303
  style="animation-delay: 0.75s;"
304
  />
305
  </div>
 
314
  </div>
315
  <div class="flex flex-col gap-6 overflow-y-hidden p-5">
316
  <PlaygroundModelSelector {compatibleModels} bind:currentModel />
317
+ <PlaygroundOptions
318
+ bind:temperature={currentConversation.config.temperature}
319
+ bind:maxTokens={currentConversation.config.maxTokens}
320
+ bind:jsonMode={currentConversation.config.jsonMode}
321
+ bind:streaming={currentConversation.config.streaming}
322
+ />
323
  <!-- <div
324
  class="mt-auto flex max-w-xs flex-col items-start gap-2.5 rounded-lg border bg-white p-4 text-gray-500 shadow dark:border-gray-800 dark:bg-gray-800/50 dark:text-gray-400"
325
  role="alert"
src/lib/components/Playground/PlaygroundOptions.svelte CHANGED
@@ -2,6 +2,7 @@
2
  export let temperature = 0.5;
3
  export let maxTokens = 2048;
4
  export let streaming = true;
 
5
  </script>
6
 
7
  <div>
@@ -65,7 +66,7 @@
65
  </div>
66
  <div class="mt-2">
67
  <label class="flex cursor-pointer items-center justify-between">
68
- <input type="checkbox" value="" class="peer sr-only" disabled />
69
  <span class="text-sm font-medium text-gray-900 dark:text-gray-300">JSON Mode</span>
70
  <div
71
  class="peer relative h-5 w-9 rounded-full bg-gray-200 after:absolute after:start-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-black peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:peer-checked:bg-blue-600"
 
2
  export let temperature = 0.5;
3
  export let maxTokens = 2048;
4
  export let streaming = true;
5
+ export let jsonMode = true;
6
  </script>
7
 
8
  <div>
 
66
  </div>
67
  <div class="mt-2">
68
  <label class="flex cursor-pointer items-center justify-between">
69
+ <input type="checkbox" value="" class="peer sr-only" disabled bind:checked={jsonMode} />
70
  <span class="text-sm font-medium text-gray-900 dark:text-gray-300">JSON Mode</span>
71
  <div
72
  class="peer relative h-5 w-9 rounded-full bg-gray-200 after:absolute after:start-[2px] after:top-[2px] after:h-4 after:w-4 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:bg-black peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:peer-checked:bg-blue-600"