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

feat(ui): Utilize OpenAI for backend #553

Merged
merged 131 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from 127 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
d3fbc32
add ui-test workflow
jalling97 Apr 24, 2024
8939555
add npm prefix
jalling97 Apr 24, 2024
d311db7
add trufflehog scans to workflows
jalling97 Apr 25, 2024
8d0bb03
Merge remote-tracking branch 'origin/main' into 407-ci-create-test-wo…
jalling97 Apr 25, 2024
488b65f
add UI linter to github workflows
jalling97 Apr 25, 2024
a62b4a8
add eslint to pre-commit
jalling97 Apr 25, 2024
bbfa0d4
fix: prettier and eslint issues
andrewrisse Apr 25, 2024
0f0cab6
add prettier to pre-commit
jalling97 Apr 26, 2024
4fc87ea
fix wording mistake
jalling97 Apr 26, 2024
03cdee8
change to npm ci vs install
jalling97 Apr 26, 2024
7021fcf
convert prettier to eslint plugin
jalling97 Apr 26, 2024
0b21f9c
update package.json and package-lock.json
jalling97 Apr 26, 2024
48c284e
merge in main and sync eslint between pre-commit and npm script
jalling97 Apr 29, 2024
0a42e8d
pin setup node actions version
jalling97 Apr 29, 2024
60a8e3b
Merge remote-tracking branch 'origin/main' into 407-ci-create-test-wo…
jalling97 Apr 29, 2024
228efdb
linting fixes
jalling97 Apr 29, 2024
2a0ac2d
fix: frontend eslint issues
andrewrisse Apr 29, 2024
02c3087
pin node version in package.json
jalling97 Apr 29, 2024
233537f
remove pre-commit comments
jalling97 Apr 29, 2024
beb9362
fix: merge conflicts, minor test update
andrewrisse Apr 30, 2024
bdb21f5
exclude .pre-commit-config.yaml from e2e workflow
jalling97 Apr 30, 2024
443e57c
catch .pre-commit-config.yaml in e2e-shim workflow
jalling97 Apr 30, 2024
81e8041
add ui-test-shim
jalling97 Apr 30, 2024
0ef7cc3
remove redundancy in secret-scan github action
jalling97 Apr 30, 2024
f5337cb
init - merge workflow branch and re-delete extra package-lock.json
andrewrisse Apr 30, 2024
7a4f26a
chore: refactor layouts and add layout for assistants page
andrewrisse Apr 30, 2024
ad0930d
wip: add initial tests and dynamic breadcrumbs
andrewrisse Apr 30, 2024
6770d81
change prettier
andrewrisse May 1, 2024
cfe43ec
chore: merge main and reformat
andrewrisse May 1, 2024
887f638
wip: add custom tooltip text input component
andrewrisse May 1, 2024
29321a5
fix: layout setup so footer can be on multiple pages
andrewrisse May 1, 2024
314d7c3
wip: add form
andrewrisse May 1, 2024
74796df
wip: add form 2
andrewrisse May 1, 2024
690a916
wip: form using svelte-forms-lib
andrewrisse May 1, 2024
47cf8bf
feat: assistants management page and create assistant
andrewrisse May 3, 2024
b63a934
feat: assistants management page and create assistant
andrewrisse May 3, 2024
241e907
Merge branch 'main' into 428-featui-assistants-management
andrewrisse May 3, 2024
d968ad8
fix: supabase secret naming
andrewrisse May 3, 2024
7a8e46c
fix: style when over 5 rows of card, causes slight page scroll
andrewrisse May 3, 2024
7fd0613
fix: footer styling
andrewrisse May 3, 2024
9acbfc1
fix: tooltip text
andrewrisse May 3, 2024
259e779
init
andrewrisse May 6, 2024
18e28ec
wip
andrewrisse May 6, 2024
f82cb8f
wip, use form action for avatar upload and assistant creation
andrewrisse May 7, 2024
34879ad
wip, pictograms
andrewrisse May 7, 2024
526e39b
pictograms working
andrewrisse May 8, 2024
31987aa
fix: mini avatar when pictogram
andrewrisse May 8, 2024
705bb53
lint
andrewrisse May 8, 2024
243c2ea
wip: design fixes
andrewrisse May 8, 2024
a578619
save validation
andrewrisse May 8, 2024
726e73c
fix: lots of ui style fixes and logic updates
andrewrisse May 8, 2024
49a000f
fix: validation
andrewrisse May 8, 2024
cd91ca6
chore: remove svelte forms lib, submit form normally
andrewrisse May 9, 2024
f544b62
fix: background color for avatar on assistant tile, add initial playw…
andrewrisse May 9, 2024
3565d29
e2es
andrewrisse May 9, 2024
1eef750
tests and formatting
andrewrisse May 10, 2024
9bf036e
fix: reduce number of icons for performance
andrewrisse May 10, 2024
25efa0a
fix: remove top dir node modules
andrewrisse May 10, 2024
2b8ec69
fix: add 'local-registry' target as dependency to 'build-ui'
YrrepNoj May 10, 2024
df3563a
chore: refactor package name from 'lfaiui' to 'leapfrogai-ui'
YrrepNoj May 10, 2024
de56fe1
chore: update default UI hostname from 'lfaiui' to 'ai'
YrrepNoj May 10, 2024
c2d7ba3
chore: update example keycloak_client_id
YrrepNoj May 10, 2024
a8fb7dc
fix: update default model for CPU bundles to not use a GPU model
YrrepNoj May 10, 2024
75b19ca
chore: merge main
andrewrisse May 10, 2024
40f486d
fix: add deleted supabase top level dir back in, minor code style upd…
andrewrisse May 10, 2024
0752c67
fix: lfaiui naming conventions
andrewrisse May 10, 2024
2d0cde2
fix: lfaiui naming conventions 2
andrewrisse May 10, 2024
c2eb836
fix: lfaiui naming conventions 3
andrewrisse May 10, 2024
613348e
fix: chat input box
andrewrisse May 10, 2024
d6529fc
fix: upload bug
andrewrisse May 10, 2024
362a314
fix: update subdomain and domain settings for UI deployment
YrrepNoj May 10, 2024
02933f5
Merge branch 'misc-ui-package-configuration-updates' into 434-edit-as…
andrewrisse May 10, 2024
8f6682d
fix: merge changes missed
andrewrisse May 10, 2024
43736fc
fix: remove comment
andrewrisse May 10, 2024
b64d7d5
chore: update keycloak client name
andrewrisse May 10, 2024
337087b
chore: merge main
andrewrisse May 10, 2024
e234333
fix: remove unused api route
andrewrisse May 10, 2024
d2204d8
chore: block save button during submit
andrewrisse May 10, 2024
383f7aa
Merge branch 'main' into 434-edit-assistant
andrewrisse May 10, 2024
6c9f669
chore: update ui migrations
andrewrisse May 10, 2024
bd6ab8f
fix: migrations in one file, lowercase assistants
andrewrisse May 13, 2024
254c344
fix: migrations in one file, lowercase assistants 2
andrewrisse May 13, 2024
9ec2b14
chore: remove rls rule for avatar storage
andrewrisse May 13, 2024
487562f
fix: Formatting for migrations file
andrewrisse May 13, 2024
fbf2ac8
fix: copy migrations to parent dir
andrewrisse May 13, 2024
2fd5841
init
andrewrisse May 13, 2024
b3adf86
chore: use sveltekit superforms and add form action tests
andrewrisse May 13, 2024
b181fd2
wip: update asssitants, remove assistants store
andrewrisse May 14, 2024
4c0c389
wip: remove debugger
andrewrisse May 14, 2024
d823175
wip: add overflow menu buttons and delete capability
andrewrisse May 14, 2024
218c3e7
feat: add cancel modal only when changes and navigating away)
andrewrisse May 14, 2024
a2a90af
chore: throw error if assistant not found
andrewrisse May 14, 2024
2d3006c
chore: merge main
andrewrisse May 14, 2024
b51af03
tests wip
andrewrisse May 14, 2024
1581a53
finish tests, fix chat input styling
andrewrisse May 14, 2024
b90dba6
feat: edit and delete assistants
andrewrisse May 14, 2024
574b1b1
fix: cancel modal
andrewrisse May 14, 2024
175cbc2
fix: cache control for image update
andrewrisse May 14, 2024
164f8d0
fix: typo in package.json script
andrewrisse May 15, 2024
94bf8fd
fix: card width override, prod bug only
andrewrisse May 15, 2024
5740024
fix: card width override, prod bug only 2
andrewrisse May 15, 2024
a37a976
fix: card width override, prod bug only 3
andrewrisse May 15, 2024
1ca3822
Fix assistant tile text cutoff
andrewrisse May 15, 2024
3640e45
fix: assistant tile text sizing bug
andrewrisse May 15, 2024
9186119
fix: remove avatar bug, schema alias, turn off autocomplete
andrewrisse May 15, 2024
c7bdd6f
fix: lint
andrewrisse May 15, 2024
d2cde79
init
andrewrisse May 16, 2024
ecb9bde
feat: threads and messages working with openai
andrewrisse May 16, 2024
2160778
wip: schemas
andrewrisse May 17, 2024
6e4b040
fix: thread import
andrewrisse May 17, 2024
69aba0f
wip: add assistants
andrewrisse May 20, 2024
a1acb36
Fix: avatar logic
andrewrisse May 20, 2024
37f8257
fix: chat responses
andrewrisse May 20, 2024
1b48b27
fix: chat sidebar tests
andrewrisse May 20, 2024
4857e5c
wip: all unit tests passing
andrewrisse May 21, 2024
786a0e6
wip: working on e2es
andrewrisse May 21, 2024
2f1e2d2
lint and tests
andrewrisse May 22, 2024
0d7a6f0
fix: assistant tests
andrewrisse May 22, 2024
f3cfa8e
fix: add migrations to supabase package
andrewrisse May 22, 2024
bf064be
fix: add back in playwright browsers
andrewrisse May 22, 2024
f92dba0
merge main
andrewrisse May 22, 2024
0c41844
remove unused mocks
andrewrisse May 22, 2024
1733ea5
fix: remove console log
andrewrisse May 22, 2024
c9a3504
Fix: drop tables order
andrewrisse May 22, 2024
62f8f8e
fix: lint
andrewrisse May 22, 2024
8f62664
fix: breadcrumb link when on edit assistant route
andrewrisse May 22, 2024
27ff335
fix: migration to drop tables only if exists
andrewrisse May 23, 2024
4a784c3
fix: update migration to include new trigger
andrewrisse May 23, 2024
9aabb7e
fix: remove unnecessary exception handling
andrewrisse May 24, 2024
3a51c45
chore: add import alias, change console.log to console.error
andrewrisse May 24, 2024
29e7556
chore: change more console.log to console.error, add alias import
andrewrisse May 24, 2024
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
115 changes: 23 additions & 92 deletions packages/supabase/migrations/20240322174521_ui_sql_schema.sql
Original file line number Diff line number Diff line change
@@ -1,120 +1,51 @@
-- Create tables
create table conversations (
id uuid primary key DEFAULT uuid_generate_v4(),
user_id uuid references auth.users not null,
label text,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);

