forked from TID-Lab/aggie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from TID-Lab/AITags
Basic Templated AI Tagging
- Loading branch information
Showing
23 changed files
with
9,109 additions
and
5,494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Adds AI-generated tags to the report | ||
|
||
module.exports = async function tagReportsAI(report, next) { | ||
const axios = require("axios"); | ||
|
||
try { | ||
console.log("PreAPI Report", JSON.parse(JSON.stringify(report))); | ||
const response = await axios.post( | ||
"http://localhost:8080/twoshotextract", | ||
JSON.parse(JSON.stringify(report)) | ||
); | ||
const data = response.data; | ||
|
||
const aiTags = {}; | ||
const tagNames = []; | ||
|
||
for (const key in data) { | ||
if (!key.endsWith("_rationale") && !key == "red_flag") { | ||
const rationaleKey = `${key}_rationale`; | ||
aiTags[key] = { | ||
value: data[key], | ||
rationale: data[rationaleKey] || null, | ||
}; | ||
tagNames.push(key); | ||
} | ||
} | ||
console.log(aiTags); | ||
console.log(tagNames); | ||
report.aitags = aiTags; | ||
report.aitagnames = tagNames; | ||
report.red_flag = Boolean(data["red_flag"]); | ||
} catch (error) { | ||
console.error("Error fetching AI tags:", error); | ||
const aiTags = { | ||
key1: { value: true, rationale: "Default rationale for key1" }, | ||
key2: { | ||
value: "default string", | ||
rationale: "Default rationale for key2", | ||
}, | ||
}; | ||
report.aitags = aiTags; | ||
report.aitagnames = Object.keys(aiTags); | ||
} | ||
console.log(report); | ||
|
||
await next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.