public with sharing class EinsteinAction { | |
public class Prediction { | |
@InvocableVariable | |
public String label; | |
@InvocableVariable | |
public Double probability; | |
} | |
@InvocableMethod(label='Classify the given files' description='Calls the Einsten API to classify the given ContentVersion files.') | |
public static List<EinsteinAction.Prediction> classifyFiles(List<ID> contentVersionIds) { | |
String access_token = new VisionController().getAccessToken(); | |
ContentVersion content = [SELECT Title,VersionData FROM ContentVersion where Id in :contentVersionIds LIMIT 1]; | |
List<EinsteinAction.Prediction> predictions = new List<EinsteinAction.Prediction>(); | |
for(Vision.Prediction vp : Vision.predictBlob(content.VersionData, access_token, 'GeneralImageClassifier')) { | |
EinsteinAction.Prediction p = new EinsteinAction.Prediction(); | |
p.label = vp.label; | |
p.probability = vp.probability; | |
predictions.add(p); | |
break; // Just take the most probable | |
} | |
return predictions; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment