Skip to content

Instantly share code, notes, and snippets.

View stefanjwojcik's full-sized avatar
Merging the parallel universes of social science and computing

Stefan Wojcik stefanjwojcik

Merging the parallel universes of social science and computing
View GitHub Profile
@ztangent
ztangent / gpt3_api.jl
Created December 5, 2022 14:53
Julia interface for the OpenAI's GPT-3 API
using HTTP, JSON3
"Call the OpenAI JSON API and return the results."
function gpt3_api_call(
prompt, n_completions::Int=1;
endpoint::String = "https://api.openai.com/v1/completions",
api_key::String = get(ENV, "OPENAI_API_KEY", ""),
organization::String = get(ENV, "OPENAI_ORGANIZATION", ""),
n_retries::Int = 10,
model::String = "text-davinci-003",