Skip to content

Commit

Permalink
feat: schemas + migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
ketsapiwiq committed Nov 15, 2024
1 parent 0c8864d commit 746e712
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 34 deletions.
122 changes: 88 additions & 34 deletions create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,101 @@ CREATE TABLE
extra JSONB
);

-- CREATE TABLE
-- votes (
-- tstamp TIMESTAMP NOT NULL,
-- model_a_name VARCHAR(255) NOT NULL,
-- model_b_name VARCHAR(255) NOT NULL,
-- model_pair_name JSONB NOT NULL,
-- chosen_model_name VARCHAR(255),
-- both_equal BOOLEAN NOT NULL,
-- opening_prompt text NOT NULL,
-- conversation_a JSONB NOT NULL,
-- conversation_b JSONB NOT NULL,
-- turns INT,
-- selected_category VARCHAR(255),
-- is_unedited_prompt BOOLEAN,
-- template JSONB,
-- uuid VARCHAR NOT NULL,
-- ip VARCHAR(255),
-- session_hash VARCHAR(255),
-- visitor_uuid VARCHAR(255),
-- details_a_positive VARCHAR(500),
-- details_a_negative VARCHAR(500),
-- details_b_positive VARCHAR(500),
-- details_b_negative VARCHAR(500),
-- comments_a TEXT,
-- comments_b TEXT,
-- extra JSONB
-- );

CREATE TABLE
votes (
tstamp TIMESTAMP NOT NULL,
model_a_name VARCHAR(255) NOT NULL,
model_b_name VARCHAR(255) NOT NULL,
model_pair_name JSONB NOT NULL,
chosen_model_name VARCHAR(255),
both_equal BOOLEAN NOT NULL,
opening_prompt text NOT NULL,
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Timestamp of the vote
model_a_name VARCHAR(500) NOT NULL,
model_b_name VARCHAR(500) NOT NULL,
-- model_pair_name JSONB NOT NULL,
chosen_model_name VARCHAR(500),
opening_msg text NOT NULL,
-- both_equal BOOLEAN NOT NULL,
conversation_a JSONB NOT NULL,
conversation_b JSONB NOT NULL,
turns INT,
conv_turns INT,
template JSONB,
selected_category VARCHAR(255),
is_unedited_prompt BOOLEAN,
template JSONB,
uuid VARCHAR NOT NULL,
ip VARCHAR(255),
conversation_pair_id VARCHAR NOT NULL,
session_hash VARCHAR(255),
visitor_uuid VARCHAR(255),
details_a_positive VARCHAR(500),
details_a_negative VARCHAR(500),
details_b_positive VARCHAR(500),
details_b_negative VARCHAR(500),
comments_a TEXT,
comments_b TEXT,
extra JSONB
ip VARCHAR(255),
conv_comments_a TEXT,
conv_comments_b TEXT
conv_useful_a BOOLEAN,
conv_useful_b BOOLEAN,
conv_creative_a BOOLEAN,
conv_creative_b BOOLEAN,
conv_clear_formatting_a BOOLEAN,
conv_clear_formatting_b BOOLEAN,
conv_incorrect_a BOOLEAN,
conv_incorrect_b BOOLEAN,
conv_superficial_a BOOLEAN,
conv_superficial_b BOOLEAN,
conv_instructions_not_followed_a BOOLEAN,
conv_instructions_not_followed_b BOOLEAN,
);

--
-- Unused profiles table
--

