Skip to content

Instantly share code, notes, and snippets.

@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",
@ztangent
ztangent / make.jl
Last active April 3, 2022 04:39
Documenter.jl workaround for custom HTML meta tags
using Documenter, PDDL
# Include workaround to inject custom meta tags
include("metatags.jl")
# Add custom metatags
empty!(CUSTOM_META_TAGS)
PREVIEW_IMAGE_URL =
"YOUR PREVIEW URL HERE"
SITE_DESCRIPTION =
@ztangent
ztangent / rand_bw.jl
Last active January 12, 2022 22:46
Random Blocksworld State Generator
"""
A Julia implementation of the random Blocksworld state generation algorithm presented in Figure 2 of [1].
Note that this implementation fixes a minor bug in the pseudo-code provided by [1].
[1] Slaney, J. and Thiébaux, S., 2001. Blocks World Revisited. Artificial Intelligence, 125(1-2), pp.119-153.
DOI: https://doi.org/10.1016/S0004-3702(00)00079-5
"""
"Number of states with `N` blocks."
function nstates(N::Int)
@ztangent
ztangent / trunc_normal.jl
Created September 21, 2021 19:52
Gen Truncated Normal Distribution
using Gen
using Distributions: truncated
struct TruncatedNormal <: Gen.Distribution{Float64} end
"""
trunc_normal(mu::Real, std::Real, lb::Real, ub::Real)
Samples a `Float64` value from a normal distribution.
"""
const trunc_normal = TruncatedNormal()