Docstrings generation
Index
CTBaseDocstrings.extract_docstring_code_pairsCTBaseDocstrings.handled_doc_appCTBaseDocstrings.html_code_doc_app
In the examples in the documentation below, the methods are not prefixed by the module name even if they are private.
julia> using CTBase
julia> x = 1
julia> private_fun(x) # throw an errormust be replaced by
julia> using CTBase
julia> x = 1
julia> CTBase.private_fun(x)However, if the method is reexported by another package, then, there is no need of prefixing.
julia> module OptimalControl
import CTBase: private_fun
export private_fun
end
julia> using OptimalControl
julia> x = 1
julia> private_fun(x)Documentation
CTBase.doc_app — Methoddoc_app(_::CTBase.DocstringsAppTag)
Launches the Julia Docstrings Generator web app on localhost.
Starts an HTTP server on port 8080 and prints the local URL for access.
Arguments
::CTBase.DocstringsAppTag: A dispatch tag used to identify this application.
Returns
nothing: This function runs the server and does not return a result.
Example
julia> CTBase.doc_app(CTBase.DocstringsAppTag())
Open http://localhost:8080 in your browser.CTBaseDocstrings.handled_doc_app — Methodhandled_doc_app(req) -> HTTP.Messages.Response
Handles HTTP requests to serve the web app interface, process user-submitted code, and shut down the server.
Arguments
req: An HTTP request object representing an incoming request to the server.
Returns
response::HTTP.Response: An appropriate HTTP response depending on the request path and method.
Example
julia> using HTTP
julia> req = HTTP.Request("GET", "/");
julia> resp = handled_doc_app(req)
HTTP.Response(200 OK)CTBaseDocstrings.html_code_doc_app — Methodhtml_code_doc_app() -> String
Returns the HTML string for the Julia Docstrings/Prompt Generator web app.
This HTML includes the structure, layout, and style definitions required for a client-side interface with dark/light mode support, tabs for input areas, and interactive elements.
Returns
html::String: A complete HTML string to be served as the main page of the application.
Example
julia> html = html_code_doc_app();
julia> occursin("DOCTYPE html", html)
trueCTBase.docstrings — Methoddocstrings(
path::String;
complement,
tests,
context,
apikey
) -> Tuple{Vector{Any}, String}
Sends code and optional context to the Mistral API and extracts generated docstrings.
Arguments
path::String: Path to the Julia source file.complement: Optional path to a complement file (defaultnothing).tests: Optional path to a test file (defaultnothing).context: Optional path to a context file for better generation (defaultnothing).apikey::String: Mistral API key (default empty).
Returns
(pairs, response)::Tuple{Vector{Tuple{String, String}}, String}: A tuple containing extracted docstring-code pairs and a reconstructed version of the code with inserted docstrings.
Example
julia> CTBase.docstrings("example.jl", apikey="sk-...")
([("Docstring", "function f(x) ... end")], "...full reconstructed text...")CTBaseDocstrings.extract_docstring_code_pairs — Methodextract_docstring_code_pairs(
ai_text::String
) -> Tuple{Vector{Any}, String}
Extracts pairs of docstrings and code blocks from the given AI-generated text.
Arguments
ai_text::String: The full string response from the AI, possibly containing multiple docstring-code pairs.
Returns
(pairs, reponse)::Tuple{Vector{Tuple{String,String}}, String}: A tuple containing a vector of(docstring, code)pairs and a string reconstruction with triple-quoted docstrings prepended.
Example
julia> text = """"Docstring"""
function f(x)
x + 1
end
";
julia> extract_docstring_code_pairs(text)
(("Docstring", "function f(x)
x + 1
end"), ...)CTBase.generate_prompt — Methodgenerate_prompt(
code_text::String,
complement_text::String,
tests_text::String,
context_text::String
) -> String
Generates a well-structured and precise prompt to produce Julia docstrings in the Documenter.jl style, using provided code, tests, and context.
Arguments
code_text::String: The Julia code (structs and functions) to document.complement_text::String: Optional complement to the prompt.tests_text::String: Optional related tests for improving examples.context_text::String: Additional domain knowledge or technical explanation to improve doc quality.
Returns
prompt::String: A clear prompt ready for use with a language model like ChatGPT or Mistral.
Example
julia> code = "function square(x); x^2; end"
julia> CTBase.generate_prompt(code, "Write in UK english.", "", "")
"Your task is to write docstrings for the following Julia code..."