Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
cbh123 committed May 26, 2023
1 parent 8ba7e37 commit 9147d3d
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
replicate-*.tar

# Temporary files, for example, from tests.
/tmp/
16 changes: 16 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "mix",
"task": "Run tests in current file",
"problemMatcher": [
"$mixCompileError",
"$mixCompileWarning",
"$mixTestFailure"
],
"group": "test",
"label": "mix: Run tests in current file"
}
]
}
Empty file added CHANGELOG.md
Empty file.
53 changes: 53 additions & 0 deletions lib/predictions.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
defmodule Replicate.Predictions do
@moduledoc """
Documentation for `Predictions`.
"""

@doc """
Hello world.
## Examples
iex> Replicate.Predictions.hello()
:world
"""
@host "https://api.replicate.com"

def hello do
:world
end

defp header() do
# should be a struct
[
Authorization: "Token #{System.fetch_env!("REPLICATE_TOKEN")}",
"Content-Type": "application/json"
]
end

def new(version, input) do
body =
Jason.encode!(%{
"version" => version,
"input" => input
})

case HTTPoison.post!(@host, body, header()) do
%HTTPoison.Response{status_code: 201, body: body} ->
{:ok, body}

%HTTPoison.Response{body: body} ->
detail = Jason.decode!(body)["detail"]
{:error, detail}
end
end

def get(prediction_id) do
HTTPoison.get!("#{@host}/#{prediction_id}", header())
end

def cancel(prediction_id) do
# todo
end
end
20 changes: 20 additions & 0 deletions lib/replicate.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule Replicate do
@moduledoc """
Documentation for `Replicate`.
"""

@doc """
Hello world.
## Examples
iex> Replicate.hello()
:world
"""
@host "https://api.replicate.com"

def hello do
:world
end
end
47 changes: 47 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule Replicate.MixProject do
use Mix.Project

def project do
[
app: :replicate,
version: "0.1.0",
elixir: "~> 1.14",
start_permanent: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
description: description(),
package: package(),
deps: deps(),
name: "Replicate",
source_url: "https://github.com/cbh123/replicate-elixir"
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:httpoison, "~> 1.8"},
{:jason, "~> 1.2"}
]
end

defp description() do
"The official Elixir client for Replicate. It lets you run models from your Elixir code, and everything else you can do with Replicate's HTTP API."
end

defp package() do
[
# These are the default files included in the package
files: ~w(lib .formatter.exs mix.exs README* CHANGELOG*),
licenses: ["Apache-2.0"],
links: %{"GitHub" => "https://github.com/cbh123/replicate-elixir"}
]
end
end
12 changes: 12 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%{
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},
"hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~> 2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"},
"httpoison": {:hex, :httpoison, "1.8.2", "9eb9c63ae289296a544842ef816a85d881d4a31f518a0fec089aaa744beae290", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "2bb350d26972e30c96e2ca74a1aaf8293d61d0742ff17f01e0279fef11599921"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}
13 changes: 13 additions & 0 deletions test/replicate_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule ReplicateTest do
use ExUnit.Case
doctest Replicate
doctest Replicate.Predictions

test "greets the world" do
assert Replicate.hello() == :world
end

test "new prediction" do
assert Replicate.Predictions.hello() == :world
end
end
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()

0 comments on commit 9147d3d

Please sign in to comment.