summaryrefslogtreecommitdiff
path: root/lib/open_ai.ex
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2022-12-09 17:33:00 +0000
committerJordan Bracco <href@random.sh>2022-12-11 02:03:36 +0000
commitc88f2454f1cedb497131e6f1fa4429bd3a38185f (patch)
treefac2b19146e959bd2bd35d9f4388edf0cd0a226f /lib/open_ai.ex
parentnew plugin: openai gpt (diff)
gpt improvements
Diffstat (limited to 'lib/open_ai.ex')
-rw-r--r--lib/open_ai.ex10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/open_ai.ex b/lib/open_ai.ex
index 9feb9a4..e28a610 100644
--- a/lib/open_ai.ex
+++ b/lib/open_ai.ex
@@ -11,6 +11,16 @@ defmodule OpenAi do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} <- HTTPoison.post(url, json, headers, options),
{:ok, data} <- Poison.decode(body) do
{:ok, data}
+ else
+ {:ok, %HTTPoison.Response{status_code: 400}} -> {:error, :bad_request}
+ {:ok, %HTTPoison.Response{status_code: 402}} -> {:error, :payment_required}
+ {:ok, %HTTPoison.Response{status_code: 403}} -> {:error, :forbidden}
+ {:ok, %HTTPoison.Response{status_code: 429}} -> {:error, :too_many_requests}
+ {:ok, %HTTPoison.Response{status_code: 500}} -> {:error, :internal_error}
+ {:ok, %HTTPoison.Response{status_code: 503}} -> {:error, :service_unavailable}
+ {:ok, %HTTPoison.Response{status_code: code}} -> {:error, String.to_atom("http #{code}")}
+ {:error, %HTTPoison.Error{reason: reason}} -> {:error, reason}
+ error -> error
end
end