-- CREATE TABLE
-- profiles (
-- tstamp TIMESTAMP NOT NULL,
-- chatbot_use VARCHAR(255),
-- gender VARCHAR(255),
-- age VARCHAR(255),
-- profession VARCHAR(255),
-- confirmed BOOLEAN,
-- session_hash VARCHAR(255),
-- visitor_uuid VARCHAR(255),
-- extra JSONB
-- );
CREATE TABLE reactions (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Timestamp of the vote
model_a_name VARCHAR(500) NOT NULL, -- Model A name
model_b_name VARCHAR(500) NOT NULL, -- Model B name
refers_to_model VARCHAR(500), -- Refers to model name (optional)
msg_rank INT, -- Message rank (optional, could be an integer or rating)
opening_msg TEXT NOT NULL, -- Opening message (prompt)
conversation_a JSONB NOT NULL, -- Conversation A (JSONB format for the conversation's messages)
conversation_b JSONB NOT NULL, -- Conversation B (JSONB format for the conversation's messages)
model_pos CHAR(1) CHECK (model_pos IN ('a', 'b')), -- Indicates the model position ('a' or 'b')
conv_turns INT NOT NULL, -- Number of turns in the conversation
template JSONB, -- Template data (JSONB format)
conversation_pair_id VARCHAR NOT NULL, -- Unique identifier for the pair of conversations
conv_a_id VARCHAR(500) NOT NULL, -- Conversation A ID
conv_b_id VARCHAR(500) NOT NULL, -- Conversation B ID
session_hash VARCHAR(255), -- Session hash (for tracking)
visitor_uuid VARCHAR(255), -- Visitor UUID (tracked user)
ip VARCHAR(255), -- IP Address (user's IP)
country VARCHAR(500), -- Country (optional, could be extracted from IP or provided)
city VARCHAR(500), -- City (optional, could be extracted from IP or provided)
response_content TEXT, -- Content of the model's response (optional)
question_content TEXT, -- Content of the question (optional)
like BOOLEAN, -- Like button (optional)
dislike BOOLEAN, -- Dislike button (optional)
comment TEXT, -- Free text comment (optional)
useful BOOLEAN, -- Is the conversation useful? (boolean)
creative BOOLEAN, -- Is the conversation creative? (boolean)
clear_formatting BOOLEAN, -- Does the conversation have clear formatting? (boolean)
incorrect BOOLEAN, -- Is the conversation incorrect? (boolean)
superficial BOOLEAN, -- Is the conversation superficial? (boolean)
instructions_not_followed BOOLEAN, -- Did the conversation not follow instructions? (boolean)
-- CONSTRAINT fk_session_hash FOREIGN KEY (session_hash) REFERENCES sessions(session_hash) -- Example for foreign key relationship if necessary
);
66 changes: 66 additions & 0 deletions migrate_15-11-2024.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
INSERT INTO votes (
timestamp,
model_a_name,
model_b_name,
chosen_model_name,
opening_msg,
conversation_a,
conversation_b,
conv_turns,
template,
selected_category,
is_unedited_prompt,
conversation_pair_id,
session_hash,
visitor_uuid,
ip,
conv_comments_a,
conv_comments_b,
-- Add any other new fields here
conv_useful_a,
conv_useful_b,
conv_creative_a,
conv_creative_b,
conv_clear_formatting_a,
conv_clear_formatting_b,
conv_incorrect_a,
conv_incorrect_b,
conv_superficial_a,
conv_superficial_b,
conv_instructions_not_followed_a,
conv_instructions_not_followed_b
)
SELECT
tstamp AS timestamp, -- Mapping `tstamp` to `timestamp`
model_a_name,
model_b_name,
chosen_model_name,
opening_prompt AS opening_msg, -- Renaming `opening_prompt` to `opening_msg`
conversation_a,
conversation_b,
turns AS conv_turns, -- Mapping `turns` to `conv_turns`
template,
selected_category,
is_unedited_prompt,
uuid AS conversation_pair_id, -- Mapping old `uuid` to `conversation_pair_id`
session_hash,
visitor_uuid,
ip,
comments_a AS conv_comments_a, -- Renaming `comments_a` to `conv_comments_a`
comments_b AS conv_comments_b, -- Renaming `comments_b` to `conv_comments_b`
-- Parsing details_a and details_b to populate boolean fields
-- For `details_a`, assuming it contains a comma-separated string of values like 'useful,creative,incorrect'
CASE WHEN details_a LIKE '%useful%' THEN TRUE ELSE FALSE END AS conv_useful_a,
CASE WHEN details_b LIKE '%useful%' THEN TRUE ELSE FALSE END AS conv_useful_b,
CASE WHEN details_a LIKE '%creative%' THEN TRUE ELSE FALSE END AS conv_creative_a,
CASE WHEN details_b LIKE '%creative%' THEN TRUE ELSE FALSE END AS conv_creative_b,
CASE WHEN details_a LIKE '%clear-formatting%' THEN TRUE ELSE FALSE END AS conv_clear_formatting_a,
CASE WHEN details_b LIKE '%clear-formatting%' THEN TRUE ELSE FALSE END AS conv_clear_formatting_b,
CASE WHEN details_a LIKE '%hallucinations%' THEN TRUE ELSE FALSE END AS conv_incorrect_a,
CASE WHEN details_b LIKE '%hallucinations%' THEN TRUE ELSE FALSE END AS conv_incorrect_b,
CASE WHEN details_a LIKE '%superficial%' THEN TRUE ELSE FALSE END AS conv_superficial_a,
CASE WHEN details_b LIKE '%superficial%' THEN TRUE ELSE FALSE END AS conv_superficial_b,
CASE WHEN details_a LIKE '%instructions-not-followed%' THEN TRUE ELSE FALSE END AS conv_instructions_not_followed_a,
CASE WHEN details_b LIKE '%instructions-not-followed%' THEN TRUE ELSE FALSE END AS conv_instructions_not_followed_b

FROM votes_old;

0 comments on commit 746e712

Please sign in to comment.