From 346b8ba8fdf634ff4b48b0b8c041a509ad1c9d5d Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Wed, 6 Aug 2025 16:12:53 +0100 Subject: [PATCH 1/5] Refactored feedback to own variable and added example input.json --- evaluation_function.wl | 73 +++++++++++++++++++++--------------------- input.json | 10 ++++++ 2 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 input.json diff --git a/evaluation_function.wl b/evaluation_function.wl index 024c90a..f99fb1e 100644 --- a/evaluation_function.wl +++ b/evaluation_function.wl @@ -2,42 +2,43 @@ including to within a given tolerance; input and output as Associations *) -equalQAssociation = - Function[ - Module[{tolerance, correctQ, error}, - If[NumericQ[#answer], - tolerance = - If[#params["tolerance_is_absolute"], - #params["tolerance"] - , - #params["tolerance"] * #params["answer"] - ]; - error = Abs[#answer - #response]; - correctQ = TrueQ[error <= tolerance] - , - error = "not applicable"; - correctQ = TrueQ[#answer == #response] - ]; - <| - "command" -> "eval" - , - "result" -> - { - "is_correct" -> correctQ - , - "feedback" -> - If[correctQ, - #params["correct_response_feedback"] - , - #params["incorrect_response_feedback" - ] - ] - , - "error" -> error - } - |> - ] - ]; +equalQAssociation = + Function[input, + Module[{tolerance, correctQ, error, answer, response, params}, + answer = input["answer"]; + response = input["response"]; + params = input["params"]; + + If[NumericQ[answer], + tolerance = + If[TrueQ[params["tolerance_is_absolute"]], + params["tolerance"], + params["tolerance"] * answer + ]; + error = Abs[answer - response]; + correctQ = TrueQ[error <= tolerance], + error = "not applicable"; + correctQ = TrueQ[answer == response] + ]; + + feedback = + If[correctQ, + params["correct_response_feedback"] + , + params["incorrect_response_feedback"] + ]; + + + <| + "command" -> "eval", + "result" -> <| + "is_correct" -> correctQ, + "feedback" -> feedback + |> + |> + ] + ]; + (* A function to test whether a response is equal to an answer, \ including to within a given tolerance; input and output as diff --git a/input.json b/input.json new file mode 100644 index 0000000..2a05b9a --- /dev/null +++ b/input.json @@ -0,0 +1,10 @@ +{ + "answer": 1, + "response": 1, + "params": { + "tolerance": 0.01, + "tolerance_is_absolute": true, + "correct_response_feedback": "Correct!", + "incorrect_response_feedback": "Try again." + } +} From 45e7278c2b0be18a4f9219a49353783975335f1f Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Mon, 11 Aug 2025 15:54:23 +0100 Subject: [PATCH 2/5] Simplified Dockerfile and updated README to use commands that work --- Dockerfile | 13 +++---------- README.md | 8 ++++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 53545af..d867a61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest +#FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest +FROM wolfram-base:latest # Command to start the evaluation function with ENV FUNCTION_COMMAND="wolframscript" @@ -12,12 +13,4 @@ ENV FUNCTION_INTERFACE="file" ENV LOG_LEVEL="DEBUG" # Copy the evaluation function to the app directory -COPY ./evaluation_function.wl /app/evaluation_function.wl - -RUN apt-get update && apt-get install -y \ - libglib2.0-0 \ - && rm -rf /var/lib/apt/lists/* - -COPY --from=wolframresearch/wolframengine:12.3.1 \ - /usr/local/Wolfram/WolframEngine/12.3/SystemFiles/Libraries/Linux-x86-64/libiomp5.so \ - /usr/local/Wolfram/WolframEngine/13.3/SystemFiles/Libraries/Linux-x86-64/libiomp5.so \ No newline at end of file +COPY ./evaluation_function.wl /app/evaluation_function.wl \ No newline at end of file diff --git a/README.md b/README.md index c5a4e7c..71b1128 100644 --- a/README.md +++ b/README.md @@ -29,14 +29,14 @@ In[1] := $PasswordFile // FilePrint 1e1d781ed0a3 6520-03713-97466 4304-2718-2K5ATR 5095-179-696:2,0,8,8:80001:20190627 ``` -This gives you a password that you can copy to a `mathpass` file on your host machine. +This gives you a password that you can copy to a `mathpass` file on your host machine. Recommended to store in the `local directory/Licensing` -**4. Run the Wolfram Engine container** +**4. Run the Evaluation Function container** Run the following command to start the Wolfram Engine container with the license: ```bash -docker run -it --rm -v $(pwd)/mathpass:/home/wolframengine/.WolframEngine/Licensing/mathpass wolframresearch/wolframengine +docker run -it --rm -v $(pwd)/Licensing:/home/wolframengine/.WolframEngine/Licensing/ {evaluation_function_tag} ``` -This command assumes that you have a `mathpass` file in the current directory, and the container is started with the `wolframengine` user. +This command assumes that you have a `mathpass` file in the Licensing directory, and the container is started with the `wolframengine` user. From 03d0dcf91930fef80235e0fbae6c1d84a14dc4e1 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Mon, 11 Aug 2025 16:09:28 +0100 Subject: [PATCH 3/5] Updated Dockerfile to pull from Github Images instead of local image --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d867a61..c00842e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -#FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest -FROM wolfram-base:latest +FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest # Command to start the evaluation function with ENV FUNCTION_COMMAND="wolframscript" From 5c90eab1a38a89034a60b00e8838fee575d3e1c7 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Tue, 12 Aug 2025 10:31:48 +0100 Subject: [PATCH 4/5] Fixed incorrect reading of JSON input --- Dockerfile | 3 ++- evaluation_function.wl | 18 +++++++++--------- input.json | 15 +++++++++------ 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index c00842e..d867a61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest +#FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest +FROM wolfram-base:latest # Command to start the evaluation function with ENV FUNCTION_COMMAND="wolframscript" diff --git a/evaluation_function.wl b/evaluation_function.wl index f99fb1e..eca7a08 100644 --- a/evaluation_function.wl +++ b/evaluation_function.wl @@ -4,11 +4,13 @@ Associations *) equalQAssociation = Function[input, - Module[{tolerance, correctQ, error, answer, response, params}, - answer = input["answer"]; - response = input["response"]; - params = input["params"]; - + Module[{data, tolerance, correctQ, error, answer, response, params, feedback}, + (*Get the evaluation parameters from the incoming request*) + data = input["params"]; + answer = data["answer"]; + response = data["response"]; + params = data["params"]; + If[NumericQ[answer], tolerance = If[TrueQ[params["tolerance_is_absolute"]], @@ -23,12 +25,10 @@ equalQAssociation = feedback = If[correctQ, - params["correct_response_feedback"] - , + params["correct_response_feedback"], params["incorrect_response_feedback"] ]; - <| "command" -> "eval", "result" -> <| @@ -58,6 +58,6 @@ Calls equalQAssociation *) equalQIO = Function[Export[#2, equalQAssociation[Import[#1, "JSON"] //. List :> Association], "JSON", "Compact" -> True]]; -argv = Rest[$ScriptCommandLine] +argv = Rest[$ScriptCommandLine]; equalQIO[argv[[1]], argv[[2]]] diff --git a/input.json b/input.json index 2a05b9a..31add5a 100644 --- a/input.json +++ b/input.json @@ -1,10 +1,13 @@ { - "answer": 1, - "response": 1, + "method": "eval", "params": { - "tolerance": 0.01, - "tolerance_is_absolute": true, - "correct_response_feedback": "Correct!", - "incorrect_response_feedback": "Try again." + "answer": 1, + "response": 1, + "params": { + "tolerance": 0.01, + "tolerance_is_absolute": true, + "correct_response_feedback": "Correct!", + "incorrect_response_feedback": "Try again." + } } } From 83020e775304dc1c6a5da80aadff124deb569b34 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Tue, 12 Aug 2025 10:42:17 +0100 Subject: [PATCH 5/5] Updated Dockerfile to use GHCR. --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d867a61..c00842e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -#FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest -FROM wolfram-base:latest +FROM ghcr.io/lambda-feedback/evaluation-function-base/wolfram:latest # Command to start the evaluation function with ENV FUNCTION_COMMAND="wolframscript"