ALLM.Providers.Support.TranscriptionAdapter behaviour (allm v0.6.1)

Copy Markdown View Source

The shared half of the bundled ALLM.TranscriptionAdapter implementations.

Layer B helper. Every bundled transcription adapter follows the same contract around its provider-specific request building and decoding:

  • The test-injection hand-off: under opts[:adapter_opts][:transcription_script] the call goes to ALLM.Providers.FakeTranscription before any gate runs, with adapter_opts[:max_audio_bytes] set to the adapter's own cap.
  • Gate order: audio that cannot be resolved, then audio over the adapter's byte cap, both before ALLM.Keys.fetch!/2.
  • One HTTP attempt per call, with no retry loop.
  • Jason.DecodeError causes are sanitised before they reach an error.
  • Span flags: gate_flags/4 refuses a timestamps: true or logprobs: true the adapter cannot honour with :unsupported_feature, with_span_flags/2 carries the supported list into the Fake hand-off, span_from/6 drops every attribute the request did not ask for, decode_span_list/3 walks a provider's span list, and absent_spans/5 applies the one rule for a response that carries no span data ([] on a blank transcript, else :unsupported_feature).

The functions are @doc false seams parameterised by the provider atom (the :provider of every error built here). Where the flow needs the adapter's own steps, the adapter module is an argument and these callbacks are invoked on it: gate_audio/2, build_request/2, decode_response/4, to_transcription_adapter_error/4 and malformed_error/2. They are declared as this module's callbacks, so an adapter that uses it declares @behaviour for this module alongside ALLM.TranscriptionAdapter and marks each one @impl; the compiler then reports a missing or misnamed callback.