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(wren-ui): Integrate thread response explanation API & refine process #539

Merged
merged 11 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
43 changes: 43 additions & 0 deletions wren-ui/src/apollo/client/graphql/__types__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type CorrectionDetail = {
__typename?: 'CorrectionDetail';
correction: Scalars['String'];
id: Scalars['Int'];
referenceNum: Scalars['Int'];
type: ReferenceType;
};

Expand Down Expand Up @@ -120,10 +121,15 @@ 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 @@ -162,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 @@ -344,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 @@ -424,6 +447,7 @@ export type Mutation = {
createRelation: Scalars['JSON'];
createThread: Thread;
createThreadResponse: ThreadResponse;
createThreadResponseExplain: Scalars['JSON'];
createView: ViewInfo;
deleteCalculatedField: Scalars['Boolean'];
deleteModel: Scalars['Boolean'];
Expand Down Expand Up @@ -496,6 +520,11 @@ export type MutationCreateThreadResponseArgs = {
};


export type MutationCreateThreadResponseExplainArgs = {
where: CreateThreadResponseExplainWhereInput;
};


export type MutationCreateViewArgs = {
data: CreateViewInput;
};
Expand Down Expand Up @@ -731,6 +760,12 @@ 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',
Expand Down Expand Up @@ -865,6 +900,7 @@ export type ThreadResponse = {
corrections?: Maybe<Array<CorrectionDetail>>;
detail?: Maybe<ThreadResponseDetail>;
error?: Maybe<Error>;
explain?: Maybe<ThreadResponseExplainInfo>;
id: Scalars['Int'];
question: Scalars['String'];
status: AskingTaskStatus;
Expand All @@ -879,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
64 changes: 59 additions & 5 deletions wren-ui/src/apollo/client/graphql/home.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Apollo from '@apollo/client';
const defaultOptions = {} as const;
export type CommonErrorFragment = { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null };

export type CommonResponseFragment = { __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, correction: string }> | null };
export type CommonResponseFragment = { __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null, references?: Array<{ __typename?: 'DetailReference', referenceId?: number | null, summary: string, type: Types.ReferenceType, sqlSnippet?: string | null, sqlLocation?: { __typename?: 'ReferenceSQLLocation', column: number, line: number } | null } | null> | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, explain?: { __typename?: 'ThreadResponseExplainInfo', queryId?: string | null, status?: Types.ExplainTaskStatus | null, error?: any | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, referenceNum: number, correction: string }> | null };

export type SuggestedQuestionsQueryVariables = Types.Exact<{ [key: string]: never; }>;

Expand All @@ -29,14 +29,14 @@ export type ThreadQueryVariables = Types.Exact<{
}>;


export type ThreadQuery = { __typename?: 'Query', thread: { __typename?: 'DetailedThread', id: number, sql: string, summary: string, responses: Array<{ __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, correction: string }> | null }> } };
export type ThreadQuery = { __typename?: 'Query', thread: { __typename?: 'DetailedThread', id: number, sql: string, summary: string, responses: Array<{ __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null, references?: Array<{ __typename?: 'DetailReference', referenceId?: number | null, summary: string, type: Types.ReferenceType, sqlSnippet?: string | null, sqlLocation?: { __typename?: 'ReferenceSQLLocation', column: number, line: number } | null } | null> | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, explain?: { __typename?: 'ThreadResponseExplainInfo', queryId?: string | null, status?: Types.ExplainTaskStatus | null, error?: any | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, referenceNum: number, correction: string }> | null }> } };

export type ThreadResponseQueryVariables = Types.Exact<{
responseId: Types.Scalars['Int'];
}>;


export type ThreadResponseQuery = { __typename?: 'Query', threadResponse: { __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, correction: string }> | null } };
export type ThreadResponseQuery = { __typename?: 'Query', threadResponse: { __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null, references?: Array<{ __typename?: 'DetailReference', referenceId?: number | null, summary: string, type: Types.ReferenceType, sqlSnippet?: string | null, sqlLocation?: { __typename?: 'ReferenceSQLLocation', column: number, line: number } | null } | null> | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, explain?: { __typename?: 'ThreadResponseExplainInfo', queryId?: string | null, status?: Types.ExplainTaskStatus | null, error?: any | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, referenceNum: number, correction: string }> | null } };

export type CreateAskingTaskMutationVariables = Types.Exact<{
data: Types.AskingTaskInput;
Expand Down Expand Up @@ -65,7 +65,14 @@ export type CreateThreadResponseMutationVariables = Types.Exact<{
}>;


export type CreateThreadResponseMutation = { __typename?: 'Mutation', createThreadResponse: { __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, correction: string }> | null } };
export type CreateThreadResponseMutation = { __typename?: 'Mutation', createThreadResponse: { __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null, references?: Array<{ __typename?: 'DetailReference', referenceId?: number | null, summary: string, type: Types.ReferenceType, sqlSnippet?: string | null, sqlLocation?: { __typename?: 'ReferenceSQLLocation', column: number, line: number } | null } | null> | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, explain?: { __typename?: 'ThreadResponseExplainInfo', queryId?: string | null, status?: Types.ExplainTaskStatus | null, error?: any | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, referenceNum: number, correction: string }> | null } };

export type CreateThreadResponseExplainMutationVariables = Types.Exact<{
where: Types.CreateThreadResponseExplainWhereInput;
}>;


export type CreateThreadResponseExplainMutation = { __typename?: 'Mutation', createThreadResponseExplain: any };

