A handler class to transform input from LLM to a format that SageMaker endpoint expects. Similarily, the class also handles transforming output from the SageMaker endpoint to a format that LLM class expects.
Example:
class ContentHandler implements ContentHandlerBase<string, string> {
contentType = "application/json"
accepts = "application/json"
transformInput(prompt: string, modelKwargs: Record<string, unknown>) {
const inputString = JSON.stringify({
prompt,
...modelKwargs
})
return Buffer.from(inputString)
}
transformOutput(output: Uint8Array) {
const responseJson = JSON.parse(Buffer.from(output).toString("utf-8"))
return responseJson[0].generated_text
}
}
class BaseSageMakerContentHandler