diff options
author | href <href@random.sh> | 2022-12-03 02:00:37 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-11 02:03:36 +0000 |
commit | 251ea43c1308eb96e4ada16edf6481a8be1fa765 (patch) | |
tree | 2148e304574c684f7eb1e74607634a907df9085d /lib/open_ai.ex | |
parent | new plugin: radio france (diff) |
new plugin: openai gpt
Diffstat (limited to 'lib/open_ai.ex')
-rw-r--r-- | lib/open_ai.ex | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/open_ai.ex b/lib/open_ai.ex new file mode 100644 index 0000000..9feb9a4 --- /dev/null +++ b/lib/open_ai.ex @@ -0,0 +1,17 @@ +defmodule OpenAi do + + def post(path, data, options \\ []) do + config = Application.get_env(:lsg, :openai, []) + url = "https://api.openai.com#{path}" + headers = [{"user-agent", "internal private experiment bot, href@random.sh"}, + {"content-type", "application/json"}, + {"authorization", "Bearer " <> Keyword.get(config, :key, "unset-api-key")}] + options = options ++ [timeout: :timer.seconds(180), recv_timeout: :timer.seconds(180)] + with {:ok, json} <- Poison.encode(data), + {:ok, %HTTPoison.Response{status_code: 200, body: body}} <- HTTPoison.post(url, json, headers, options), + {:ok, data} <- Poison.decode(body) do + {:ok, data} + end + end + +end |