Skip to content

Commit 136a298

Browse files
committed
Improved local documentation for llm
1 parent 13f3f4c commit 136a298

4 files changed

Lines changed: 5718 additions & 5688 deletions

File tree

modules/wljs-api/src/Frontend.wl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,24 @@ apiCall[request_, "/api/docs/"] := {
168168
"/api/docs/find/"
169169
}
170170

171+
getNLinesAfter[url_, query_, n_:40] := Module[{stream = OpenRead[url], skipping = False},
172+
If[!StringQ[Find[stream, query]], Close[stream]; Return[$Failed]];
173+
With[{res = StringRiffle[Table[With[{line = ReadLine[stream]},
174+
If[StringMatchQ[line, (StartOfString~~"# "~~___) | "Please visit the official [Wolfram Language Reference]"~~___] || skipping, skipping = True; Nothing, line]
175+
], {n}], "\n"]},
176+
Close[stream];
177+
res
178+
]
179+
]
180+
171181

172182
apiCall[request_, "/api/docs/find/"] := With[{
173183
query = request["Body"]["Query"],
174-
wordSearch = Lookup[request["Body"], "WordSearch", True]
184+
number = ToExpression@Lookup[request["Body"], "LinesCount", 40]
185+
}, {
186+
found = getNLinesAfter[getLLMFile, "# "<>StringTrim[query], number]
175187
},
176-
FindList[getLLMFile, query, 5, WordSearch->wordSearch]
188+
If[!StringQ[found], failure["No results"], found]
177189
]
178190

179191
(*

0 commit comments

Comments
 (0)