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

epic(wren-ui): Feedback & correction Loop #543

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.createTable('thread_response_explain', (table) => {
table.increments('id').comment('ID');
table
.integer('thread_response_id')
.comment('Reference to thread_response.id');
table
.foreign('thread_response_id')
.references('thread_response.id')
.onDelete('CASCADE');

table.string('query_id').nullable();
table.string('status').nullable();
table.jsonb('detail').nullable();
table.jsonb('error').nullable();
table.jsonb('analysis').nullable();

// timestamps
table.timestamps(true, true);
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.dropTable('thread_response_explain');
};
22 changes: 22 additions & 0 deletions wren-ui/migrations/20240711082655_update_thread_response_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.alterTable('thread_response', (table) => {
table
.jsonb('corrections')
.nullable()
.comment('the corrections of the previous thread response'); // [{type, id, correct}, ...]
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.alterTable('thread_response', (table) => {
table.dropColumn('corrections');
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
const threadResponses = await knex('thread_response').select('*');
if (threadResponses.length === 0) {
return;
}
const explainData = threadResponses.map((threadResponse) => {
const error = {
code: 'OLD_VERSION',
message:
'Question asked before v0.8.0. Click "Retry" to generate manually.',
};
return {
thread_response_id: threadResponse.id,
status: 'FAILED',
error: process.env.DB_TYPE === 'pg' ? error : JSON.stringify(error),
};
});

await knex('thread_response_explain').insert(explainData);
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
// remove all data
await knex('thread_response_explain').delete();
};
1 change: 1 addition & 0 deletions wren-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@typescript-eslint/parser": "6.18.0",
"ace-builds": "^1.32.3",
"antd": "4.20.4",
"clsx": "^2.1.1",
"dayjs": "^1.11.11",
"duckdb": "^0.10.1",
"duckdb-async": "^0.10.0",
Expand Down
79 changes: 79 additions & 0 deletions wren-ui/src/apollo/client/graphql/__types__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,26 @@ export type ConnectionInfo = {
username?: Maybe<Scalars['String']>;
};

export type CorrectionDetail = {
__typename?: 'CorrectionDetail';
correction: Scalars['String'];
id: Scalars['Int'];
referenceNum: Scalars['Int'];
type: ReferenceType;
};

export type CreateCalculatedFieldInput = {
expression: ExpressionName;
lineage: Array<Scalars['Int']>;
modelId: Scalars['Int'];
name: Scalars['String'];
};

export type CreateCorrectedThreadResponseInput = {
corrections: Array<CreateThreadResponseCorrectionInput>;
responseId: Scalars['Int'];
};

export type CreateModelInput = {
fields: Array<Scalars['String']>;
primaryKey?: InputMaybe<Scalars['String']>;
Expand All @@ -104,6 +117,19 @@ export type CreateThreadInput = {
viewId?: InputMaybe<Scalars['Int']>;
};

export type CreateThreadResponseCorrectionInput = {
correction: Scalars['String'];
id: Scalars['Int'];
reference: Scalars['String'];
referenceNum: Scalars['Int'];
stepIndex: Scalars['Int'];
type: ReferenceType;
};

export type CreateThreadResponseExplainWhereInput = {
responseId: Scalars['Int'];
};

export type CreateThreadResponseInput = {
question?: InputMaybe<Scalars['String']>;
sql?: InputMaybe<Scalars['String']>;
Expand Down Expand Up @@ -142,9 +168,19 @@ export enum DataSourceName {
POSTGRES = 'POSTGRES'
}

export type DetailReference = {
__typename?: 'DetailReference';
referenceId?: Maybe<Scalars['Int']>;
sqlLocation?: Maybe<ReferenceSqlLocation>;
sqlSnippet?: Maybe<Scalars['String']>;
summary: Scalars['String'];
type: ReferenceType;
};

export type DetailStep = {
__typename?: 'DetailStep';
cteName?: Maybe<Scalars['String']>;
references?: Maybe<Array<Maybe<DetailReference>>>;
sql: Scalars['String'];
summary: Scalars['String'];
};
Expand Down Expand Up @@ -324,6 +360,13 @@ export type Error = {
stacktrace?: Maybe<Array<Maybe<Scalars['String']>>>;
};

export enum ExplainTaskStatus {
FAILED = 'FAILED',
FINISHED = 'FINISHED',
GENERATING = 'GENERATING',
UNDERSTANDING = 'UNDERSTANDING'
}

export enum ExpressionName {
ABS = 'ABS',
AVG = 'AVG',
Expand Down Expand Up @@ -399,10 +442,12 @@ export type Mutation = {
cancelAskingTask: Scalars['Boolean'];
createAskingTask: Task;
createCalculatedField: Scalars['JSON'];
createCorrectedThreadResponse: ThreadResponse;
createModel: Scalars['JSON'];
createRelation: Scalars['JSON'];
createThread: Thread;
createThreadResponse: ThreadResponse;
createThreadResponseExplain: Scalars['JSON'];
createView: ViewInfo;
deleteCalculatedField: Scalars['Boolean'];
deleteModel: Scalars['Boolean'];
Expand Down Expand Up @@ -448,6 +493,12 @@ export type MutationCreateCalculatedFieldArgs = {
};


export type MutationCreateCorrectedThreadResponseArgs = {
data: CreateCorrectedThreadResponseInput;
threadId: Scalars['Int'];
};


export type MutationCreateModelArgs = {
data: CreateModelInput;
};
Expand All @@ -469,6 +520,11 @@ export type MutationCreateThreadResponseArgs = {
};


export type MutationCreateThreadResponseExplainArgs = {
where: CreateThreadResponseExplainWhereInput;
};


export type MutationCreateViewArgs = {
data: CreateViewInput;
};
Expand Down Expand Up @@ -704,6 +760,20 @@ export type RecommendRelations = {
relations: Array<Maybe<Relation>>;
};

export type ReferenceSqlLocation = {
__typename?: 'ReferenceSQLLocation';
column: Scalars['Int'];
line: Scalars['Int'];
};

export enum ReferenceType {
FIELD = 'FIELD',
FILTER = 'FILTER',
GROUP_BY = 'GROUP_BY',
QUERY_FROM = 'QUERY_FROM',
SORTING = 'SORTING'
}

export type Relation = {
__typename?: 'Relation';
fromColumnId: Scalars['Int'];
Expand Down Expand Up @@ -827,8 +897,10 @@ export type Thread = {

export type ThreadResponse = {
__typename?: 'ThreadResponse';
corrections?: Maybe<Array<CorrectionDetail>>;
detail?: Maybe<ThreadResponseDetail>;
error?: Maybe<Error>;
explain?: Maybe<ThreadResponseExplainInfo>;
id: Scalars['Int'];
question: Scalars['String'];
status: AskingTaskStatus;
Expand All @@ -843,6 +915,13 @@ export type ThreadResponseDetail = {
view?: Maybe<ViewInfo>;
};

export type ThreadResponseExplainInfo = {
__typename?: 'ThreadResponseExplainInfo';
error?: Maybe<Scalars['JSON']>;
queryId?: Maybe<Scalars['String']>;
status?: Maybe<ExplainTaskStatus>;
};

export type ThreadUniqueWhereInput = {
id: Scalars['Int'];
};
Expand Down
Loading
Loading