Skip to content

Commit a815a3e

Browse files
committed
Successfully deployed evaluate API
1 parent d2624c0 commit a815a3e

File tree

2 files changed

+40
-55
lines changed

2 files changed

+40
-55
lines changed

deploy.wls

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
#!/usr/bin/env wolframscript
22

3-
packagePath = FileNameJoin[{Directory[], "Preview.m"}];
3+
previewPackagePath = FileNameJoin[{Directory[], "Preview.m"}];
44

5-
If[!FileExistsQ[packagePath],
6-
Print["Error: file not found at " <> packagePath];
5+
If[!FileExistsQ[previewPackagePath],
6+
Print["Error: file not found at " <> previewPackagePath];
7+
Abort[];
8+
];
9+
10+
evaluatePackagePath = FileNameJoin[{Directory[], "Evaluate.m"}];
11+
12+
If[!FileExistsQ[evaluatePackagePath],
13+
Print["Error: file not found at " <> evaluatePackagePath];
714
Abort[];
815
];
916

1017
(* Load the package locally first *)
11-
Get[packagePath];
18+
Get[previewPackagePath];
19+
Get[evaluatePackagePath];
1220

1321
(* Test locally *)
14-
Print["Testing locally:"];
22+
Print["Testing preview locally:"];
1523
Print[preview`PreviewFunction["x^2"]];
1624

25+
Print["Testing evaluate locally:"];
26+
Print[evaluate`EvaluationFunction["structure", "x^2", "y^2",
27+
<|"correct_response_feedback" -> "Correct", "incorrect_response_feedback" -> "Incorrect"|>]];
28+
1729

1830

1931
(* Deploy the API with explicit JSON export *)
20-
api = APIFunction[
32+
previewAPI = APIFunction[
2133
{"response" -> "String"},
2234
ExportForm[preview`PreviewFunction[#response], "JSON"] &
2335
];
2436

25-
obj = CloudDeploy[api, "preview-api", Permissions -> "Public"];
37+
previewObj = CloudDeploy[previewAPI, "preview-api", Permissions -> "Public"];
38+
39+
Print["Preview API deployed to: ", previewObj];
40+
41+
evaluateAPI = APIFunction[
42+
{"type" -> "String",
43+
"response" -> "String",
44+
"answer" -> "String",
45+
"params" -> "JSON"},
46+
ExportForm[evaluate`EvaluationFunction[#type, #answer, #response, #params], "JSON"] &
47+
];
48+
49+
evaluateObj = CloudDeploy[evaluateAPI, "evaluate-api", Permissions -> "Public"];
2650

27-
Print["API deployed to: ", obj];
51+
Print["Evaluate API deployed to: ", evaluateObj];

evaluate.m

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,24 @@
1616

1717
(* For new style packages see: https://mathematica.stackexchange.com/a/176489) *)
1818
(* Declare package context *)
19-
BeginPackage["evaluate`"]
19+
BeginPackage["evaluate`"];
2020

2121
EvaluationFunction[type_, answer_, response_, params_] := Module[{result, feedback},
2222
Print["Running Evaluation Function"];
2323
result = evalQ[type, answer, response, params];
24-
Print["Results"];
25-
Print[result];
2624
feedback = If[result["is_correct"],
2725
Lookup[params, "correct_response_feedback", "Correct!"],
2826
Lookup[params, "incorrect_response_feedback", "Incorrect!"]
2927
];
28+
3029
<|
31-
"command" -> "eval",
32-
"result" -> <|
33-
"is_correct" -> result["is_correct"],
34-
"feedback" -> feedback,
35-
"error" -> result["error"]
36-
|>
30+
"is_correct" -> result["is_correct"],
31+
"feedback" -> feedback,
32+
"error" -> result["error"]
3733
|>
38-
]
34+
];
3935

40-
Begin["`Private`"]
36+
Begin["`Private`"];
4137

4238
equalQNumeric[answer_, response_, params_] := Module[{tolerance},
4339
Print["Evaluating Equal Numeric"];
@@ -174,40 +170,5 @@
174170
equalQOther[answer, response, params]
175171
]
176172
];
177-
178-
EvaluationFunction[type_, answer_, response_, params_] := Module[{result,feedback},
179-
Print["Running Evaluation Function"];
180-
result = evalQ[type, answer, response, params];
181-
Print["Results"];
182-
Print[result];
183-
feedback = If[result["is_correct"],
184-
Lookup[params, "correct_response_feedback", "Correct!"],
185-
Lookup[params, "incorrect_response_feedback", "Incorrect!"]
186-
];
187-
<|
188-
"command" -> "eval",
189-
"result" -> <|
190-
"is_correct" -> result["is_correct"],
191-
"feedback" -> feedback,
192-
"error" -> result["error"]
193-
|>
194-
|>
195-
];
196-
197-
evalQuestionIO = Function[
198-
Module[{jsonData, result,requestData,answer,response,params,type},
199-
jsonData = Import[#1, "JSON"] //. List :> Association;
200-
requestData = jsonData["params"];
201-
answer = requestData["answer"];
202-
response = requestData["response"];
203-
params = requestData["params"];
204-
type = params["comparisonType"];
205-
Print["Evaluating Response Against Answer"];
206-
result = EvaluationFunction[type, answer, response, params];
207-
Print["Response"];
208-
Print[result];
209-
Export[#2, result, "JSON", "Compact" -> True]
210-
]
211-
];
212-
End[]
173+
End[];
213174
EndPackage[]

0 commit comments

Comments
 (0)