bls.py 1011 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
26
27
28
29
30
31
32
33
34
import asyncio

import uvloop
from triton_distributed_rs import DistributedRuntime, triton_worker

uvloop.install()


@triton_worker()
async def worker(runtime: DistributedRuntime):
    foo = (
        await runtime.namespace("examples/bls")
        .component("foo")
        .endpoint("generate")
        .client()
    )
    bar = (
        await runtime.namespace("examples/bls")
        .component("bar")
        .endpoint("generate")
        .client()
    )

    # hello world showed us the client has a .generate, which uses the default load balancer
    # however, you can explicitly opt-in to client side load balancing by using the `round_robin`
    # or `random` methods on client. note - there is a direct method as well, but that is for a
    # router example
    async for char in await foo.round_robin("hello world"):
        # the responses are sse-style responses, so we extract the data key
        async for x in await bar.random(char.get("data")):
            print(x)


asyncio.run(worker())