Skip to content

Commit

Permalink
Fix auth bugs with concepts. Pip install lilac[all] in the dockerfile. (
Browse files Browse the repository at this point in the history
#622)

- Fix auth bugs with adding concepts.
- Make sure to install lilac[all] in the huggingface space so we can run
everything.

Compare:
https://lilacai-lilac.hf.space/datasets#lilac/mmlu_professional_law
to:

https://lilacai-nikhil-staging.hf.space/datasets#lilac/mmlu_professional_law

Towards #601
  • Loading branch information
nsthorat authored Aug 31, 2023
1 parent 128efee commit efce4d0
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ WORKDIR $HOME/app
# Install the dependencies. This will look in ./dist for any wheels that match lilac. If they are
# not found, it will use the public pip package.
COPY --chown=user /dist ./dist/
RUN python -m pip install --find-links=dist lilac
RUN python -m pip install --find-links=dist lilac[all]

COPY --chown=user .env .
COPY --chown=user .env.demo .
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started/quickstart_python.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ index once. For a fast on-device embedding, we recommend the
Before we can index with GTE-small, we need to install optional dependencies for the gte embedding:

```sh
pip install lilacai[gte]
pip install lilac[gte]
```

```py
Expand Down
2 changes: 1 addition & 1 deletion web/blueprint/src/lib/components/Navigation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$: username = $authInfo.data?.user?.given_name;
$: canCreateDataset = $authInfo.data?.access.create_dataset;
// TODO(nsthorat): Make this a separate bit for canCreateConcepts.
$: canCreateConcepts = !$authInfo.data?.auth_enabled;
$: canCreateConcepts = !$authInfo.data?.auth_enabled || $authInfo.data?.user != null;
const urlHashContext = getUrlHashContext();
const navStore = getNavigationContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
$: userId = $authInfo.data?.user?.id;
$: defaultNamespace = command.namespace || (authEnabled ? userId : null);
let namespace = defaultNamespace || 'local';
$: {
if (userId != null) {
namespace = userId;
}
}
$: dataset = command.dataset;
$: datasetId = dataset ? `${dataset.namespace}/${dataset.name}` : '';
$: path = command.path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import {TextInput} from 'carbon-components-svelte';
import TrashCan from 'carbon-icons-svelte/lib/TrashCan.svelte';
import {createEventDispatcher} from 'svelte';
import {hoverTooltip} from '../common/HoverTooltip';
export let data: Example[];
export let canEditConcept: boolean;
let newSampleText: string;
Expand All @@ -29,13 +31,21 @@
<span class="shrink">
{row.text}
</span>
<button
title="Remove sample"
class="shrink-0 opacity-50 hover:text-red-400 hover:opacity-100"
on:click={() => dispatch('remove', row.id)}
<div
use:hoverTooltip={{
text: !canEditConcept ? 'User does not have access to edit this concept.' : ''
}}
class:opacity-40={!canEditConcept}
>
<TrashCan size={16} />
</button>
<button
title="Remove sample"
class="shrink-0 opacity-50 hover:text-red-400 hover:opacity-100"
on:click={() => dispatch('remove', row.id)}
disabled={!canEditConcept}
>
<TrashCan size={16} />
</button>
</div>
</div>
{/each}
</div>
26 changes: 24 additions & 2 deletions web/blueprint/src/lib/components/concepts/ConceptView.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import {goto} from '$app/navigation';
import {editConceptMutation} from '$lib/queries/conceptQueries';
import {editConceptMutation, queryConcepts} from '$lib/queries/conceptQueries';
import {queryAuthInfo} from '$lib/queries/serverQueries';
import {queryEmbeddings} from '$lib/queries/signalQueries';
import {createDatasetViewStore} from '$lib/stores/datasetViewStore';
Expand All @@ -23,6 +23,13 @@
const authInfo = queryAuthInfo();
$: userId = $authInfo.data?.user?.id;
const concepts = queryConcepts();
$: conceptInfo = $concepts.data?.find(
c => c.namespace === concept.namespace && c.name === concept.concept_name
);
$: canEditConcept = conceptInfo?.acls.write == true;
const conceptMutation = editConceptMutation();
const embeddings = queryEmbeddings();
Expand Down Expand Up @@ -138,7 +145,20 @@
{/if}
<Expandable>
<div slot="above" class="text-md font-semibold">Collect labels</div>
<ConceptLabeler slot="below" {concept} />
<div slot="below" class="w-full">
{#if canEditConcept}
<ConceptLabeler {concept} />
{:else}
<ToastNotification
hideCloseButton
kind="warning"
fullWidth
lowContrast
title="You don't have permission to edit this concept"
caption={'You can only edit concepts you created.'}
/>
{/if}
</div>
</Expandable>
<div class="flex gap-x-4">
<div class="flex w-0 flex-grow flex-col gap-y-4">
Expand All @@ -149,6 +169,7 @@
data={positiveExamples}
on:remove={ev => remove(ev.detail)}
on:add={ev => add(ev.detail, true)}
{canEditConcept}
/>
</div>
<div class="flex w-0 flex-grow flex-col gap-y-4">
Expand All @@ -159,6 +180,7 @@
data={negativeExamples}
on:remove={ev => remove(ev.detail)}
on:add={ev => add(ev.detail, false)}
{canEditConcept}
/>
</div>
</div>
Expand Down
54 changes: 28 additions & 26 deletions web/blueprint/src/lib/components/datasetView/RowItemMedia.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
formatValue,
getValueNodes,
pathIsEqual,
serializePath,
type LilacField,
type LilacValueNode,
type Path
Expand All @@ -32,36 +33,37 @@
$: settings = querySettings($datasetViewStore.namespace, $datasetViewStore.datasetName);
$: values = getValueNodes(row, path)
.map(v => L.value(v))
.filter(notEmpty);
$: valueNodes = getValueNodes(row, path);
</script>

{#each values as value, i}
{@const suffix = values.length > 1 ? `[${i}]` : ''}
{@const markdown = $settings.data?.ui?.markdown_paths?.find(p => pathIsEqual(p, path)) != null}
<div class="flex flex-row">
<div class="flex w-full flex-col">
<div
class="sticky top-0 z-10 w-full self-start border-t border-neutral-200 bg-neutral-100 px-2 py-2
{#each valueNodes as valueNode}
{@const value = L.value(valueNode)}
{#if notEmpty(value)}
{@const path = L.path(valueNode) || []}
{@const markdown = $settings.data?.ui?.markdown_paths?.find(p => pathIsEqual(p, path)) != null}
<div class="flex flex-row">
<div class="flex w-full flex-col">
<div
class="sticky top-0 z-10 w-full self-start border-t border-neutral-200 bg-neutral-100 px-2 py-2
pb-2 font-mono font-medium text-neutral-500"
>
{path.join('.') + suffix}
</div>
>
{serializePath(path)}
</div>

<div class="mx-4 font-normal">
<StringSpanHighlight
text={formatValue(value)}
{row}
{path}
{markdown}
spanPaths={spanValuePaths.spanPaths}
valuePaths={spanValuePaths.valuePaths}
{datasetViewStore}
datasetStore={$datasetStore}
embeddings={computedEmbeddings}
/>
<div class="mx-4 font-normal">
<StringSpanHighlight
text={formatValue(value)}
{row}
{path}
{markdown}
spanPaths={spanValuePaths.spanPaths}
valuePaths={spanValuePaths.valuePaths}
{datasetViewStore}
datasetStore={$datasetStore}
embeddings={computedEmbeddings}
/>
</div>
</div>
</div>
</div>
{/if}
{/each}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import {getNotificationsContext} from '$lib/stores/notificationsStore';
import {ITEM_SCROLL_CONTAINER_CTX_KEY, mergeSpans, type MergedSpan} from '$lib/view_utils';
import {
L,
getValueNodes,
pathIncludes,
pathIsEqual,
serializePath,
type ConceptSignal,
Expand Down Expand Up @@ -56,7 +58,9 @@
$: pathToSpans = Object.fromEntries(
spanPaths.map(p => [
serializePath(p),
getValueNodes(row, p) as LilacValueNodeCasted<'string_span'>[]
getValueNodes(row, p).filter(v =>
pathIncludes(L.path(v), path)
) as LilacValueNodeCasted<'string_span'>[]
])
);
Expand Down
3 changes: 2 additions & 1 deletion web/blueprint/src/lib/view_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ export function getSpanValuePaths(
// Find the non-keyword span fields under this field.
const spanFields = children
.filter(f => f.dtype === 'string_span')
.filter(f => !childFields(f).some(c => c.dtype === 'embedding'));
.filter(f => !childFields(f).some(c => c.dtype === 'embedding'))
.filter(f => visibleFields?.some(visibleField => pathIsEqual(visibleField.path, f.path)));
const spanPaths = spanFields.map(f => f.path);

const valuePaths: SpanValueInfo[] = [];
Expand Down

0 comments on commit efce4d0

Please sign in to comment.