Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test New LLMs (Llama2, CodeLlama, etc.) on Chat-UI? #1

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
df5a2eb
Fix typo in Settings.ts (#286)
eltociear Jun 9, 2023
abe7804
Fixed grammar (#291)
CAPTAIN320 Jun 13, 2023
5d07536
Added ChatUI branding & put theming behind an env variable (#298)
nsarrazin Jun 16, 2023
0dace21
➕ Update README.md to Include endpoints Variable (#288)
averad Jun 19, 2023
f567f41
Fix code example preview (#300)
arifszn Jun 19, 2023
e34af36
Fix README linting & add details about auth
nsarrazin Jun 19, 2023
7457e8c
add a readme section about theming
nsarrazin Jun 20, 2023
6f7b315
Added Serper.dev API as an alternative web search provider (#302)
rogerserper Jun 20, 2023
b46dc11
add details about websearch to README
nsarrazin Jun 20, 2023
922b1b2
very basic rate limiter (#320)
nsarrazin Jun 23, 2023
0aa57de
Add support for websearch retries (#318)
nsarrazin Jun 26, 2023
fb55900
loader dots fix
gary149 Jul 6, 2023
3baa389
feat: factor out HF_API_ROOT to allow different inference endpoints (…
DayOfThePenguin Jul 11, 2023
10d1ab5
Add support for HF summarization endpoint in the websearch (#319)
nsarrazin Jul 11, 2023
1eff97d
Add optional timestamps to messages (#294)
nsarrazin Jul 12, 2023
ce2231f
Add ability to define custom model/dataset URLs (#347)
secondtruth Jul 17, 2023
b3411af
Added Docker Space deployment docs (#350)
merveenoyan Jul 18, 2023
a38cbb5
bump version to 0.4 (#353)
nsarrazin Jul 19, 2023
479dbfa
Update README.md (#354)
merveenoyan Jul 19, 2023
6183fe7
Option to disable login on first N messages (#352)
nsarrazin Jul 19, 2023
0a662b7
Revert "Option to disable login on first N messages (#352)"
gary149 Jul 19, 2023
7767757
support rate limiting based on user IP (#342)
nsarrazin Jul 20, 2023
7c4fdc9
Reopen: Feature/disable login for n messages (#356)
gary149 Jul 20, 2023
ac291a6
Revert "support rate limiting based on user IP (#342)"
nsarrazin Jul 20, 2023
569bde3
Update README.md (#359)
osanseviero Jul 20, 2023
a935f0a
Added access token note (#360)
merveenoyan Jul 28, 2023
7dd8724
Update /privacy and other content following Llama v2 release (#374)
julien-c Jul 28, 2023
19db9db
Clarify that model 'tokens' are not actual tokens (#367)
AndreasMadsen Jul 28, 2023
932ee7e
Attempt to clarify how hosted API ≠ local endpoint (#373)
julien-c Jul 28, 2023
54e8a52
Make model branding customizable based on env var (#345)
flozi00 Aug 1, 2023
d2a650e
trim and remove stop-suffixes from summary (#369)
AndreasMadsen Aug 2, 2023
8fa7bd9
add a login button when users are logged out (#381)
nsarrazin Aug 2, 2023
f209301
allow different user and assistant end-token (#375)
AndreasMadsen Aug 2, 2023
0ad340e
Leverage model link to modelUrl when informed (#385)
airibarne Aug 3, 2023
49caedf
Update README.md
krrishdholakia Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reopen: Feature/disable login for n messages (huggingface#356)
* disable login on first message

* update banner here too

* modal wording tweaks

* prevent NaN

* fix login wall

* fix flicker

* lint

* put modal text behind login check

* fix bug with sending messages without login

* fix misalignment between ui and api

* fix data update on disable login

---------

Co-authored-by: Nathan Sarrazin <[email protected]>
  • Loading branch information
gary149 and nsarrazin authored Jul 20, 2023
commit 7c4fdc9a373425acfeb9e347ceae46c5ea272927
9 changes: 5 additions & 4 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": "Chat UI is now open sourced on GitHub",
"linkTitle": "GitHub repo",
"linkHref": "https://github.com/huggingface/chat-ui"
{
"title": "Llama v2 is live on HuggingChat! 🦙",
"linkTitle": "Announcement",
"linkHref": "https://huggingface.co/blog/llama2"
}
]`

Expand All @@ -72,6 +72,7 @@ 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
8 changes: 6 additions & 2 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { COOKIE_NAME } from "$env/static/private";
import { COOKIE_NAME, MESSAGES_BEFORE_LOGIN } from "$env/static/private";
import type { Handle } from "@sveltejs/kit";
import {
PUBLIC_GOOGLE_ANALYTICS_ID,
Expand Down Expand Up @@ -64,7 +64,11 @@ export const handle: Handle = async ({ event, resolve }) => {
!event.url.pathname.startsWith(`${base}/admin`) &&
!["GET", "OPTIONS", "HEAD"].includes(event.request.method)
) {
if (!user && requiresUser) {
if (
!user &&
requiresUser &&
!((MESSAGES_BEFORE_LOGIN ? parseInt(MESSAGES_BEFORE_LOGIN) : 0) > 0)
) {
return errorResponse(401, ERROR_MESSAGES.authOnly);
}

Expand Down
14 changes: 9 additions & 5 deletions src/lib/components/LoginModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@
v{PUBLIC_VERSION}
</div>
</h2>
<p class="px-4 text-lg font-semibold leading-snug text-gray-800 sm:px-12">
This application is for demonstration purposes only.
</p>
{#if $page.data.requiresLogin}
<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>
{/if}
<p class="text-base text-gray-800">
AI is an area of active research with known problems such as biased generation and
Disclaimer: 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 @@ -54,7 +59,6 @@
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: 2 additions & 1 deletion 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 } from "$env/static/private";
import { SERPAPI_KEY, SERPER_API_KEY, MESSAGES_BEFORE_LOGIN } from "$env/static/private";

export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
const { conversations } = collections;
Expand Down Expand Up @@ -82,5 +82,6 @@ export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
email: locals.user.email,
},
requiresLogin: requiresUser,
messagesBeforeLogin: MESSAGES_BEFORE_LOGIN ? 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}
{#if requiresLogin && data.messagesBeforeLogin === 0}
<LoginModal settings={data.settings} />
{/if}
<slot />
Expand Down
11 changes: 9 additions & 2 deletions src/routes/conversation/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { webSearchParameters } from "$lib/stores/webSearchParameters";
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 All @@ -33,6 +33,7 @@

let loading = false;
let pending = false;
let loginRequired = false;

async function getTextGenerationStream(
inputs: string,
Expand Down Expand Up @@ -195,7 +196,6 @@
await getTextGenerationStream(message, messageId, isRetry, searchResponseId ?? undefined);

webSearchMessages = [];
if (browser) invalidate(UrlDependency.Conversation);

if (messages.filter((m) => m.from === "user").length === 1) {
summarizeTitle($page.params.id)
Expand Down Expand Up @@ -259,6 +259,12 @@
});
$: $page.params.id, (isAborted = true);
$: title = data.conversations.find((conv) => conv.id === $page.params.id)?.title ?? data.title;

$: loginRequired =
(data.requiresLogin
? !data.user
: !data.settings.ethicsModalAcceptedAt && !!PUBLIC_APP_DISCLAIMER) &&
messages.length >= data.messagesBeforeLogin;
</script>

<svelte:head>
Expand All @@ -279,4 +285,5 @@
models={data.models}
currentModel={findCurrentModel([...data.models, ...data.oldModels], data.model)}
settings={data.settings}
{loginRequired}
/>
12 changes: 10 additions & 2 deletions src/routes/conversation/[id]/+server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RATE_LIMIT } from "$env/static/private";
import { MESSAGES_BEFORE_LOGIN, RATE_LIMIT } from "$env/static/private";
import { buildPrompt } from "$lib/buildPrompt";
import { PUBLIC_SEP_TOKEN } from "$lib/constants/publicSepToken";
import { abortedGenerations } from "$lib/server/abortedGenerations";
import { authCondition } from "$lib/server/auth";
import { authCondition, requiresUser } from "$lib/server/auth";
import { collections } from "$lib/server/database";
import { modelEndpoint } from "$lib/server/modelEndpoint";
import { models } from "$lib/server/models";
Expand Down Expand Up @@ -37,6 +37,14 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
throw error(404, "Conversation not found");
}

if (
!locals.user?._id &&
requiresUser &&
conv.messages.length > (MESSAGES_BEFORE_LOGIN ? parseInt(MESSAGES_BEFORE_LOGIN) : 0)
) {
throw error(429, "Exceeded number of messages before login");
}

if (RATE_LIMIT !== "") {
let nEvents = 0;
if (locals.user?._id) {
Expand Down