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

explorer: remove table name for chart options #1238

Merged
Merged
Changes from 1 commit
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
Next Next commit
explorer: remove table name for chart options
  • Loading branch information
Mini256 committed Feb 1, 2023
commit 6e87a84dc253ca814afb4b59518fc677f0504ac4
18 changes: 17 additions & 1 deletion packages/api-server/src/plugins/services/bot-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default fp(async (fastify) => {

const GENERATE_ANSWER_PROMPT_TEMPLATE_NAME = 'explorer-generate-answer';

const tableColumnRegexp = /(?<table_name>.+)\.(?<column_name>.+)/;

export class BotService {
private readonly openai: OpenAIApi;

Expand Down Expand Up @@ -150,7 +152,10 @@ export class BotService {
chart: answer.chart ? {
chartName: answer.chart.chartName,
title: answer.chart.title,
...answer.chart.options
...this.removeTableNameForColumn({
country_code: "gr.country_code",
actor_login: "gu.actor_login"
})
} : null,
questions: answer.questions || [],
}
Expand All @@ -168,6 +173,17 @@ export class BotService {
}
}

removeTableNameForColumn(chartOptions: Record<string, string>) {
Object.entries(chartOptions).forEach(([key, value]) => {
const match = tableColumnRegexp.exec(value);
if (match) {
const groups = match.groups as any;
chartOptions[key] = groups.column_name;
}
});
return chartOptions;
}

async generateRecommendQuestions(template: GenerateQuestionsPromptTemplate, n: number): Promise<RecommendQuestion[]> {
const prompt = template.stringify(n);

Expand Down