generated from lambda-feedback/evaluation-function-boilerplate-wolfram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.wls
More file actions
51 lines (36 loc) · 1.4 KB
/
deploy.wls
File metadata and controls
51 lines (36 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env wolframscript
previewPackagePath = FileNameJoin[{Directory[], "Preview.m"}];
If[!FileExistsQ[previewPackagePath],
Print["Error: file not found at " <> previewPackagePath];
Abort[];
];
evaluatePackagePath = FileNameJoin[{Directory[], "Evaluate.m"}];
If[!FileExistsQ[evaluatePackagePath],
Print["Error: file not found at " <> evaluatePackagePath];
Abort[];
];
(* Load the package locally first *)
Get[previewPackagePath];
Get[evaluatePackagePath];
(* Test locally *)
Print["Testing preview locally:"];
Print[preview`PreviewFunction["x^2"]];
Print["Testing evaluate locally:"];
Print[evaluate`EvaluationFunction["structure", "x^2", "y^2",
<|"correct_response_feedback" -> "Correct", "incorrect_response_feedback" -> "Incorrect"|>]];
(* Deploy the API with explicit JSON export *)
previewAPI = APIFunction[
{"response" -> "String"},
ExportForm[preview`PreviewFunction[#response], "JSON"] &
];
previewObj = CloudDeploy[previewAPI, "preview-api", Permissions -> "Public"];
Print["Preview API deployed to: ", previewObj];
evaluateAPI = APIFunction[
{"type" -> "String",
"response" -> "String",
"answer" -> "String",
"params" -> "JSON"},
ExportForm[evaluate`EvaluationFunction[#type, #answer, #response, #params], "JSON"] &
];
evaluateObj = CloudDeploy[evaluateAPI, "evaluate-api", Permissions -> "Public"];
Print["Evaluate API deployed to: ", evaluateObj];