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

fix(wren-ui): adjust recommend question to reduce cost #962

Merged
merged 3 commits into from
Nov 28, 2024
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
24 changes: 24 additions & 0 deletions wren-ui/src/apollo/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export interface IConfig {
wrenEngineVersion?: string;
wrenAIVersion?: string;
wrenProductVersion?: string;

// generate recommendation questions max categories
projectRecommendationQuestionMaxCategories?: number;
projectRecommendationQuestionsMaxQuestions?: number;
threadRecommendationQuestionMaxCategories?: number;
threadRecommendationQuestionsMaxQuestions?: number;
}

const defaultConfig = {
Expand Down Expand Up @@ -124,6 +130,24 @@ const config = {
wrenEngineVersion: process.env.WREN_ENGINE_VERSION,
wrenAIVersion: process.env.WREN_AI_SERVICE_VERSION,
wrenProductVersion: process.env.WREN_PRODUCT_VERSION,

// generate recommendation questions max questions
projectRecommendationQuestionMaxCategories: process.env
.PROJECT_RECOMMENDATION_QUESTION_MAX_CATEGORIES
? parseInt(process.env.PROJECT_RECOMMENDATION_QUESTION_MAX_CATEGORIES)
: 3,
projectRecommendationQuestionsMaxQuestions: process.env
.PROJECT_RECOMMENDATION_QUESTIONS_MAX_QUESTIONS
? parseInt(process.env.PROJECT_RECOMMENDATION_QUESTIONS_MAX_QUESTIONS)
: 3,
threadRecommendationQuestionMaxCategories: process.env
.THREAD_RECOMMENDATION_QUESTION_MAX_CATEGORIES
? parseInt(process.env.THREAD_RECOMMENDATION_QUESTION_MAX_CATEGORIES)
: 3,
threadRecommendationQuestionsMaxQuestions: process.env
.THREAD_RECOMMENDATION_QUESTIONS_MAX_QUESTIONS
? parseInt(process.env.THREAD_RECOMMENDATION_QUESTIONS_MAX_QUESTIONS)
: 1,
};

export function getConfig(): IConfig {
Expand Down
24 changes: 15 additions & 9 deletions wren-ui/src/apollo/server/services/askingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ import {
TelemetryEvent,
WrenService,
} from '../telemetry/telemetry';
import { IViewRepository, View } from '../repositories';
import { IViewRepository, Project, View } from '../repositories';
import { IQueryService, PreviewDataResponse } from './queryService';
import { IMDLService } from './mdlService';
import { ThreadRecommendQuestionBackgroundTracker } from '../backgrounds';
import { getConfig } from '@server/config';

const config = getConfig();

const logger = getLogger('AskingService');
logger.level = 'debug';
Expand Down Expand Up @@ -411,11 +414,7 @@ export class AskingService implements IAskingService {
const recommendQuestionData: RecommendationQuestionsInput = {
manifest,
previousQuestions: questions,
maxCategories: 3,
maxQuestions: 9,
configuration: {
language: project.language,
},
...this.getThreadRecommendationQuestionsConfig(project),
};

const result = await this.wrenAIAdaptor.generateRecommendationQuestions(
Expand Down Expand Up @@ -668,9 +667,7 @@ export class AskingService implements IAskingService {
const response = await this.wrenAIAdaptor.generateRecommendationQuestions({
manifest,
previousQuestions: input.previousQuestions,
maxCategories: 3,
maxQuestions: 3,
configuration: { language: project.language },
...this.getThreadRecommendationQuestionsConfig(project),
});
return { id: response.queryId };
}
Expand Down Expand Up @@ -748,4 +745,13 @@ export class AskingService implements IAskingService {
},
});
}
private getThreadRecommendationQuestionsConfig(project: Project) {
return {
maxCategories: config.threadRecommendationQuestionMaxCategories,
maxQuestions: config.threadRecommendationQuestionsMaxQuestions,
configuration: {
language: project.language,
},
};
}
}
7 changes: 5 additions & 2 deletions wren-ui/src/apollo/server/services/projectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import { RecommendQuestionResultStatus } from './askingService';
import { IMDLService } from './mdlService';
import { ProjectRecommendQuestionBackgroundTracker } from '../backgrounds';
import { ITelemetry } from '../telemetry/telemetry';
import { getConfig } from '../config';

const config = getConfig();

const logger = getLogger('ProjectService');
logger.level = 'debug';
Expand Down Expand Up @@ -233,8 +236,8 @@ export class ProjectService implements IProjectService {

private getProjectRecommendationQuestionsConfig(project: Project) {
return {
maxCategories: 3,
maxQuestions: 9,
maxCategories: config.projectRecommendationQuestionMaxCategories,
maxQuestions: config.projectRecommendationQuestionsMaxQuestions,
regenerate: true,
configuration: {
language: project.language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const QuestionTemplate = ({ category, sql, question, onSelect }) => {
const QuestionColumnIterator = makeIterable(QuestionTemplate);

export default function RecommendedQuestionsPrompt(props) {
const { onSelect, recommendedQuestions, buttonProps } = props;
const { onSelect, recommendedQuestions } = props;

const [isExpanded, setIsExpanded] = useState<boolean>(false);

Expand All @@ -65,15 +65,14 @@ export default function RecommendedQuestionsPrompt(props) {

return (
<div className="bg-gray-2 px-10 py-6">
<div className="d-flex align-center mb-3 justify-space-between">
<div className="d-flex align-center mb-3">
<Logo size={24} color="var(--gray-8)" />
<div className="text-md text-medium gray-8 mx-3">
Know more about your data.
</div>
<div className="text-medium gray-7">
Try asking some of the following questions
</div>
<Button className="ml-3" {...buttonProps} />
</div>
<Space
style={{ width: 680 }}
Expand Down
1 change: 1 addition & 0 deletions wren-ui/src/hooks/useRecommendedQuestionsInstruction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default function useRecommendedQuestionsInstruction() {
};

if (showRecommendedQuestionsPromptMode && isRegenerate) {
// The cost of generating recommend questions is too high, so we still return button pops, but the button will not show on the UI now.
return {
...baseProps,
icon: <ReloadOutlined />,
Expand Down
1 change: 0 additions & 1 deletion wren-ui/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function RecommendedQuestionsInstruction(props) {
<RecommendedQuestionsPrompt
recommendedQuestions={recommendedQuestions}
onSelect={onSelect}
buttonProps={buttonProps}
/>
<div className="py-12" />
</div>
Expand Down