The platform sends audio and document attacks only when the matching modality is
selected on the target. A text-only adapter never sees them and needs no change.
def pre_process(context, inference_input):
if inference_input.audio is None: # not an audio attack: send the prompt as text
return PreProcessResult(
url=context.vars["endpoint"],
json_body={"message": inference_input.prompt},
)
clip = inference_input.audio.first(AudioFormat.MP3, AudioFormat.WAV)
if clip is None:
offered = ", ".join(f.value for f in inference_input.audio.formats())
raise_target_error(f"no supported audio format; offered: {offered}")
return PreProcessResult(
url=context.vars["endpoint"],
json_body={"audio": clip.b64, "format": clip.format.value},
)