Skip to content

Commit

Permalink
Merge pull request #77 from yangcancai/main
Browse files Browse the repository at this point in the history
Optimizing Tesla client to convert text to image api
  • Loading branch information
leeduckgo authored Dec 12, 2023
2 parents 5a06375 + 9f8caec commit 949fe00
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/components/ai_pic.ex
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
defmodule Components.AiPic do


use HTTPoison.Base
@base "https://clipdrop-api.co"

def text_to_image(txt) do
end

def client() do
Tesla.client([
# TODO: convert input/output type
{Tesla.Middleware.BaseUrl, @base},
{Tesla.Middleware.Headers, [{"content-type", "text/plain"}, {"x-api-key", Constants.clipdrop_key()}]},
{Tesla.Middleware.JSON, engine_opts: [keys: :atoms]}
{Tesla.Middleware.Headers, [{"x-api-key", Constants.clipdrop_key()}]}
])
end

def run do
client() |>
do_text_to_image("Draw a dancing dog")
end
def do_text_to_image(client, prompt) do
mp =
Tesla.Multipart.new()
|> Tesla.Multipart.add_file_content("prompt=#{prompt}", "sample.txt")
Tesla.post(client, "/text-to-image/v1", "prompt=#{prompt}")
mp = Tesla.Multipart.new()
|> Tesla.Multipart.add_content_type_param("charset=utf-8")
|> Tesla.Multipart.add_field("prompt", prompt,
headers: [{"content-type", "text/plain"}]
)
Tesla.post(client, "/text-to-image/v1", mp)
end
# def do_text_to_image(txt) do
# IO.puts inspect Constants.clipdrop_key()
# body = "prompt=#{txt}"
# heads =
# 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)
Expand All @@ -37,15 +39,15 @@ defmodule Components.AiPic do
# {"Content-Type", "text/plain"}
# ]

# body =
# body =
# "prompt=#{prompt}"

# response = post!(
# @api.text_to_image,
# @api.text_to_image,
# {headers, :multipart, body}
# )
# # [:file, output_file])
# {:ok, response}
# end

end
end

0 comments on commit 949fe00

Please sign in to comment.