Skip to content

Instantly share code, notes, and snippets.

@alongubkin
Created October 14, 2021 15:58
Show Gist options
  • Save alongubkin/e261a25150f8dbf56ca1b4b8f3aa23ee to your computer and use it in GitHub Desktop.
Save alongubkin/e261a25150f8dbf56ca1b4b8f3aa23ee to your computer and use it in GitHub Desktop.
Log predictions to Aporia from Node.js
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}`);
}
}
@alongubkin
Copy link
Author

alongubkin commented Oct 14, 2021

Usage example:

await logPredictions({
  modelId: "my-model",
  modelVersion: "v1",
  environment: "prod",
  predictions: [{
    id: "some-prediction-id",
    occurredAt: new Date().toISOString(),
    features: {
      x: 0.5,
    },
    predictions: {
      y: true,
    },
  }],
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment