backend.py 578 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import asyncio

import uvloop
from triton_distributed_rs import DistributedRuntime, triton_worker

uvloop.install()


class RequestHandler:
    async def generate(self, request):
        request = f"{request}-back"
        for char in request:
            yield char


@triton_worker()
async def worker(runtime: DistributedRuntime):
    component = runtime.namespace("examples/pipeline").component("backend")
    await component.create_service()

    endpoint = component.endpoint("generate")
    await endpoint.serve_endpoint(RequestHandler().generate)


asyncio.run(worker())