export type UpdateThreadMutationVariables = Types.Exact<{
where: Types.ThreadUniqueWhereInput;
Expand Down Expand Up @@ -102,7 +109,7 @@ export type CreateRegeneratedThreadResponseMutationVariables = Types.Exact<{
}>;


export type CreateRegeneratedThreadResponseMutation = { __typename?: 'Mutation', createRegeneratedThreadResponse: { __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, correction: string }> | null } };
export type CreateRegeneratedThreadResponseMutation = { __typename?: 'Mutation', createRegeneratedThreadResponse: { __typename?: 'ThreadResponse', id: number, question: string, summary: string, status: Types.AskingTaskStatus, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null, detail?: { __typename?: 'ThreadResponseDetail', sql?: string | null, description?: string | null, steps: Array<{ __typename?: 'DetailStep', summary: string, sql: string, cteName?: string | null, references?: Array<{ __typename?: 'DetailReference', referenceId?: number | null, summary: string, type: Types.ReferenceType, sqlSnippet?: string | null, sqlLocation?: { __typename?: 'ReferenceSQLLocation', column: number, line: number } | null } | null> | null }>, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null } | null, explain?: { __typename?: 'ThreadResponseExplainInfo', queryId?: string | null, status?: Types.ExplainTaskStatus | null, error?: any | null } | null, corrections?: Array<{ __typename?: 'CorrectionDetail', id: number, type: Types.ReferenceType, referenceNum: number, correction: string }> | null } };

export const CommonErrorFragmentDoc = gql`
fragment CommonError on Error {
Expand All @@ -125,6 +132,16 @@ export const CommonResponseFragmentDoc = gql`
summary
sql
cteName
references {
referenceId
summary
type
sqlSnippet
sqlLocation {
column
line
}
}
}
view {
id
Expand All @@ -133,9 +150,15 @@ export const CommonResponseFragmentDoc = gql`
displayName
}
}
explain {
queryId
status
error
}
corrections {
id
type
referenceNum
correction
}
}
Expand Down Expand Up @@ -481,6 +504,37 @@ export function useCreateThreadResponseMutation(baseOptions?: Apollo.MutationHoo
export type CreateThreadResponseMutationHookResult = ReturnType<typeof useCreateThreadResponseMutation>;
export type CreateThreadResponseMutationResult = Apollo.MutationResult<CreateThreadResponseMutation>;
export type CreateThreadResponseMutationOptions = Apollo.BaseMutationOptions<CreateThreadResponseMutation, CreateThreadResponseMutationVariables>;
export const CreateThreadResponseExplainDocument = gql`
mutation CreateThreadResponseExplain($where: CreateThreadResponseExplainWhereInput!) {
createThreadResponseExplain(where: $where)
}
`;
export type CreateThreadResponseExplainMutationFn = Apollo.MutationFunction<CreateThreadResponseExplainMutation, CreateThreadResponseExplainMutationVariables>;

/**
* __useCreateThreadResponseExplainMutation__
*
* To run a mutation, you first call `useCreateThreadResponseExplainMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useCreateThreadResponseExplainMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [createThreadResponseExplainMutation, { data, loading, error }] = useCreateThreadResponseExplainMutation({
* variables: {
* where: // value for 'where'
* },
* });
*/
export function useCreateThreadResponseExplainMutation(baseOptions?: Apollo.MutationHookOptions<CreateThreadResponseExplainMutation, CreateThreadResponseExplainMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<CreateThreadResponseExplainMutation, CreateThreadResponseExplainMutationVariables>(CreateThreadResponseExplainDocument, options);
}
export type CreateThreadResponseExplainMutationHookResult = ReturnType<typeof useCreateThreadResponseExplainMutation>;
export type CreateThreadResponseExplainMutationResult = Apollo.MutationResult<CreateThreadResponseExplainMutation>;
export type CreateThreadResponseExplainMutationOptions = Apollo.BaseMutationOptions<CreateThreadResponseExplainMutation, CreateThreadResponseExplainMutationVariables>;
export const UpdateThreadDocument = gql`
mutation UpdateThread($where: ThreadUniqueWhereInput!, $data: UpdateThreadInput!) {
updateThread(where: $where, data: $data) {
Expand Down
24 changes: 24 additions & 0 deletions wren-ui/src/apollo/client/graphql/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ const COMMON_RESPONSE = gql`
summary
sql
cteName
references {
referenceId
summary
type
sqlSnippet
sqlLocation {
column
line
}
}
}
view {
id
Expand All @@ -30,9 +40,15 @@ const COMMON_RESPONSE = gql`
displayName
}
}
explain {
queryId
status
error
}
corrections {
id
type
referenceNum
correction
}
}
Expand Down Expand Up @@ -152,6 +168,14 @@ export const CREATE_THREAD_RESPONSE = gql`
${COMMON_ERROR}
`;

export const CREATE_THREAD_RESPONSE_EXPLAIN = gql`
andreashimin marked this conversation as resolved.
Show resolved Hide resolved
mutation CreateThreadResponseExplain(
$where: CreateThreadResponseExplainWhereInput!
) {
createThreadResponseExplain(where: $where)
}
`;

export const UPDATE_THREAD = gql`
mutation UpdateThread(
$where: ThreadUniqueWhereInput!
Expand Down
5 changes: 3 additions & 2 deletions wren-ui/src/apollo/server/adaptors/wrenAIAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,11 @@ export class WrenAIAdaptor implements IWrenAIAdaptor {
const res = await axios.get(
`${this.wrenAIBaseEndpoint}/v1/sql-explanations/${queryId}/result`,
);
const { status, error } = this.transformStatusAndError(res.data);
return {
status: res.data.status as ExplainPipelineStatus,
status: status as ExplainPipelineStatus,
response: res.data.response,
error: this.transformStatusAndError(res.data).error,
error,
};
} catch (err: any) {
logger.debug(
Expand Down
Loading