forked from langchain-ai/opengpts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from brighthive/feat-customtools
Feat customtools
- Loading branch information
Showing
18 changed files
with
4,003 additions
and
1,495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
3 changes: 3 additions & 0 deletions
3
backend/migrations/000001_create_extensions_and_first_tables.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP TABLE IF EXISTS thread; | ||
DROP TABLE IF EXISTS assistant; | ||
DROP TABLE IF EXISTS checkpoints; |
24 changes: 24 additions & 0 deletions
24
backend/migrations/000001_create_extensions_and_first_tables.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
CREATE EXTENSION IF NOT EXISTS vector; | ||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; | ||
|
||
CREATE TABLE IF NOT EXISTS assistant ( | ||
assistant_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
user_id VARCHAR(255) NOT NULL, | ||
name VARCHAR(255) NOT NULL, | ||
config JSON NOT NULL, | ||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), | ||
public BOOLEAN NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS thread ( | ||
thread_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
assistant_id UUID REFERENCES assistant(assistant_id) ON DELETE SET NULL, | ||
user_id VARCHAR(255) NOT NULL, | ||
name VARCHAR(255) NOT NULL, | ||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS checkpoints ( | ||
thread_id TEXT PRIMARY KEY, | ||
checkpoint BYTEA | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE checkpoints | ||
DROP CONSTRAINT IF EXISTS checkpoints_pkey, | ||
ADD PRIMARY KEY (thread_id), | ||
DROP COLUMN IF EXISTS thread_ts, | ||
DROP COLUMN IF EXISTS parent_ts; |
11 changes: 11 additions & 0 deletions
11
backend/migrations/000002_checkpoints_update_schema.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ALTER TABLE checkpoints | ||
ADD COLUMN IF NOT EXISTS thread_ts TIMESTAMPTZ, | ||
ADD COLUMN IF NOT EXISTS parent_ts TIMESTAMPTZ; | ||
|
||
UPDATE checkpoints | ||
SET thread_ts = CURRENT_TIMESTAMP AT TIME ZONE 'UTC' | ||
WHERE thread_ts IS NULL; | ||
|
||
ALTER TABLE checkpoints | ||
DROP CONSTRAINT IF EXISTS checkpoints_pkey, | ||
ADD PRIMARY KEY (thread_id, thread_ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ALTER TABLE assistant | ||
DROP CONSTRAINT fk_assistant_user_id, | ||
ALTER COLUMN user_id TYPE VARCHAR USING (user_id::text); | ||
|
||
ALTER TABLE thread | ||
DROP CONSTRAINT fk_thread_user_id, | ||
ALTER COLUMN user_id TYPE VARCHAR USING (user_id::text); | ||
|
||
DROP TABLE IF EXISTS "user"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
CREATE TABLE IF NOT EXISTS "user" ( | ||
user_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
sub VARCHAR(255) UNIQUE NOT NULL, | ||
created_at TIMESTAMP WITH TIME ZONE DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') | ||
); | ||
|
||
INSERT INTO "user" (user_id, sub) | ||
SELECT DISTINCT user_id::uuid, user_id | ||
FROM assistant | ||
WHERE user_id IS NOT NULL | ||
ON CONFLICT (user_id) DO NOTHING; | ||
|
||
INSERT INTO "user" (user_id, sub) | ||
SELECT DISTINCT user_id::uuid, user_id | ||
FROM thread | ||
WHERE user_id IS NOT NULL | ||
ON CONFLICT (user_id) DO NOTHING; | ||
|
||
ALTER TABLE assistant | ||
ALTER COLUMN user_id TYPE UUID USING (user_id::UUID), | ||
ADD CONSTRAINT fk_assistant_user_id FOREIGN KEY (user_id) REFERENCES "user"(user_id); | ||
|
||
ALTER TABLE thread | ||
ALTER COLUMN user_id TYPE UUID USING (user_id::UUID), | ||
ADD CONSTRAINT fk_thread_user_id FOREIGN KEY (user_id) REFERENCES "user"(user_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE thread | ||
DROP COLUMN metadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ALTER TABLE thread | ||
ADD COLUMN metadata JSONB; | ||
|
||
UPDATE thread | ||
SET metadata = json_build_object( | ||
'assistant_type', (SELECT config->'configurable'->>'type' | ||
FROM assistant | ||
WHERE assistant.assistant_id = thread.assistant_id) | ||
); |
Oops, something went wrong.