Mantis summary updates.
This commit is contained in:
parent
0e0d1bffb3
commit
af8cc56e79
7 changed files with 168 additions and 16 deletions
|
@ -3,7 +3,8 @@ import { PrismaClient } from '@prisma/client'; // Import Prisma Client
|
|||
import { getMantisSettings, saveTicketToDatabase } from '../services/mantisDownloader.js';
|
||||
import axios from 'axios';
|
||||
import reader from '@kenjiuno/msgreader';
|
||||
import SuperJSON from 'superjson';
|
||||
import { askGemini } from '../utils/gemini.js';
|
||||
import { usernameMap } from '../services/mantisSummarizer.js';
|
||||
const MsgReader = reader.default;
|
||||
|
||||
const prisma = new PrismaClient(); // Instantiate Prisma Client
|
||||
|
@ -356,4 +357,42 @@ router.get('/stats/comments', async(req, res) =>
|
|||
}
|
||||
});
|
||||
|
||||
router.get('/summary/:ticketId', async(req, res) =>
|
||||
{
|
||||
const { ticketId } = req.params;
|
||||
|
||||
try
|
||||
{
|
||||
const ticket = await prisma.mantisIssue.findUnique({
|
||||
where: { id: parseInt(ticketId, 10) },
|
||||
include: {
|
||||
comments: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!ticket)
|
||||
{
|
||||
return res.status(404).json({ error: 'Mantis ticket not found' });
|
||||
}
|
||||
|
||||
//We need to change the usernames using the usernameMap
|
||||
ticket.reporterUsername = usernameMap[ticket.reporterUsername] || ticket.reporterUsername;
|
||||
ticket.comments = ticket.comments.map((comment) =>
|
||||
{
|
||||
comment.senderUsername = usernameMap[comment.senderUsername] || comment.senderUsername;
|
||||
return comment;
|
||||
});
|
||||
|
||||
//Ask Gemini to summarize the ticket
|
||||
const summary = await askGemini(`Please summarize the following Mantis ticket in the form of a markdown list of bullet points formatted as "[Date] Point" (ensure a newline between each point, format the date as DD/MM/YYY and surround it with square brackets "[]"). Then after your summary, list any outstanding actions as a markdown list in the format "[Name] Action" (again surrounding the name with square brackets).
|
||||
Output a heading 6 "Summary:", a newline, the summary, then two newlines, a heading 6 "Actions:" then the actions. Do not wrap the output in a code block.\n\n### Ticket Data ###\n\n` + JSON.stringify(ticket, null, 2));
|
||||
res.status(200).json({ summary });
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
console.error('Error fetching Mantis summary:', error.message);
|
||||
res.status(500).json({ error: 'Failed to fetch Mantis summary' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
|
@ -4,7 +4,7 @@ import prisma from '../database.js'; // Import Prisma client
|
|||
import { getSetting } from '../utils/settings.js';
|
||||
import { askGemini } from '../utils/gemini.js';
|
||||
|
||||
const usernameMap = {
|
||||
export const usernameMap = {
|
||||
credmore: 'Cameron Redmore',
|
||||
dgibson: 'Dane Gibson',
|
||||
egzibovskis: 'Ed Gzibovskis',
|
||||
|
|
|
@ -5,9 +5,17 @@ import { getSetting } from './settings.js';
|
|||
|
||||
const model = 'gemini-2.0-flash';
|
||||
|
||||
const geminiResponseCache = new Map();
|
||||
|
||||
export async function askGemini(content)
|
||||
{
|
||||
|
||||
// Check if the content is already cached
|
||||
if (geminiResponseCache.has(content))
|
||||
{
|
||||
return geminiResponseCache.get(content);
|
||||
}
|
||||
|
||||
const GOOGLE_API_KEY = await getSetting('GEMINI_API_KEY');
|
||||
|
||||
if (!GOOGLE_API_KEY)
|
||||
|
@ -34,6 +42,9 @@ export async function askGemini(content)
|
|||
}
|
||||
});
|
||||
|
||||
// Cache the response
|
||||
geminiResponseCache.set(content, response.text);
|
||||
|
||||
return response.text;
|
||||
}
|
||||
catch (error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue