JuliaZoid

Your home for Julia programming articles on Medium! Share your Julia learnings, projects, and packages with the world. By the community, for the community!

Follow publication

Automatically generate comments for your Julia code with OpenAI.jl and GPT-3

Logan Kilpatrick
JuliaZoid
Published in
8 min readDec 2, 2022

--

Image by Author
GIF from the OpenAI Blog: https://openai.com/blog/gpt-3-edit-insert/

Getting Started with the OpenAI API 🧠

Image captured by Author
Image captured by Author

Installing the OpenAI Package 📦

(@v1.7) pkg> add openai

Making Our First Request 🥇

using OpenAIlist_models_response = list_models("insert-api-key-here")print(list_models_response.response)
edit_response = create_edit("api-key-here", "text-davinci-edit-001", "Fix the spelling mistakes", input="What day of the wek is it?")print(edit_response.response)
Dict{String, Any} with 4 entries:
"choices" => Any[Dict{String, Any}("text"=>"What day of the week is it?\n", "index"=>0)]
"usage" => Dict{String, Any}("completion_tokens"=>28, "total_tokens"=>53, "prompt_tokens"=>25)
"object" => "edit"
"created" => 1666731677

Taking things up a notch — Let’s document your Julia Code ✍️

x = Dict("a"=>"A", "b"=>"B", "c"=>"C")

for (key, value) in x
print(key); print(value)
end
# Remove new lines and replace them with \n using https://www.gillmeister-software.com/online-tools/text/remove-line-breaks.aspx# for (key, value) in x\nprint(key); print(value)\nendedit_response = create_edit("api-key-here", "text-davinci-edit-001", "Add a comment explaining what this for loop does", input="for (key, value) in x\nprint(key); print(value)\nend")
// Silly example 00\nfor (key, value) in x\nprint(key); print(value)\n end\n
# iterate over key,value pairs\nfor (key, value) in x\nprint(key); print(value)\n end\n
# layer = Conv(weight, bias, sigmoid)response = create_edit("api-key-here", "text-davinci-edit-001", "Add a comment explaining what each argument does in the function call", input="layer = Conv(weight, bias, sigmoid)")
#This creates an object taht contains three parameters\nlayer = Conv(weight, bias, sigmoid)\n# The veritcal size of the output should be n_filters, \n# the horizontal size should be the input size minus the filter size,\n#  divided by the stride and plus one.\n\n# layer -> image 1 , weight -> image 2 , bias -> scalar value, stride -> scalar value\n# sigmoid -> flag: if set(1), the activation function is the sigmoid functionlayer = Conv(weight, bias, sigmoid)

Other parameters to play around with 🛝

response = create_edit("api-key-here", "text-davinci-edit-001", "Add a comment explaining what this for loop does", input="for (key, value) in x\nprint(key); print(value)\n end", n=2, temperature=0.8)

Wrapping Things Up + Resources 🎁

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in JuliaZoid

Your home for Julia programming articles on Medium! Share your Julia learnings, projects, and packages with the world. By the community, for the community!

Written by Logan Kilpatrick

Lead product for Google AI Studio, working on the Gemini API, and AGI. Ex-OpenAI.

Responses (1)