mirror of
https://github.com/Canner/WrenAI.git
synced 2026-09-21 13:20:21 +08:00
fix incorrect column mapping in project repository .
refactor check task exists in recommend-question BT.
This commit is contained in:
@@ -222,15 +222,13 @@ export class WrenAIAdaptor implements IWrenAIAdaptor {
|
||||
max_categories: input.maxCategories,
|
||||
configuration: input.configuration,
|
||||
};
|
||||
logger.debug(
|
||||
`Wren AI: Generating recommendation questions, body: ${JSON.stringify(body)}`,
|
||||
);
|
||||
logger.info(`Wren AI: Generating recommendation questions`);
|
||||
try {
|
||||
const res = await axios.post(
|
||||
`${this.wrenAIBaseEndpoint}/v1/question-recommendations`,
|
||||
body,
|
||||
);
|
||||
logger.debug(
|
||||
logger.info(
|
||||
`Wren AI: Generating recommendation questions, queryId: ${res.data.id}`,
|
||||
);
|
||||
return { queryId: res.data.id };
|
||||
|
||||
@@ -164,6 +164,10 @@ export class ProjectRecommendQuestionBackgroundTracker {
|
||||
public taskKey(project: Project) {
|
||||
return project.id;
|
||||
}
|
||||
|
||||
public isExist(project: Project) {
|
||||
return this.tasks[this.taskKey(project)];
|
||||
}
|
||||
}
|
||||
|
||||
export class ThreadRecommendQuestionBackgroundTracker {
|
||||
@@ -310,4 +314,8 @@ export class ThreadRecommendQuestionBackgroundTracker {
|
||||
public taskKey(thread: Thread) {
|
||||
return thread.id;
|
||||
}
|
||||
|
||||
public isExist(thread: Thread) {
|
||||
return this.tasks[this.taskKey(thread)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ export class ProjectRepository
|
||||
extends BaseRepository<Project>
|
||||
implements IProjectRepository
|
||||
{
|
||||
private jsonTypeColumns = ['questions', 'questionsError', 'connectionInfo'];
|
||||
private jsonTypeColumns = ['questions', 'questions_error', 'connection_info'];
|
||||
|
||||
constructor(knexPg: Knex) {
|
||||
super({ knexPg, tableName: 'project' });
|
||||
@@ -136,8 +136,7 @@ export class ProjectRepository
|
||||
if (!isPlainObject(data)) {
|
||||
throw new Error('Unexpected db data');
|
||||
}
|
||||
const camelCaseData = mapKeys(data, (_value, key) => camelCase(key));
|
||||
const formattedData = mapValues(camelCaseData, (value, key) => {
|
||||
const formattedData = mapValues(data, (value, key) => {
|
||||
if (this.jsonTypeColumns.includes(key) && typeof value === 'string') {
|
||||
// should return {} if value is null / {}, use value ? {} : JSON.parse(value) will throw error when value is null
|
||||
return isEmpty(value) ? {} : JSON.parse(value);
|
||||
@@ -147,7 +146,10 @@ export class ProjectRepository
|
||||
}
|
||||
return value;
|
||||
});
|
||||
return formattedData as Project;
|
||||
const camelCaseData = mapKeys(formattedData, (_value, key) =>
|
||||
camelCase(key),
|
||||
);
|
||||
return camelCaseData as Project;
|
||||
};
|
||||
|
||||
public override transformToDBData: (data: Project) => any = (
|
||||
|
||||
@@ -390,10 +390,7 @@ export class AskingService implements IAskingService {
|
||||
throw new Error(`Thread ${threadId} not found`);
|
||||
}
|
||||
|
||||
const tasks = this.threadRecommendQuestionBackgroundTracker.getTasks();
|
||||
const taskKey =
|
||||
this.threadRecommendQuestionBackgroundTracker.taskKey(thread);
|
||||
if (tasks[taskKey]) {
|
||||
if (this.threadRecommendQuestionBackgroundTracker.isExist(thread)) {
|
||||
logger.debug(
|
||||
`thread "${threadId}" recommended questions are generating, skip the current request`,
|
||||
);
|
||||
|
||||
@@ -111,14 +111,14 @@ export class ProjectService implements IProjectService {
|
||||
questions: [],
|
||||
questionsError: null,
|
||||
});
|
||||
const tasks = this.projectRecommendQuestionBackgroundTracker.getTasks();
|
||||
const taskKey =
|
||||
this.projectRecommendQuestionBackgroundTracker.taskKey(updatedProject);
|
||||
if (!tasks[taskKey]) {
|
||||
|
||||
if (
|
||||
!this.projectRecommendQuestionBackgroundTracker.isExist(updatedProject)
|
||||
) {
|
||||
this.projectRecommendQuestionBackgroundTracker.addTask(updatedProject);
|
||||
} else {
|
||||
logger.debug(
|
||||
`Generate Project Recommendation Questions Task ${taskKey} already exists, skip adding`,
|
||||
`Generate Project Recommendation Questions Task ${updatedProject.id} already exists, skip adding`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,8 +268,8 @@ export class QueryService implements IQueryService {
|
||||
this.telemetry.sendEvent(
|
||||
event,
|
||||
{
|
||||
correlationId: err.extensions.other.correlationId,
|
||||
processTime: err.extensions.other.processTime,
|
||||
correlationId: err.extensions?.other?.correlationId,
|
||||
processTime: err.extensions?.other?.processTime,
|
||||
error: err.message,
|
||||
...others,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user