| 1 | import prisma from "./prisma"; |
| 2 | |
| 3 | export async function upsertPrediction(predictionData) { |
| 4 | console.log("🤔 upsert prediction? ", predictionData.id); |
| 5 | |
| 6 | if (predictionData?.status !== "succeeded") { |
| 7 | console.log("🙈 skiping incomplete or unsuccesful prediction"); |
| 8 | return; |
| 9 | } |
| 10 | |
| 11 | const prediction = { |
| 12 | uuid: predictionData.id, |
| 13 | input: predictionData.input, |
| 14 | output: predictionData.output, |
| 15 | status: predictionData.status, |
| 16 | created_at: predictionData.created_at, |
| 17 | started_at: predictionData.started_at, |
| 18 | completed_at: predictionData.completed_at, |
| 19 | version: predictionData.version, |
| 20 | metrics: predictionData.metrics, |
| 21 | error: predictionData.error, |
| 22 | }; |
| 23 | |
| 24 | try { |
| 25 | await prisma.prediction.upsert({ |
| 26 | where: { |
| 27 | uuid: prediction.uuid, |
| 28 | }, |
| 29 | update: prediction, |
| 30 | create: prediction, |
| 31 | }); |
| 32 | |
| 33 | console.log("✅ upserted prediction ", prediction.uuid); |
| 34 | } catch (e) { |
| 35 | console.error(e); |
| 36 | } finally { |
| 37 | await prisma.$disconnect(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | export async function getRecentPredictions() { |
| 42 | const predictions = await prisma.prediction.findMany({ |