Skip to content

Commit

Permalink
update with newest
Browse files Browse the repository at this point in the history
  • Loading branch information
leeduckgo committed Dec 11, 2023
1 parent 21b1190 commit bc0df68
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ config :tai_shang_micro_faas_system,
did_mainnet: "0x61b96051f553d767d7e6dfcc04b04c28d793c8af3d07d3a43b4e2f8f4ca04c9f",
did_testnet: "0xc71124a51e0d63cfc6eb04e690c39a4ea36774ed4df77c00f7cbcbc9d0505b2c",
api_key: System.get_env("API_KEY"),
admin_key: System.get_env("ADMIN_KEY")
admin_key: System.get_env("ADMIN_KEY"),
clipdrop_key: System.get_env("CLIPDROP_KEY")

config :cors_plug,
max_age: 2592000,
Expand Down
16 changes: 16 additions & 0 deletions lib/components/ai_pic.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule Components.AiPic do

@api %{text_to_image: "https://clipdrop-api.co/text-to-image/v1"}
alias Components.ExHttp
def text_to_image(txt) do
end

def do_text_to_image(txt) do
IO.puts inspect Constants.clipdrop_key()
body = "prompt=#{txt}"
heads =
[{"Content-Type", "text/plain"}, {"x-api-key", Constants.clipdrop_key()}]
IO.puts inspect heads
ExHttp.http_post(@api.text_to_image, body, heads, 3)
end
end
26 changes: 26 additions & 0 deletions lib/components/ex_http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ defmodule Components.ExHttp do
{:error, "POST retires #{@retries} times and not success"}
end

def http_post(_url, _data, _, retries) when retries == 0 do
{:error, "POST retires #{@retries} times and not success"}
end

def http_post(url, data, heads, retries) do
body = Poison.encode!(data)

url
|> HTTPoison.post(
body,
# [{"User-Agent", @default_user_agent}, {"Content-Type", "text/plain"}]
heads,
hackney: [headers: [{"User-Agent", @default_user_agent}]]
)
|> handle_response()
|> case do
{:ok, body} ->
{:ok, body}
{:error, 404} ->
{:error, 404}
{:error, _} ->
Process.sleep(500)
http_post(url, data, heads, retries - 1)
end
end

def http_post(url, data, retries) do
body = Poison.encode!(data)

Expand Down
5 changes: 5 additions & 0 deletions lib/utils/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ defmodule Constants do
def get_admin_key() do
Application.fetch_env!(:tai_shang_micro_faas_system, :admin_key)
end

def clipdrop_key() do
:tai_shang_micro_faas_system
|> Application.fetch_env!(:clipdrop_key)
end
end

0 comments on commit bc0df68

Please sign in to comment.