Function serve

  • Spawn an HTTP server to handle tensor input and output requests.

    Remarks

    This function does not return. The default port is 3000.

    Example

    // any function with tensor inputs/outputs can be served
    function genRandTensor() {
    return sm.rand([128])
    }

    // async functions can be served as well
    async function talkToServer() {
    const t = await sm.network.tfetch(different_server)
    return t.mul(sm.rand([128]))
    }

    sm.network.serve({
    genRandTensor: genRandTensor,
    remoteCall: talkToServer
    })

    The above functions are accessible from a different process with network.tfetch:

    const t0 = await sm.network.tfetch(`${host}:3000/genRandTensor`)
    const t1 = await sm.network.tfetch(`${host}:3000/remoteCall`)

    Parameters

    • request_dict: Record<string, ((...args: unknown[]) => unknown)>

      A map of endpoint names to the underlying (possibly async) function calls.

    • options: ServeOptions

      A set of options passed to the underlying Bun.serve call.

    Returns void

Generated using TypeDoc