Created
October 14, 2021 15:58
-
-
Save alongubkin/e261a25150f8dbf56ca1b4b8f3aa23ee to your computer and use it in GitHub Desktop.
Log predictions to Aporia from Node.js
This file contains hidden or 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
import fetch from "node-fetch"; | |
const APORIA_TOKEN = "<TOKEN>"; | |
async function logPredictions(data) { | |
const query = ` | |
mutation LogPredict( | |
$modelId: String!, | |
$modelVersion: String!, | |
$environment: String!, | |
$predictions: [Prediction]! | |
$isSync: Boolean! | |
) { | |
logPredictions( | |
modelId: $modelId, | |
modelVersion: $modelVersion, | |
environment: $environment, | |
predictions: $predictions | |
isSync: $isSync | |
) { | |
warnings | |
} | |
} | |
` | |
const response = await fetch("https://app.aporia.com/v1/controller/graphql", { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": `Bearer ${APORIA_TOKEN}`, | |
}, | |
body: JSON.stringify({ | |
query, | |
variables: { | |
...data, | |
isSync: true, | |
}, | |
}), | |
}); | |
const warnings = (await response.json()).data.logPredictions.warnings; | |
if (warnings.length > 0) { | |
throw new Error(`Failed to log predictions; ${warnings}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example: