Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tesla Response Stream is not compatible with Tesla Multipart upload #648

Open
elijahkim opened this issue Jan 5, 2024 · 0 comments
Open

Comments

@elijahkim
Copy link

I've been trying to stream an upload from GCP Cloud Storage to OpenAi using Tesla and I'm running into issues that I think has to do with Tesla. The code looks similar to this:

def get_stream(bucket, object) do
    {:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/cloud-platform")

    Tesla.client(
      [{Tesla.Middleware.Headers, [{"authorization", "Bearer #{token.token}"}]}],
      {Tesla.Adapter.Mint, [body_as: :stream]}
    )
    |> GoogleApi.Storage.V1.Api.Objects.storage_objects_get(
      bucket,
      object,
      [alt: "media"]
    )
end

def upload(stream) do
    body =
      Multipart.new()
      |> Multipart.add_file_content(stream, "file.mp4")
      |> Multipart.add_field("model", "whisper-1")
      |> Multipart.add_field("response_format", "json")

    post("v1/audio/transcriptions", body)
end

{:ok, resp} = get_stream("foo", "bar")

upload(resp.body)

The response from GCP returns a stream that is a function/2 and if I try to use that directly in upload/1 I get an error due to https://github.com/elixir-tesla/tesla/blob/master/lib/tesla/multipart.ex#L189. I also tried turning the function into a stream doing Stream.map(env.body, &Function.identity/1) but that seems to just hang before doing the upload. The last thing I tried was adding is_function into the guard that checks if the part is a valid type but that hangs as well.

I tried spelunking a bit deeper into Tesla but can't seem to figure out exactly how it works or else I would've tried opening a PR. Any help will be appreciated.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant