Skip to content

Commit

Permalink
Removing user notes from data sent to AI
Browse files Browse the repository at this point in the history
  • Loading branch information
davetaz committed Aug 30, 2024
1 parent 4adb82c commit 637b273
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maturity.theodi.org",
"version": "0.8.0",
"version": "0.8.1",
"description": "The ODI Maturity Assessment Tool (pathway)",
"main": "index.js",
"scripts": {
Expand Down
22 changes: 16 additions & 6 deletions routes/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,24 @@ router.get('/:id/assistant/getActivitySummary', ensureAuthenticated, checkProjec
return res.status(404).json({ error: 'Activity not found' });
}

// 4. Use the getOrGenerateActivitySummary function to handle the summary generation or retrieval
// 4. Create a deep copy of the activity object to remove notes before sending to AI
const activityCopy = JSON.parse(JSON.stringify(activity));

// 5. Remove notes from userAnswer in the activityCopy
activityCopy.statements.forEach(statement => {
if (statement.userAnswer && statement.userAnswer.notes) {
delete statement.userAnswer.notes;
}
});

// 6. Use the getOrGenerateActivitySummary function with the modified activityCopy
const levelKeys = ["Initial", "Repeatable", "Defined", "Managed", "Optimising"];
const summary = await getOrGenerateActivitySummary(activity, dimension.name, levelKeys, assessmentTitle);
const summary = await getOrGenerateActivitySummary(activityCopy, dimension.name, levelKeys, assessmentTitle);

// 5. Generate hash for the current activity state
// 7. Generate hash for the current activity state
const activityHash = generateHash(activity.statements.map(s => s.userAnswer));

// 6. Update the specific activity's aiResponse in the dimension
// 8. Update the specific activity's aiResponse in the dimension
const updateQuery = {
_id: projectId,
'assessmentData.dimensions.name': dimension.name,
Expand All @@ -154,10 +164,10 @@ router.get('/:id/assistant/getActivitySummary', ensureAuthenticated, checkProjec
new: true
};

// 7. Perform the update
// 9. Perform the update
await Project.findOneAndUpdate(updateQuery, updateAction, updateOptions);

// 8. Send the summary as the response
// 10. Send the summary as the response
res.json({ response: summary });

} catch (error) {
Expand Down

0 comments on commit 637b273

Please sign in to comment.