generated from lambda-feedback/evaluation-function-boilerplate-wolfram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluation_function.wl
More file actions
86 lines (67 loc) · 2.09 KB
/
evaluation_function.wl
File metadata and controls
86 lines (67 loc) · 2.09 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(* ::Package:: *)
(* The code that handles incoming messages and passes them to evaluate or preview accordingly*)
<< "evaluate.m";
<< "preview.m";
processEvaluate[jsonData_] := Module[{result, requestData, answer, response, params, type},
requestData = jsonData["params"];
answer = requestData["answer"];
response = requestData["response"];
params = requestData["params"];
type = params["type"];
Print["Evaluating Response Against Answer"];
result = EvaluationFunction[type, answer, response, params];
Print["Output: ", result];
If[result["error"] != Null,
Return[
<| "command" -> "eval",
"error" -> <|
"message" -> result["error"]
|>
|>
]
];
<| "command" -> "eval",
"result" -> <|
"is_correct" -> result["is_correct"],
"feedback" -> result["feedback"]
|>
|>
]
processPreview[jsonData_] := Module[{result, requestData, response},
requestData = jsonData["params"];
response = requestData["response"];
Print["Previewing Response"];
result = PreviewFunction[response];
Print["Result: ", result];
If[result["error"] != Null,
Return[
<| "command" -> "eval",
"error" -> <|
"message" -> result["error"]
|>
|>
]
];
<| "command" -> "preview",
"result" ->
<|"preview" -> result|>
|>
]
evalQuestionIO = Function[
Module[{jsonData, command, resultAssoc, response},
jsonData = Import[#1, "JSON"] //. List :> Association;
Print["Input"];
Print[jsonData];
command = Lookup[jsonData, "command", "unknown"];
resultAssoc = Which[
command == "eval", processEvaluate[jsonData],
command == "preview", processPreview[jsonData],
True, <| "status" -> "error", "message" -> "Incorrect command" |>
];
Print["Outputted JSON"];
Print[resultAssoc];
Export[#2, resultAssoc, "JSON", "Compact" -> True]
]
];
argv = Rest[$ScriptCommandLine];
evalQuestionIO[argv[[1]], argv[[2]]]