Skip to content

Commit

Permalink
Rename USE_TABLE_INDEX => LILAC_USE_TABLE_INDEX. Add LILAC_PROD_MODE. (
Browse files Browse the repository at this point in the history
…#1134)

Renames USE_TABLE_INDEX to LILAC_USE_TABLE_INDEX, and then makes sure
it's backwards compat.

Add LILAC_PROD_MODE, which disables toast notification errors for the
public demo, which makes it just look janky and broken.

Also add embeddings to missing datasets.
  • Loading branch information
nsthorat authored Jan 26, 2024
1 parent 1ec5818 commit 36281ae
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 29 deletions.
8 changes: 4 additions & 4 deletions lilac/data/dataset_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def __init__(
self._signal_manifests: list[SignalManifest] = []
self._map_manifests: list[MapManifest] = []
self._label_schemas: dict[str, Schema] = {}
if env('USE_TABLE_INDEX', default=False):
if env('LILAC_USE_TABLE_INDEX', default=False):
self.con = duckdb.connect(database=os.path.join(self.dataset_path, DUCKDB_CACHE_FILE))
else:
self.con = duckdb.connect(database=':memory:')
Expand Down Expand Up @@ -521,7 +521,7 @@ def _recompute_joint_table(self, latest_mtime_micro_sec: int) -> DatasetManifest
[SOURCE_VIEW_NAME]
+ [f'LEFT JOIN {escape_col_name(parquet_id)} USING ({ROWID})' for parquet_id in parquet_ids]
)
if env('USE_TABLE_INDEX', default=False):
if env('LILAC_USE_TABLE_INDEX', default=False):
self.con.execute(
"""CREATE TABLE IF NOT EXISTS mtime_cache AS
(SELECT CAST(0 AS bigint) AS mtime);"""
Expand Down Expand Up @@ -572,7 +572,7 @@ def _clear_joint_table_cache(self) -> None:
"""Clears the cache for the joint table."""
self._recompute_joint_table.cache_clear()
self._pivot_cache.clear()
if env('USE_TABLE_INDEX', default=False):
if env('LILAC_USE_TABLE_INDEX', default=False):
self.con.execute('DROP TABLE IF EXISTS mtime_cache')

def _add_map_keys_to_schema(self, path: PathTuple, field: Field, merged_schema: Schema) -> None:
Expand Down Expand Up @@ -2901,7 +2901,7 @@ def _create_where(
# So, we insert a range clause to limit the extent of the index scan. This optimization
# works well because nearly all of our queries are sorted by rowid, meaning that min/max
# will narrow down the index scan to a small range.
if env('USE_TABLE_INDEX', default=False) and ROWID in select_str:
if env('LILAC_USE_TABLE_INDEX', default=False) and ROWID in select_str:
min_row, max_row = min(filter_list_val), max(filter_list_val)
filter_query += f' AND {ROWID} BETWEEN {min_row} AND {max_row}'
# wrap in parens to isolate from other filters, just in case?
Expand Down
14 changes: 13 additions & 1 deletion lilac/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ class LilacEnvironment(BaseModel):
description='Turn on Lilac debug mode to log queries and timing information.'
)
DISABLE_LOGS: str = PydanticField(description='Disable log() statements to the console.')
USE_TABLE_INDEX: str = PydanticField(description='Use persistent tables with rowid indexes.')
USE_TABLE_INDEX: str = PydanticField(
description='Use persistent tables with rowid indexes.'
' NOTE: This is deprecated in favor of USE_TABLE_INDEX.'
)
LILAC_USE_TABLE_INDEX: str = PydanticField(
description='Use persistent tables with rowid indexes.'
)
LILAC_DISABLE_ERROR_NOTIFICATIONS: str = PydanticField(
description='Set lilac in production mode. This will disable error messages in the UI.'
)

# API Keys.
OPENAI_API_KEY: str = PydanticField(
Expand Down Expand Up @@ -140,6 +149,9 @@ def _init_env() -> None:

def env(key: str, default: Optional[Any] = None) -> Any:
"""Return the value of an environment variable."""
# For backwards compatibility, shim USE_TABLE_INDEX to LILAC_USE_TABLE_INDEX.
if key == 'USE_TABLE_INDEX':
key = 'LILAC_USE_TABLE_INDEX'
return os.environ.get(key, default)


Expand Down
2 changes: 2 additions & 0 deletions lilac/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class ServerStatus(BaseModel):

version: str
google_analytics_enabled: bool
disable_error_notifications: bool


@app.get('/status')
Expand All @@ -142,6 +143,7 @@ def status() -> ServerStatus:
return ServerStatus(
version=metadata.version('lilac'),
google_analytics_enabled=env('GOOGLE_ANALYTICS_ENABLED', False),
disable_error_notifications=env('LILAC_DISABLE_ERROR_NOTIFICATIONS', False),
)


Expand Down
18 changes: 17 additions & 1 deletion lilac_hf_space.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ datasets:
- - conversations
- '*'
- value
embeddings:
- embedding: gte-small
path:
- conversations
- '*'
- value

- namespace: lilac
name: UltraChat-200k
Expand All @@ -159,6 +165,13 @@ datasets:
media_paths:
- prompt
- completion
embeddings:
- embedding: gte-small
path:
- prompt
- embedding: gte-small
path:
- completion

## Eval datasets
- namespace: lilac
Expand Down Expand Up @@ -385,7 +398,10 @@ datasets:
- instruction
- input
- output

embeddings:
- embedding: gte-small
path:
- instruction
signals:
- signal_name: text_statistics
- signal_name: lang_detection
Expand Down
33 changes: 33 additions & 0 deletions web/blueprint/src/lib/components/ErrorNotifications.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script lang="ts">
import {apiErrors} from '$lib/queries/queryClient';
import {ToastNotification} from 'carbon-components-svelte';
import {queryServerStatus} from '$lib/queries/serverQueries';
import type {ApiError} from '$lilac';
import ApiErrorModal from './ApiErrorModal.svelte';
let showError: ApiError | undefined = undefined;
$: serverStatus = queryServerStatus();
$: disableErrorNotifications = $serverStatus.data?.disable_error_notifications;
</script>

{#if !disableErrorNotifications}
{#each $apiErrors as error}
<ToastNotification
lowContrast
title={error.name || 'Error'}
subtitle={error.body.message || error.message}
on:close={() => {
$apiErrors = $apiErrors.filter(e => e !== error);
}}
>
<div slot="caption">
<button class="underline" on:click={() => (showError = error)}>Show error</button>
</div>
</ToastNotification>
{/each}
{#if showError}
<ApiErrorModal error={showError} />
{/if}
{/if}
27 changes: 4 additions & 23 deletions web/blueprint/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts">
import ApiErrorModal from '$lib/components/ApiErrorModal.svelte';
import {apiErrors, queryClient} from '$lib/queries/queryClient';
import {queryClient} from '$lib/queries/queryClient';
import TaskMonitor from '$lib/stores/TaskMonitor.svelte';
import {OpenAPI, type ApiError} from '$lilac';
import {OpenAPI} from '$lilac';
import {QueryClientProvider} from '@tanstack/svelte-query';
import {Theme, ToastNotification} from 'carbon-components-svelte';
import {onMount} from 'svelte';
Expand All @@ -21,12 +20,11 @@
import {slide} from 'svelte/transition';
import {base} from '$app/paths';
import ErrorNotifications from '$lib/components/ErrorNotifications.svelte';
import GoogleAnalytics from '$lib/components/GoogleAnalytics.svelte';
import {SIDEBAR_TRANSITION_TIME_MS} from '$lib/view_utils';
import '../app.css';
let showError: ApiError | undefined = undefined;
// Set the base URL for the OpenAPI requests when the app is served from a subdir.
OpenAPI.BASE = base;
Expand Down Expand Up @@ -138,24 +136,7 @@
{/each}
</div>
<div class="absolute bottom-4 right-4" style="z-index: 1000">
{#each $apiErrors as error}
<ToastNotification
lowContrast
title={error.name || 'Error'}
subtitle={error.body.message || error.message}
on:close={() => {
$apiErrors = $apiErrors.filter(e => e !== error);
}}
>
<div slot="caption">
<button class="underline" on:click={() => (showError = error)}>Show error</button>
</div>
</ToastNotification>
{/each}

{#if showError}
<ApiErrorModal error={showError} />
{/if}
<ErrorNotifications />
</div>

<TaskMonitor />
Expand Down
1 change: 1 addition & 0 deletions web/lib/fastapi_client/models/ServerStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
export type ServerStatus = {
version: string;
google_analytics_enabled: boolean;
disable_error_notifications: boolean;
};

0 comments on commit 36281ae

Please sign in to comment.