From e7c47bfaddd019693427c861fe70fca6c833f43a Mon Sep 17 00:00:00 2001 From: "wren-ai[bot]" Date: Thu, 26 Dec 2024 06:20:43 +0000 Subject: [PATCH 1/7] Upgrade AI Service version to 0.13.8 --- wren-ai-service/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wren-ai-service/pyproject.toml b/wren-ai-service/pyproject.toml index 4dd1c75ff..411762941 100644 --- a/wren-ai-service/pyproject.toml +++ b/wren-ai-service/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "wren-ai-service" -version = "0.13.7" +version = "0.13.8" description = "" authors = ["Jimmy Yeh ", "Pao Sheng Wang ", "Aster Sun "] license = "AGPL-3.0" From ce4529c7d453d2fdd276d8b0d38b71968fd7f326 Mon Sep 17 00:00:00 2001 From: Freda Lai <42527625+fredalai@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:23:31 +0800 Subject: [PATCH 2/7] feat(wren-ui): remove unnecessary sql column of thread table (#1063) --- .../20241226135712_remove_thread_sql.js | 26 +++++++++++++++++++ .../src/apollo/client/graphql/__types__.ts | 4 --- .../apollo/client/graphql/home.generated.ts | 9 +++---- wren-ui/src/apollo/client/graphql/home.ts | 3 --- .../server/repositories/threadRepository.ts | 1 - wren-ui/src/apollo/server/schema.ts | 8 ------ .../apollo/server/services/askingService.ts | 3 --- 7 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 wren-ui/migrations/20241226135712_remove_thread_sql.js diff --git a/wren-ui/migrations/20241226135712_remove_thread_sql.js b/wren-ui/migrations/20241226135712_remove_thread_sql.js new file mode 100644 index 000000000..cf453b326 --- /dev/null +++ b/wren-ui/migrations/20241226135712_remove_thread_sql.js @@ -0,0 +1,26 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = async function (knex) { + // drop foreign key constraint before altering column type to prevent data loss + await knex.schema.alterTable('thread_response', (table) => { + table.dropForeign('thread_id'); + }); + await knex.schema.alterTable('thread', (table) => { + table.dropColumn('sql'); + }); + await knex.schema.alterTable('thread_response', (table) => { + table.foreign('thread_id').references('thread.id').onDelete('CASCADE'); + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = async function (knex) { + await knex.schema.alterTable('thread', (table) => { + table.text('sql').nullable(); + }); +}; diff --git a/wren-ui/src/apollo/client/graphql/__types__.ts b/wren-ui/src/apollo/client/graphql/__types__.ts index 3e41e03d4..412aa82af 100644 --- a/wren-ui/src/apollo/client/graphql/__types__.ts +++ b/wren-ui/src/apollo/client/graphql/__types__.ts @@ -257,8 +257,6 @@ export type DetailedThread = { __typename?: 'DetailedThread'; id: Scalars['Int']; responses: Array; - /** @deprecated Doesn't seem to be reasonable to put a sql in a thread */ - sql: Scalars['String']; }; export type Diagram = { @@ -997,8 +995,6 @@ export type Task = { export type Thread = { __typename?: 'Thread'; id: Scalars['Int']; - /** @deprecated Doesn't seem to be reasonable to put a sql in a thread */ - sql: Scalars['String']; summary: Scalars['String']; }; diff --git a/wren-ui/src/apollo/client/graphql/home.generated.ts b/wren-ui/src/apollo/client/graphql/home.generated.ts index ec71b81eb..fec180e44 100644 --- a/wren-ui/src/apollo/client/graphql/home.generated.ts +++ b/wren-ui/src/apollo/client/graphql/home.generated.ts @@ -37,7 +37,7 @@ export type ThreadQueryVariables = Types.Exact<{ }>; -export type ThreadQuery = { __typename?: 'Query', thread: { __typename?: 'DetailedThread', id: number, sql: string, responses: Array<{ __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null }> } }; +export type ThreadQuery = { __typename?: 'Query', thread: { __typename?: 'DetailedThread', id: number, responses: Array<{ __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null }> } }; export type ThreadResponseQueryVariables = Types.Exact<{ responseId: Types.Scalars['Int']; @@ -65,7 +65,7 @@ export type CreateThreadMutationVariables = Types.Exact<{ }>; -export type CreateThreadMutation = { __typename?: 'Mutation', createThread: { __typename?: 'Thread', id: number, sql: string } }; +export type CreateThreadMutation = { __typename?: 'Mutation', createThread: { __typename?: 'Thread', id: number } }; export type CreateThreadResponseMutationVariables = Types.Exact<{ threadId: Types.Scalars['Int']; @@ -81,7 +81,7 @@ export type UpdateThreadMutationVariables = Types.Exact<{ }>; -export type UpdateThreadMutation = { __typename?: 'Mutation', updateThread: { __typename?: 'Thread', id: number, sql: string, summary: string } }; +export type UpdateThreadMutation = { __typename?: 'Mutation', updateThread: { __typename?: 'Thread', id: number, summary: string } }; export type DeleteThreadMutationVariables = Types.Exact<{ where: Types.ThreadUniqueWhereInput; @@ -386,7 +386,6 @@ export const ThreadDocument = gql` query Thread($threadId: Int!) { thread(threadId: $threadId) { id - sql responses { ...CommonResponse } @@ -524,7 +523,6 @@ export const CreateThreadDocument = gql` mutation CreateThread($data: CreateThreadInput!) { createThread(data: $data) { id - sql } } `; @@ -592,7 +590,6 @@ export const UpdateThreadDocument = gql` mutation UpdateThread($where: ThreadUniqueWhereInput!, $data: UpdateThreadInput!) { updateThread(where: $where, data: $data) { id - sql summary } } diff --git a/wren-ui/src/apollo/client/graphql/home.ts b/wren-ui/src/apollo/client/graphql/home.ts index 53236c489..f6b12c1ad 100644 --- a/wren-ui/src/apollo/client/graphql/home.ts +++ b/wren-ui/src/apollo/client/graphql/home.ts @@ -144,7 +144,6 @@ export const THREAD = gql` query Thread($threadId: Int!) { thread(threadId: $threadId) { id - sql responses { ...CommonResponse } @@ -180,7 +179,6 @@ export const CREATE_THREAD = gql` mutation CreateThread($data: CreateThreadInput!) { createThread(data: $data) { id - sql } } `; @@ -204,7 +202,6 @@ export const UPDATE_THREAD = gql` ) { updateThread(where: $where, data: $data) { id - sql summary } } diff --git a/wren-ui/src/apollo/server/repositories/threadRepository.ts b/wren-ui/src/apollo/server/repositories/threadRepository.ts index 2a243be54..647c2a4a3 100644 --- a/wren-ui/src/apollo/server/repositories/threadRepository.ts +++ b/wren-ui/src/apollo/server/repositories/threadRepository.ts @@ -17,7 +17,6 @@ export interface ThreadRecommendationQuestionResult { export interface Thread { id: number; // ID projectId: number; // Reference to project.id - sql: string; // SQL summary: string; // Thread summary // recommend question diff --git a/wren-ui/src/apollo/server/schema.ts b/wren-ui/src/apollo/server/schema.ts index 167633d34..970680712 100644 --- a/wren-ui/src/apollo/server/schema.ts +++ b/wren-ui/src/apollo/server/schema.ts @@ -700,20 +700,12 @@ export const typeDefs = gql` # Thread only consists of basic information of a thread type Thread { id: Int! - sql: String! - @deprecated( - reason: "Doesn't seem to be reasonable to put a sql in a thread" - ) summary: String! } # Detailed thread consists of thread and thread responses type DetailedThread { id: Int! - sql: String! - @deprecated( - reason: "Doesn't seem to be reasonable to put a sql in a thread" - ) responses: [ThreadResponse!]! } diff --git a/wren-ui/src/apollo/server/services/askingService.ts b/wren-ui/src/apollo/server/services/askingService.ts index 6ace876ee..f6982649c 100644 --- a/wren-ui/src/apollo/server/services/askingService.ts +++ b/wren-ui/src/apollo/server/services/askingService.ts @@ -575,7 +575,6 @@ export class AskingService implements IAskingService { const { id } = await this.projectService.getCurrentProject(); const thread = await this.threadRepository.createOne({ projectId: id, - sql: input.sql, summary: input.question, }); @@ -969,8 +968,6 @@ export class AskingService implements IAskingService { const { id } = await this.projectService.getCurrentProject(); const thread = await this.threadRepository.createOne({ projectId: id, - // todo: remove sql from thread - sql: view.statement, summary: input.question, }); From 0e4b53ee8807c172b4ff0b2bf1173b62774b52f3 Mon Sep 17 00:00:00 2001 From: Shimin Date: Thu, 26 Dec 2024 14:43:23 +0800 Subject: [PATCH 3/7] fix(wren-ui): remove custom scale & add adjustment flag for adjust chart scenario (#1062) --- .../src/apollo/client/graphql/__types__.ts | 1 + .../apollo/client/graphql/home.generated.ts | 19 +++--- wren-ui/src/apollo/client/graphql/home.ts | 1 + .../src/apollo/server/backgrounds/chart.ts | 1 + .../repositories/threadResponseRepository.ts | 1 + wren-ui/src/apollo/server/schema.ts | 1 + .../apollo/server/services/askingService.ts | 1 + wren-ui/src/components/chart/handler.ts | 60 ------------------- .../pages/home/promptThread/ChartAnswer.tsx | 22 ++++--- wren-ui/src/styles/components/chart.less | 6 +- 10 files changed, 35 insertions(+), 78 deletions(-) diff --git a/wren-ui/src/apollo/client/graphql/__types__.ts b/wren-ui/src/apollo/client/graphql/__types__.ts index 412aa82af..c411e7097 100644 --- a/wren-ui/src/apollo/client/graphql/__types__.ts +++ b/wren-ui/src/apollo/client/graphql/__types__.ts @@ -1040,6 +1040,7 @@ export type ThreadResponseBreakdownDetail = { export type ThreadResponseChartDetail = { __typename?: 'ThreadResponseChartDetail'; + adjustment?: Maybe; chartSchema?: Maybe; description?: Maybe; error?: Maybe; diff --git a/wren-ui/src/apollo/client/graphql/home.generated.ts b/wren-ui/src/apollo/client/graphql/home.generated.ts index fec180e44..1380c96e3 100644 --- a/wren-ui/src/apollo/client/graphql/home.generated.ts +++ b/wren-ui/src/apollo/client/graphql/home.generated.ts @@ -9,9 +9,9 @@ export type CommonBreakdownDetailFragment = { __typename?: 'ThreadResponseBreakd export type CommonAnswerDetailFragment = { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null }; -export type CommonChartDetailFragment = { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null }; +export type CommonChartDetailFragment = { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null }; -export type CommonResponseFragment = { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null }; +export type CommonResponseFragment = { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null }; export type CommonRecommendedQuestionsTaskFragment = { __typename?: 'RecommendedQuestionsTask', status: Types.RecommendedQuestionsTaskStatus, questions: Array<{ __typename?: 'ResultQuestion', question: string, category: string, sql: string }>, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null }; @@ -37,14 +37,14 @@ export type ThreadQueryVariables = Types.Exact<{ }>; -export type ThreadQuery = { __typename?: 'Query', thread: { __typename?: 'DetailedThread', id: number, responses: Array<{ __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null }> } }; +export type ThreadQuery = { __typename?: 'Query', thread: { __typename?: 'DetailedThread', id: number, responses: Array<{ __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null }> } }; export type ThreadResponseQueryVariables = Types.Exact<{ responseId: Types.Scalars['Int']; }>; -export type ThreadResponseQuery = { __typename?: 'Query', threadResponse: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; +export type ThreadResponseQuery = { __typename?: 'Query', threadResponse: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; export type CreateAskingTaskMutationVariables = Types.Exact<{ data: Types.AskingTaskInput; @@ -73,7 +73,7 @@ export type CreateThreadResponseMutationVariables = Types.Exact<{ }>; -export type CreateThreadResponseMutation = { __typename?: 'Mutation', createThreadResponse: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; +export type CreateThreadResponseMutation = { __typename?: 'Mutation', createThreadResponse: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; export type UpdateThreadMutationVariables = Types.Exact<{ where: Types.ThreadUniqueWhereInput; @@ -154,21 +154,21 @@ export type GenerateThreadResponseBreakdownMutationVariables = Types.Exact<{ }>; -export type GenerateThreadResponseBreakdownMutation = { __typename?: 'Mutation', generateThreadResponseBreakdown: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; +export type GenerateThreadResponseBreakdownMutation = { __typename?: 'Mutation', generateThreadResponseBreakdown: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; export type GenerateThreadResponseAnswerMutationVariables = Types.Exact<{ responseId: Types.Scalars['Int']; }>; -export type GenerateThreadResponseAnswerMutation = { __typename?: 'Mutation', generateThreadResponseAnswer: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; +export type GenerateThreadResponseAnswerMutation = { __typename?: 'Mutation', generateThreadResponseAnswer: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; export type GenerateThreadResponseChartMutationVariables = Types.Exact<{ responseId: Types.Scalars['Int']; }>; -export type GenerateThreadResponseChartMutation = { __typename?: 'Mutation', generateThreadResponseChart: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; +export type GenerateThreadResponseChartMutation = { __typename?: 'Mutation', generateThreadResponseChart: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; export type AdjustThreadResponseChartMutationVariables = Types.Exact<{ responseId: Types.Scalars['Int']; @@ -176,7 +176,7 @@ export type AdjustThreadResponseChartMutationVariables = Types.Exact<{ }>; -export type AdjustThreadResponseChartMutation = { __typename?: 'Mutation', adjustThreadResponseChart: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; +export type AdjustThreadResponseChartMutation = { __typename?: 'Mutation', adjustThreadResponseChart: { __typename?: 'ThreadResponse', id: number, threadId: number, question: string, sql: string, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null, breakdownDetail?: { __typename?: 'ThreadResponseBreakdownDetail', queryId?: string | null, status: Types.AskingTaskStatus, description?: string | null, steps?: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }> | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, answerDetail?: { __typename?: 'ThreadResponseAnswerDetail', queryId?: string | null, status?: Types.ThreadResponseAnswerStatus | null, content?: string | null, numRowsUsedInLLM?: number | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null, chartDetail?: { __typename?: 'ThreadResponseChartDetail', queryId?: string | null, status: Types.ChartTaskStatus, description?: string | null, chartSchema?: any | null, adjustment?: boolean | null, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array | null } | null } | null } }; export const CommonErrorFragmentDoc = gql` fragment CommonError on Error { @@ -221,6 +221,7 @@ export const CommonChartDetailFragmentDoc = gql` error { ...CommonError } + adjustment } ${CommonErrorFragmentDoc}`; export const CommonResponseFragmentDoc = gql` diff --git a/wren-ui/src/apollo/client/graphql/home.ts b/wren-ui/src/apollo/client/graphql/home.ts index f6b12c1ad..994042dfd 100644 --- a/wren-ui/src/apollo/client/graphql/home.ts +++ b/wren-ui/src/apollo/client/graphql/home.ts @@ -50,6 +50,7 @@ const COMMON_CHART_DETAIL = gql` error { ...CommonError } + adjustment } `; diff --git a/wren-ui/src/apollo/server/backgrounds/chart.ts b/wren-ui/src/apollo/server/backgrounds/chart.ts index c5451ec26..fd435326c 100644 --- a/wren-ui/src/apollo/server/backgrounds/chart.ts +++ b/wren-ui/src/apollo/server/backgrounds/chart.ts @@ -205,6 +205,7 @@ export class ChartAdjustmentBackgroundTracker { error: result?.error, description: result?.response?.reasoning, chartSchema: result?.response?.chartSchema, + adjustment: true, }; logger.debug( `Job ${threadResponse.id} chart status changed, updating`, diff --git a/wren-ui/src/apollo/server/repositories/threadResponseRepository.ts b/wren-ui/src/apollo/server/repositories/threadResponseRepository.ts index f3d3a81e6..2bb4ee5e4 100644 --- a/wren-ui/src/apollo/server/repositories/threadResponseRepository.ts +++ b/wren-ui/src/apollo/server/repositories/threadResponseRepository.ts @@ -35,6 +35,7 @@ export interface ThreadResponseChartDetail { error?: object; description?: string; chartSchema?: Record; + adjustment?: boolean; } export interface ThreadResponse { diff --git a/wren-ui/src/apollo/server/schema.ts b/wren-ui/src/apollo/server/schema.ts index 970680712..c565a5a85 100644 --- a/wren-ui/src/apollo/server/schema.ts +++ b/wren-ui/src/apollo/server/schema.ts @@ -684,6 +684,7 @@ export const typeDefs = gql` error: Error description: String chartSchema: JSON + adjustment: Boolean } type ThreadResponse { diff --git a/wren-ui/src/apollo/server/services/askingService.ts b/wren-ui/src/apollo/server/services/askingService.ts index f6982649c..5c42a35b4 100644 --- a/wren-ui/src/apollo/server/services/askingService.ts +++ b/wren-ui/src/apollo/server/services/askingService.ts @@ -779,6 +779,7 @@ export class AskingService implements IAskingService { chartDetail: { queryId: response.queryId, status: ChartStatus.FETCHING, + adjustment: true, }, }, ); diff --git a/wren-ui/src/components/chart/handler.ts b/wren-ui/src/components/chart/handler.ts index a0d90a0c6..572a0080a 100644 --- a/wren-ui/src/components/chart/handler.ts +++ b/wren-ui/src/components/chart/handler.ts @@ -234,7 +234,6 @@ export default class ChartSpecHandler { private addEncoding(encoding: EncodingSpec) { this.encoding = encoding; - const { x, y } = this.getAxisDomain(); // fill color by x field if AI not provide color(category) field if (isNil(this.encoding.color)) { @@ -253,26 +252,6 @@ export default class ChartSpecHandler { // handle scale on bar chart if (this.mark.type === MarkType.BAR) { - if (y) { - this.encoding.y = { - ...this.encoding.y, - scale: { - domain: y, - nice: false, - }, - }; - } - - if (x) { - this.encoding.x = { - ...this.encoding.x, - scale: { - domain: x, - nice: false, - }, - }; - } - if ('stack' in this.encoding.y) { this.encoding.y.stack = this.options.stack; } @@ -291,45 +270,6 @@ export default class ChartSpecHandler { this.addHoverHighlight(this.encoding); } - private getAxisDomain() { - const xField = this.encoding.x as PositionFieldDef; - const yField = this.encoding.y as PositionFieldDef; - const calculateMaxDomain = (field: PositionFieldDef) => { - if (field?.type !== 'quantitative') return null; - const fieldValue = field.field; - const values = (this.data as any).values.map((d) => d[fieldValue]); - - const maxValue = Math.max(...values); - - // Get the magnitude (e.g., 1, 10, 100, 1000) - const magnitude = Math.pow(10, Math.floor(Math.log10(maxValue))); - - // Get number between 1-10 - const normalizedValue = maxValue / magnitude; - let niceNumber; - - if (normalizedValue <= 1.2) niceNumber = 1.2; - else if (normalizedValue <= 1.5) niceNumber = 1.5; - else if (normalizedValue <= 2) niceNumber = 2; - else if (normalizedValue <= 2.5) niceNumber = 2.5; - else if (normalizedValue <= 3) niceNumber = 3; - else if (normalizedValue <= 4) niceNumber = 4; - else if (normalizedValue <= 5) niceNumber = 5; - else if (normalizedValue <= 7.5) niceNumber = 7.5; - else if (normalizedValue <= 8) niceNumber = 8; - else niceNumber = 10; - - const domainMax = niceNumber * magnitude; - return [0, domainMax]; - }; - const xDomain = calculateMaxDomain(xField); - const yDomain = calculateMaxDomain(yField); - return { - x: xDomain, - y: yDomain, - }; - } - private addHoverHighlight(encoding: EncodingSpec) { const category = ( encoding.color?.condition ? encoding.color.condition : encoding.color diff --git a/wren-ui/src/components/pages/home/promptThread/ChartAnswer.tsx b/wren-ui/src/components/pages/home/promptThread/ChartAnswer.tsx index 4a1d36a6a..423ebffa9 100644 --- a/wren-ui/src/components/pages/home/promptThread/ChartAnswer.tsx +++ b/wren-ui/src/components/pages/home/promptThread/ChartAnswer.tsx @@ -96,7 +96,7 @@ export default function ChartAnswer(props: Props) { const [form] = Form.useForm(); const { chartDetail } = threadResponse; - const { error, status } = chartDetail || {}; + const { error, status, adjustment } = chartDetail || {}; const [previewData, previewDataResult] = usePreviewDataMutation({ onError: (error) => console.error(error), @@ -203,6 +203,14 @@ export default function ChartAnswer(props: Props) { onResetState(); }; + const regenerateBtn = ( +
+ +
+ ); + if (error) { return (
@@ -212,15 +220,13 @@ export default function ChartAnswer(props: Props) { type="error" showIcon /> -
- -
+ {regenerateBtn}
); } + const chartRegenerateBtn = adjustment ? regenerateBtn : null; + return (
{chartDetail?.description} - {chartSpec && ( + {chartSpec ? ( + ) : ( + chartRegenerateBtn )}
diff --git a/wren-ui/src/styles/components/chart.less b/wren-ui/src/styles/components/chart.less index 1fd6c0ccc..c5317572f 100644 --- a/wren-ui/src/styles/components/chart.less +++ b/wren-ui/src/styles/components/chart.less @@ -17,7 +17,8 @@ cursor: pointer; width: 28px; height: 28px; - opacity: 0.2; + opacity: 0.4; + color: @gray-8; transition: all 0.4s ease-in; &:hover { @@ -33,7 +34,7 @@ .vega-embed { &:hover { summary { - opacity: 0.2 !important; + opacity: 0.4 !important; } } @@ -43,6 +44,7 @@ box-shadow: none; transition: all 0.4s ease-in; color: @gray-8; + opacity: 0.4 !important; &:hover { opacity: 1 !important; From c7faa089abae1795e79b356363a05595f63d231c Mon Sep 17 00:00:00 2001 From: "wren-ai[bot]" Date: Thu, 26 Dec 2024 07:11:05 +0000 Subject: [PATCH 4/7] update wren-ui version to 0.18.10 --- wren-ui/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wren-ui/package.json b/wren-ui/package.json index 6ba4227a6..9458f0779 100644 --- a/wren-ui/package.json +++ b/wren-ui/package.json @@ -1,6 +1,6 @@ { "name": "wren-ui", - "version": "0.18.9", + "version": "0.18.10", "private": true, "scripts": { "dev": "next dev", From 0e25b4c1c11d1d4f77809e960166b951534f5abe Mon Sep 17 00:00:00 2001 From: Shimin Date: Thu, 26 Dec 2024 15:40:50 +0800 Subject: [PATCH 5/7] fix(wren-ui): chart handler lint (#1066) --- wren-ui/src/components/chart/handler.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/wren-ui/src/components/chart/handler.ts b/wren-ui/src/components/chart/handler.ts index 572a0080a..1b2d71d0d 100644 --- a/wren-ui/src/components/chart/handler.ts +++ b/wren-ui/src/components/chart/handler.ts @@ -1,7 +1,6 @@ import { ChartType } from '@/apollo/client/graphql/__types__'; import { isNil, cloneDeep, uniq, sortBy, omit, isNumber } from 'lodash'; import { Config, TopLevelSpec } from 'vega-lite'; -import { PositionFieldDef } from 'vega-lite/build/src/channeldef'; enum MarkType { ARC = 'arc', From 67603cadd4fe705adc56ecc9454bfc1e53e91f1f Mon Sep 17 00:00:00 2001 From: Chih-Yu Yeh Date: Thu, 26 Dec 2024 16:08:27 +0800 Subject: [PATCH 6/7] chore(wren-ai-service): refine intent classification for time related questions (#1067) --- .../src/pipelines/generation/intent_classification.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wren-ai-service/src/pipelines/generation/intent_classification.py b/wren-ai-service/src/pipelines/generation/intent_classification.py index 9b0ae93f6..62022acd0 100644 --- a/wren-ai-service/src/pipelines/generation/intent_classification.py +++ b/wren-ai-service/src/pipelines/generation/intent_classification.py @@ -31,6 +31,7 @@ - Steps to rephrase the user's question: - First, try to recognize adjectives in the user's question that are important to the user's intent. - Second, change the adjectives to more specific and clear ones that can be matched to columns in the database schema. + - Third, if the user's question is related to time/date, add time/date format(such as YYYY-MM-DD) in the rephrased_question output. - MUST use the rephrased user's question to make the intent classification. - MUST put the rephrased user's question in the rephrased_question output. - REASONING MUST be within 20 words. From 81e4f2a6fabf8b8ba2440897ace01d3121f2afa0 Mon Sep 17 00:00:00 2001 From: "wren-ai[bot]" Date: Thu, 26 Dec 2024 08:13:37 +0000 Subject: [PATCH 7/7] Upgrade AI Service version to 0.13.9 --- wren-ai-service/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wren-ai-service/pyproject.toml b/wren-ai-service/pyproject.toml index 411762941..c52a21a86 100644 --- a/wren-ai-service/pyproject.toml +++ b/wren-ai-service/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "wren-ai-service" -version = "0.13.8" +version = "0.13.9" description = "" authors = ["Jimmy Yeh ", "Pao Sheng Wang ", "Aster Sun "] license = "AGPL-3.0"