I don’t seem to be able to append/update :private from within the into: fun
def transcribe_audio(url, callback) do
req =
Req.new(
url: "http://faster-whisper-server-patient-voice-8559.flycast/v1/audio/transcriptions",
connect_options: [transport_opts: [inet6: true]],
receive_timeout: 120_000
)
file_path =
file_path_from_url(
"https://s3-us-west-2.amazonaws.com/moth-social/media_attachments/files/113/087/363/649/463/883/original/6f9b1ad7ff1c0018.mp3"
)
multipart =
Multipart.new()
|> Multipart.add_part(Multipart.Part.text_field("true", "stream"))
|> Multipart.add_part(Multipart.Part.file_field(file_path, "file"))
content_length = Multipart.content_length(multipart)
content_type = Multipart.content_type(multipart, "multipart/form-data")
headers = [
{"Content-Type", content_type},
{"Content-Length", to_string(content_length)}
]
{:ok, response} =
Req.post(
req,
headers: headers,
body: Multipart.body_stream(multipart),
into: fn {:data, data}, {req, resp} ->
# try to add any value to the response
Req.Response.put_private(resp, :transcription, [{%{:b => "moe"}}])
results = parse(data)
segment = Enum.at(results.segments, 0)
callback.(trunc(segment.start), segment.text)
# update private response
Req.Response.update_private(resp, :transcript, [], fn state -> [results | state] end)
IO.inspect(resp.private)
{:cont, {req, resp}}
end
)
Req.Response.put_private(response, :something_else, [{%{:a => "ted"}}])
# Make sure we shut the agent down
# data_results = Agent.get(agent, & &1) |> Enum.reverse()
# :ok = Agent.stop(agent)
# data_results
end
the put_private or update_private from the into: fun are not on the return response, but the final put_private is added
#Req.Response<
status: 200,
headers: %{
"content-type" => ["text/event-stream; charset=utf-8"],
"date" => ["Thu, 05 Sep 2024 23:39:26 GMT"],
"fly-request-id" => ["01J728X25018F47F3W0KD31EJ1-ord"],
"server" => ["Fly/813cb6e67 (2024-09-03)"],
"transfer-encoding" => ["chunked"],
"via" => ["1.1 fly.io"]
},
body: "",
trailers: %{},
private: %{something_else: [{%{a: "ted"}}]},
...
>






















