Skip to content

Commit

Permalink
Revert "Option to disable login on first N messages (huggingface#352)"
Browse files Browse the repository at this point in the history
This reverts commit 6183fe7.
  • Loading branch information
gary149 committed Jul 19, 2023
1 parent 6183fe7 commit 0a662b7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
9 changes: 4 additions & 5 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ PUBLIC_SHARE_PREFIX=#https://hf.co/chat
PUBLIC_GOOGLE_ANALYTICS_ID=#G-XXXXXXXX / Leave empty to disable
PUBLIC_DEPRECATED_GOOGLE_ANALYTICS_ID=#UA-XXXXXXXX-X / Leave empty to disable
PUBLIC_ANNOUNCEMENT_BANNERS=`[
{
"title": "Llama v2 is live on HuggingChat! 🦙",
"linkTitle": "Announcement",
"linkHref": "https://huggingface.co/blog/llama2"
{
"title": "Chat UI is now open sourced on GitHub",
"linkTitle": "GitHub repo",
"linkHref": "https://github.com/huggingface/chat-ui"
}
]`

Expand All @@ -72,7 +72,6 @@ PARQUET_EXPORT_HF_TOKEN=
PARQUET_EXPORT_SECRET=

RATE_LIMIT= # requests per minute
MESSAGES_BEFORE_LOGIN=# how many messages a user can send in a conversation before having to login. set to 0 to force login right away

PUBLIC_APP_NAME=ChatUI # name used as title throughout the app
PUBLIC_APP_ASSETS=chatui # used to find logos & favicons in static/$PUBLIC_APP_ASSETS
Expand Down
4 changes: 2 additions & 2 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { COOKIE_NAME, MESSAGES_BEFORE_LOGIN } from "$env/static/private";
import { COOKIE_NAME } from "$env/static/private";
import type { Handle } from "@sveltejs/kit";
import {
PUBLIC_GOOGLE_ANALYTICS_ID,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const handle: Handle = async ({ event, resolve }) => {
!event.url.pathname.startsWith(`${base}/admin`) &&
!["GET", "OPTIONS", "HEAD"].includes(event.request.method)
) {
if (!user && requiresUser && !((parseInt(MESSAGES_BEFORE_LOGIN) || 0) > 0)) {
if (!user && requiresUser) {
return errorResponse(401, ERROR_MESSAGES.authOnly);
}

Expand Down
10 changes: 4 additions & 6 deletions src/lib/components/LoginModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
v{PUBLIC_VERSION}
</div>
</h2>
<p
class="px-4 text-lg font-semibold leading-snug text-gray-800 sm:px-12"
style="text-wrap: balance;"
>
Please Sign in with Hugging Face to continue
<p class="px-4 text-lg font-semibold leading-snug text-gray-800 sm:px-12">
This application is for demonstration purposes only.
</p>
<p class="text-base text-gray-800">
Disclaimer: AI is an area of active research with known problems such as biased generation and
AI is an area of active research with known problems such as biased generation and
misinformation. Do not use this application for high-stakes decisions or advice.
</p>
{#if PUBLIC_APP_DATA_SHARING}
Expand All @@ -57,6 +54,7 @@
with <LogoHuggingFaceBorderless classNames="text-xl mr-1 ml-1.5" /> Hugging Face
{/if}
</button>
<p class="mt-2 px-2 text-sm text-gray-500">to start chatting right away</p>
{:else}
<input type="hidden" name="ethicsModalAccepted" value={true} />
{#each Object.entries(settings) as [key, val]}
Expand Down
3 changes: 1 addition & 2 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { UrlDependency } from "$lib/types/UrlDependency";
import { defaultModel, models, oldModels, validateModel } from "$lib/server/models";
import { authCondition, requiresUser } from "$lib/server/auth";
import { DEFAULT_SETTINGS } from "$lib/types/Settings";
import { SERPAPI_KEY, SERPER_API_KEY, MESSAGES_BEFORE_LOGIN } from "$env/static/private";
import { SERPAPI_KEY, SERPER_API_KEY } from "$env/static/private";

export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
const { conversations } = collections;
Expand Down Expand Up @@ -82,6 +82,5 @@ export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
email: locals.user.email,
},
requiresLogin: requiresUser,
messagesBeforeLogin: parseInt(MESSAGES_BEFORE_LOGIN ?? 0),
};
};
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
{#if isSettingsOpen}
<SettingsModal on:close={() => (isSettingsOpen = false)} settings={data.settings} />
{/if}
{#if requiresLogin && data.messagesBeforeLogin === 0}
{#if requiresLogin}
<LoginModal settings={data.settings} />
{/if}
<slot />
Expand Down
5 changes: 0 additions & 5 deletions src/routes/conversation/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import type { WebSearchMessage } from "$lib/types/WebSearch";
import type { Message } from "$lib/types/Message";
import { browser } from "$app/environment";
import { PUBLIC_APP_DISCLAIMER } from "$env/static/public";
export let data;
Expand Down Expand Up @@ -280,8 +279,4 @@
models={data.models}
currentModel={findCurrentModel([...data.models, ...data.oldModels], data.model)}
settings={data.settings}
loginRequired={(data.requiresLogin
? !data.user
: !data.settings.ethicsModalAcceptedAt && !!PUBLIC_APP_DISCLAIMER) &&
data.messages.length > data.messagesBeforeLogin}
/>

0 comments on commit 0a662b7

Please sign in to comment.