Skip to content

Commit d2624c0

Browse files
committed
Successfully deployed preview API
1 parent e24cd0c commit d2624c0

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

deploy.wls

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env wolframscript
2+
3+
packagePath = FileNameJoin[{Directory[], "Preview.m"}];
4+
5+
If[!FileExistsQ[packagePath],
6+
Print["Error: file not found at " <> packagePath];
7+
Abort[];
8+
];
9+
10+
(* Load the package locally first *)
11+
Get[packagePath];
12+
13+
(* Test locally *)
14+
Print["Testing locally:"];
15+
Print[preview`PreviewFunction["x^2"]];
16+
17+
18+
19+
(* Deploy the API with explicit JSON export *)
20+
api = APIFunction[
21+
{"response" -> "String"},
22+
ExportForm[preview`PreviewFunction[#response], "JSON"] &
23+
];
24+
25+
obj = CloudDeploy[api, "preview-api", Permissions -> "Public"];
26+
27+
Print["API deployed to: ", obj];

preview.m

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
(* For new style packages see: https://mathematica.stackexchange.com/a/176489) *)
1616
(* Declare package context *)
17-
BeginPackage["preview`"]
17+
BeginPackage["preview`"];
1818

19-
PreviewFunction[response_] := Module[{parsedResponse, latexString, wolframString},
19+
PreviewFunction[response_] := Module[{latexString, wolframString, parsedResponse},
2020
Print["Running Preview Function"];
2121
Print["Preview Input:", response];
2222

@@ -32,23 +32,17 @@
3232
]
3333
];
3434

35-
latexString = ToString[TeXForm[parsedResponse]];
36-
wolframString = ToString[InputForm[parsedResponse]];
35+
latexString = ToString[parsedResponse, TeXForm];
36+
wolframString = ToString[parsedResponse, InputForm];
3737

38-
(* Below is the current format expected by Lambda Feedback. Both the latex and sympy fields are currently required.
39-
To suggest that sympy gets renamed to parsed-expression or similar.*)
4038
<|
41-
"command" -> "preview",
42-
"result" -> <|
43-
"preview" -> <|
44-
"latex" -> latexString,
45-
"sympy" -> wolframString
46-
|>
47-
|>
48-
|>
49-
]
39+
"parsedResponse" -> ToString[parsedResponse],
40+
"latexString" -> latexString,
41+
"sympyString" -> wolframString
42+
|>
43+
];
5044

51-
Begin["`Private`"]
45+
Begin["`Private`"];
5246

5347
SafeToExpression[str_String] :=
5448
Module[{expr, result},
@@ -85,5 +79,5 @@
8579

8680

8781

88-
End[]
89-
EndPackage[]
82+
End[];
83+
EndPackage[];

0 commit comments

Comments
 (0)