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): use intent reasoning instead of hard code string for misleading query #1217

Merged
merged 1 commit into from
Jan 24, 2025
Merged
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
1 change: 1 addition & 0 deletions wren-ui/src/apollo/client/graphql/__types__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type AskingTask = {
__typename?: 'AskingTask';
candidates: Array<ResultCandidate>;
error?: Maybe<Error>;
intentReasoning?: Maybe<Scalars['String']>;
status: AskingTaskStatus;
type?: Maybe<AskingTaskType>;
};
Expand Down
3 changes: 2 additions & 1 deletion wren-ui/src/apollo/client/graphql/home.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type AskingTaskQueryVariables = Types.Exact<{
}>;


export type AskingTaskQuery = { __typename?: 'Query', askingTask: { __typename?: 'AskingTask', status: Types.AskingTaskStatus, type?: Types.AskingTaskType | null, candidates: Array<{ __typename?: 'ResultCandidate', sql: string, type: Types.ResultCandidateType, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null }>, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null } };
export type AskingTaskQuery = { __typename?: 'Query', askingTask: { __typename?: 'AskingTask', status: Types.AskingTaskStatus, type?: Types.AskingTaskType | null, intentReasoning?: string | null, candidates: Array<{ __typename?: 'ResultCandidate', sql: string, type: Types.ResultCandidateType, view?: { __typename?: 'ViewInfo', id: number, name: string, statement: string, displayName: string } | null }>, error?: { __typename?: 'Error', code?: string | null, shortMessage?: string | null, message?: string | null, stacktrace?: Array<string | null> | null } | null } };

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

Expand Down Expand Up @@ -318,6 +318,7 @@ export const AskingTaskDocument = gql`
error {
...CommonError
}
intentReasoning
}
}
${CommonErrorFragmentDoc}`;
Expand Down
1 change: 1 addition & 0 deletions wren-ui/src/apollo/client/graphql/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const ASKING_TASK = gql`
error {
...CommonError
}
intentReasoning
}
}
${COMMON_ERROR}
Expand Down
3 changes: 2 additions & 1 deletion wren-ui/src/apollo/server/adaptors/wrenAIAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export class WrenAIAdaptor implements IWrenAIAdaptor {
}

private transformAskResult(body: any): AskResult {
const { type } = body;
const { type, intent_reasoning } = body;
const { status, error } = this.transformStatusAndError(body);
const candidates = (body?.response || []).map((candidate: any) => ({
type: candidate?.type?.toUpperCase() as AskCandidateType,
Expand All @@ -520,6 +520,7 @@ export class WrenAIAdaptor implements IWrenAIAdaptor {
status: status as AskResultStatus,
error,
response: candidates,
intentReasoning: intent_reasoning,
};
}

Expand Down
4 changes: 3 additions & 1 deletion wren-ui/src/apollo/server/models/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ export type AskResult = AskResponse<
viewId?: number | null;
}>,
AskResultStatus
>;
> & {
intentReasoning?: string;
};

export enum RecommendationQuestionStatus {
GENERATING = 'GENERATING',
Expand Down
2 changes: 2 additions & 0 deletions wren-ui/src/apollo/server/resolvers/askingResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface AskingTask {
sql: string;
}>;
error: WrenAIError | null;
intentReasoning?: string;
}

// DetailedThread is a type that represents a detailed thread, which is a thread with responses.
Expand Down Expand Up @@ -224,6 +225,7 @@ export class AskingResolver {
status: askResult.status,
error: askResult.error,
candidates,
intentReasoning: askResult.intentReasoning,
};
}

Expand Down
1 change: 1 addition & 0 deletions wren-ui/src/apollo/server/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ export const typeDefs = gql`
type: AskingTaskType
error: Error
candidates: [ResultCandidate!]!
intentReasoning: String
}

input InstantRecommendedQuestionsInput {
Expand Down
7 changes: 4 additions & 3 deletions wren-ui/src/components/pages/home/prompt/Result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface Props {
candidates: AskingTask['candidates'];
askingStreamTask: string;
recommendedQuestions: RecommendedQuestionsTask;
intentReasoning: string;
};
error?: any;
onSelectResult: (payload: { sql: string; viewId: number | null }) => void;
Expand Down Expand Up @@ -117,7 +118,9 @@ const makeProcessingError =
Close
</Button>
</div>
<div className="gray-7">{config.description || message}</div>
<div className="gray-7">
{config.description || data.intentReasoning || message}
</div>
{hasStacktrace && (
<ErrorCollapse className="mt-2" message={stacktrace.join('\n')} />
)}
Expand Down Expand Up @@ -243,8 +246,6 @@ const GeneralAnswer = (props: Props) => {
const MisleadingQuery = makeProcessingError({
icon: <WarningOutlined className="mr-2 text-lg gold-6" />,
title: 'Clarification needed',
description:
"Could you please provide more details or specify the information you're seeking?",
});

const getGeneralAnswerStateComponent = (state: PROCESS_STATE) => {
Expand Down
1 change: 1 addition & 0 deletions wren-ui/src/components/pages/home/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default forwardRef<Attributes, Props>(function Prompt(props, ref) {
candidates: askingTask?.candidates || [], // for text to sql answer, only one candidate
askingStreamTask, // for general answer
recommendedQuestions, // guiding user to ask
intentReasoning: askingTask?.intentReasoning || '',
}),
[data],
);
Expand Down