create table messages (
id uuid primary key DEFAULT uuid_generate_v4(),
user_id uuid references auth.users not null,
conversation_id uuid references conversations on delete cascade not null,
role text check (role in ('system', 'user', 'assistant', 'function', 'data', 'tool')),
content text,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
-- Tables
create table public.profiles (
id uuid references auth.users not null primary key,
full_name text,
thread_ids text array DEFAULT '{}'
);


create table profiles (
id uuid references auth.users not null primary key,
updated_at timestamp with time zone,
username text unique,
full_name text,
avatar_url text,
website text,
constraint username_length check (char_length(username) >= 3)
);

create table assistants (
id uuid primary key DEFAULT uuid_generate_v4(),
object text check (object in ('assistant')),
name varchar(255),
description varchar(512),
model varchar(255) not null,
instructions TEXT,
tools jsonb,
tool_resources jsonb,
metadata jsonb,
temperature float,
top_p float,
response_format jsonb,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);

-- Set up Storage!
-- Storage
insert into storage.buckets
(id, name, public)
values
('assistant_avatars', 'assistant_avatars', true);

-- These are user profiles avatars, currently not used by app and will be removed soon
insert into storage.buckets (id, name)
values ('avatars', 'avatars');

-- RLS policies
alter table conversations enable row level security;
alter table messages enable row level security;
alter table profiles enable row level security;
alter table assistants enable row level security;

-- Policies for conversations
create policy "Individuals can create conversations." on conversations for
insert with check (auth.uid() = user_id);
create policy "Individuals can view their own conversations. " on conversations for
select using (auth.uid() = user_id);
create policy "Individuals can update their own conversations." on conversations for
update using (auth.uid() = user_id);
create policy "Individuals can delete their own conversations." on conversations for
delete using (auth.uid() = user_id);
alter table public.profiles enable row level security;

-- Policies for messages
create policy "Individuals can view their own messages." on messages for
select using (auth.uid() = user_id);
create policy "Individuals can create messages." on messages for
insert with check (auth.uid() = user_id);
create policy "Individuals can update their own messages." on messages for
update using (auth.uid() = user_id);
create policy "Individuals can delete their own messages." on messages for
delete using (auth.uid() = user_id);

-- Policies for profiles
create policy "Public profiles are viewable by everyone." on profiles
for select using (true);
create policy "Users can view their own profiles" on profiles
for select using (auth.uid() = id);
create policy "Users can insert their own profile." on profiles
for insert with check (auth.uid() = id);
for insert with check (auth.uid() = id);
create policy "Users can update own profile." on profiles
for update using (auth.uid() = id);
for update using (auth.uid() = id);

-- Policies for assistants
create policy "Individuals can view their own assistants." ON assistants
for select using ((metadata ->> 'created_by') = auth.uid()::text);
create policy "Individuals can create assistants." on assistants for
insert with check ((metadata ->> 'created_by') = auth.uid()::text);
create policy "Individuals can update their own assistants." on assistants for
update using ((metadata ->> 'created_by') = auth.uid()::text);
create policy "Individuals can delete their own assistants." on assistants for
delete using ((metadata ->> 'created_by') = auth.uid()::text);

-- Policies for storage.
create policy "Avatar images are publicly accessible." on storage.objects
for select using (bucket_id = 'avatars');
create policy "Anyone can upload an avatar." on storage.objects
for insert with check (bucket_id = 'avatars');
create policy "Anyone can update their own avatar." on storage.objects
for update using (auth.uid() = owner) with check (bucket_id = 'avatars');
-- Policies for storage

create policy "Assistant Avatar images are publicly accessible." on storage.objects
for select using (bucket_id = 'assistant_avatars');
create policy "Anyone can upload an assistant avatar." on storage.objects
for insert with check (bucket_id = 'assistant_avatars');
for insert with check (bucket_id = 'assistant_avatars');
create policy "Anyone can update their own assistant avatars." on storage.objects
for update using (auth.uid() = owner) with check (bucket_id = 'assistant_avatars');


-- Triggers

-- This trigger automatically creates a profile entry when a new user signs up via Supabase Auth.
-- See https://supabase.com/docs/guides/auth/managing-user-data#using-triggers for more details.
create function public.handle_new_user()
returns trigger as $$
begin
insert into public.profiles (id, full_name, avatar_url)
values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
return new;
insert into public.profiles (id, full_name)
values (new.id, new.raw_user_meta_data->>'full_name');
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- First, rename the existing table to keep a backup
ALTER TABLE profiles RENAME TO profiles_old;

-- Create the new table with the required structure
CREATE TABLE public.profiles (
id uuid REFERENCES auth.users NOT NULL PRIMARY KEY,
full_name text,
thread_ids text[] DEFAULT '{}'
);

-- Insert data from the old table to the new one (only the required columns)
INSERT INTO public.profiles (id, full_name)
SELECT id, full_name
FROM profiles_old;

-- Drop the old table if the data transfer is successful
-- DROP TABLE profiles_old;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DO $$
BEGIN
BEGIN
DROP TABLE IF EXISTS messages;
EXCEPTION
WHEN others THEN
-- do nothing, fail silently
END;

BEGIN
DROP TABLE IF EXISTS conversations;
EXCEPTION
WHEN others THEN
-- do nothing, fail silently
andrewrisse marked this conversation as resolved.
Show resolved Hide resolved
END;
END $$;
10 changes: 10 additions & 0 deletions src/leapfrogai_ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,13 @@ To get the MFA secret, create your new Keycloak user with the normal Keycloak lo
When scanning the QR code, use an app that lets you see the url of the QR code. The secret is contained in that URL.

Login flow was adapted from [this reference](https://supabase.com/docs/guides/getting-started/tutorials/with-sveltekit?database-method=sql)

### Using OpenAI

You can use OpenAI instead of Leapfrog API by changing these environment variables:

```
DEFAULT_MODEL=gpt-3.5-turbo
LEAPFROGAI_API_BASE_URL=https://api.openai.com/v1
LEAPFROGAI_API_KEY=<your-openai-api-key>
```
Loading