Thomas G. Lopes
commited on
Commit
·
6a8491a
1
Parent(s):
654f56a
working project select
Browse files
src/lib/components/InferencePlayground/InferencePlaygroundProjectSelect.svelte
CHANGED
@@ -3,31 +3,35 @@
|
|
3 |
import { cn } from "$lib/utils/cn";
|
4 |
import { createSelect, createSync } from "@melt-ui/svelte";
|
5 |
import IconCaret from "../Icons/IconCaret.svelte";
|
6 |
-
import
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
const {
|
9 |
elements: { trigger, menu, option },
|
10 |
-
states: { selected },
|
11 |
} = createSelect<string, false>();
|
12 |
const sync = createSync({ selected });
|
13 |
$: sync.selected({ value: getActiveProject($session).id, label: getActiveProject($session).name }, p => {
|
14 |
-
if (p
|
|
|
|
|
|
|
|
|
15 |
});
|
16 |
</script>
|
17 |
|
18 |
<div class="flex flex-col gap-2">
|
19 |
-
<!--
|
20 |
-
<label class="flex items-baseline gap-2 text-sm font-medium text-gray-900 dark:text-white">
|
21 |
-
Providers<span class="text-xs font-normal text-gray-400"></span>
|
22 |
-
</label>
|
23 |
-
-->
|
24 |
-
|
25 |
<button
|
26 |
{...$trigger}
|
27 |
use:trigger
|
28 |
class={cn(
|
29 |
"relative flex items-center justify-between gap-6 overflow-hidden rounded-lg border bg-gray-100/80 px-3 py-1.5 leading-tight whitespace-nowrap shadow-sm",
|
30 |
-
"hover:brightness-95 dark:border-gray-700 dark:bg-gray-800 dark:hover:brightness-110"
|
|
|
31 |
)}
|
32 |
>
|
33 |
<div class="flex items-center gap-1 text-sm">
|
@@ -47,8 +51,24 @@
|
|
47 |
class="flex items-center gap-2 rounded-md px-2 py-1.5 group-data-[highlighted]:bg-gray-200 dark:group-data-[highlighted]:bg-gray-700"
|
48 |
>
|
49 |
{name}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
</div>
|
51 |
</button>
|
52 |
{/each}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
</div>
|
54 |
</div>
|
|
|
3 |
import { cn } from "$lib/utils/cn";
|
4 |
import { createSelect, createSync } from "@melt-ui/svelte";
|
5 |
import IconCaret from "../Icons/IconCaret.svelte";
|
6 |
+
import IconDelete from "../Icons/IconDelete.svelte";
|
7 |
+
|
8 |
+
let classNames: string = "";
|
9 |
+
export { classNames as class };
|
10 |
+
|
11 |
+
const newProjectId = "__new-project-i-hope-no-one-uses-this-as-an-id__";
|
12 |
|
13 |
const {
|
14 |
elements: { trigger, menu, option },
|
15 |
+
states: { selected, open },
|
16 |
} = createSelect<string, false>();
|
17 |
const sync = createSync({ selected });
|
18 |
$: sync.selected({ value: getActiveProject($session).id, label: getActiveProject($session).name }, p => {
|
19 |
+
if (p?.value === newProjectId) {
|
20 |
+
session.addProject("Project #" + ($session.projects.length + 1));
|
21 |
+
} else if (p) {
|
22 |
+
$session.activeProjectId = p?.value;
|
23 |
+
}
|
24 |
});
|
25 |
</script>
|
26 |
|
27 |
<div class="flex flex-col gap-2">
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
<button
|
29 |
{...$trigger}
|
30 |
use:trigger
|
31 |
class={cn(
|
32 |
"relative flex items-center justify-between gap-6 overflow-hidden rounded-lg border bg-gray-100/80 px-3 py-1.5 leading-tight whitespace-nowrap shadow-sm",
|
33 |
+
"hover:brightness-95 dark:border-gray-700 dark:bg-gray-800 dark:hover:brightness-110",
|
34 |
+
classNames
|
35 |
)}
|
36 |
>
|
37 |
<div class="flex items-center gap-1 text-sm">
|
|
|
51 |
class="flex items-center gap-2 rounded-md px-2 py-1.5 group-data-[highlighted]:bg-gray-200 dark:group-data-[highlighted]:bg-gray-700"
|
52 |
>
|
53 |
{name}
|
54 |
+
<button
|
55 |
+
class="ml-auto grid place-items-center rounded-md p-1 hover:bg-gray-300 dark:hover:bg-gray-600"
|
56 |
+
on:click={e => {
|
57 |
+
e.stopPropagation();
|
58 |
+
session.deleteProject(id);
|
59 |
+
}}
|
60 |
+
>
|
61 |
+
<IconDelete />
|
62 |
+
</button>
|
63 |
</div>
|
64 |
</button>
|
65 |
{/each}
|
66 |
+
<button {...$option({ value: newProjectId })} use:option class="group block w-full p-1 text-sm dark:text-white">
|
67 |
+
<div
|
68 |
+
class="flex items-center gap-2 rounded-md px-2 py-1.5 group-data-[highlighted]:bg-gray-200 dark:group-data-[highlighted]:bg-gray-700"
|
69 |
+
>
|
70 |
+
Add new project
|
71 |
+
</div>
|
72 |
+
</button>
|
73 |
</div>
|
74 |
</div>
|
src/lib/stores/session.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import { goto } from "$app/navigation";
|
2 |
import { defaultGenerationConfig } from "$lib/components/InferencePlayground/generationConfigSettings";
|
3 |
import { models } from "$lib/stores/models";
|
4 |
import {
|
@@ -38,7 +37,7 @@ const emptyModel: ModelWithTokenizer = {
|
|
38 |
};
|
39 |
|
40 |
function createSessionStore() {
|
41 |
-
|
42 |
const $models = get(models);
|
43 |
const featured = getTrending($models);
|
44 |
const defaultModel = featured[0] ?? $models[0] ?? emptyModel;
|
@@ -63,6 +62,12 @@ function createSessionStore() {
|
|
63 |
conversations: [defaultConversation],
|
64 |
};
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
// Get saved session from localStorage if available
|
67 |
let savedSession: Session = {
|
68 |
projects: [defaultProject],
|
@@ -139,11 +144,36 @@ function createSessionStore() {
|
|
139 |
};
|
140 |
|
141 |
// Add a method to clear localStorage
|
142 |
-
|
143 |
localStorage.removeItem(LOCAL_STORAGE_KEY);
|
144 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
-
return { ...store, set, update, clearSavedSession };
|
147 |
}
|
148 |
|
149 |
export const session = createSessionStore();
|
|
|
|
|
1 |
import { defaultGenerationConfig } from "$lib/components/InferencePlayground/generationConfigSettings";
|
2 |
import { models } from "$lib/stores/models";
|
3 |
import {
|
|
|
37 |
};
|
38 |
|
39 |
function createSessionStore() {
|
40 |
+
function getDefaults() {
|
41 |
const $models = get(models);
|
42 |
const featured = getTrending($models);
|
43 |
const defaultModel = featured[0] ?? $models[0] ?? emptyModel;
|
|
|
62 |
conversations: [defaultConversation],
|
63 |
};
|
64 |
|
65 |
+
return { defaultProject, defaultConversation };
|
66 |
+
}
|
67 |
+
|
68 |
+
const store = writable<Session>(undefined, set => {
|
69 |
+
const { defaultConversation, defaultProject } = getDefaults();
|
70 |
+
|
71 |
// Get saved session from localStorage if available
|
72 |
let savedSession: Session = {
|
73 |
projects: [defaultProject],
|
|
|
144 |
};
|
145 |
|
146 |
// Add a method to clear localStorage
|
147 |
+
function clearSavedSession() {
|
148 |
localStorage.removeItem(LOCAL_STORAGE_KEY);
|
149 |
+
}
|
150 |
+
|
151 |
+
function addProject(name: string) {
|
152 |
+
const { defaultConversation } = getDefaults();
|
153 |
+
update(s => {
|
154 |
+
const project: Project = {
|
155 |
+
name,
|
156 |
+
id: crypto.randomUUID(),
|
157 |
+
conversations: [defaultConversation],
|
158 |
+
};
|
159 |
+
|
160 |
+
return { ...s, projects: [...s.projects, project], activeProjectId: project.id };
|
161 |
+
});
|
162 |
+
}
|
163 |
+
|
164 |
+
function deleteProject(id: string) {
|
165 |
+
update(s => {
|
166 |
+
const projects = s.projects.filter(p => p.id !== id);
|
167 |
+
if (projects.length === 0) {
|
168 |
+
const { defaultProject } = getDefaults();
|
169 |
+
return { ...s, projects: [defaultProject], activeProjectId: defaultProject.id };
|
170 |
+
}
|
171 |
+
const currProject = projects.find(p => p.id === s.activeProjectId);
|
172 |
+
return { ...s, projects, activeProjectId: currProject?.id ?? projects[0]?.id! };
|
173 |
+
});
|
174 |
+
}
|
175 |
|
176 |
+
return { ...store, set, update, clearSavedSession, addProject, deleteProject };
|
177 |
}
|
178 |
|
179 |
export const session = createSessionStore();
|