Build and deploy two example Chains
Help for setting up a clean development environment
>=3.8,<3.13
. To set up a fresh development environment,
you can use the following commands, creating a environment named chains_env
using pyenv
:.bashrc
:
hello_chain/hello.py
:
HelloWorld
, the entrypoint, which handles the input and output.RandInt
, which generates a random integer. It is used a as a dependency
by HelloWorld
.@chains.mark_entrypoint
decorator. This Chainlet is responsible for
handling public-facing input and output for the whole Chain in response to an
API call.
A Chainlet class has a single public method,
run_remote()
, which is
the API
endpoint for the entrypoint Chainlet and the function that other Chainlets can
use as a dependency. The
run_remote()
method must be fully type-annotated
with
or .
Chainlets cannot be instantiated. The only correct usages are:
chains.depends()
directive
as an __init__
-argument as shown above for the RandInt
Chainlet.ACTIVE
and test invoking your Chain (replace
$INVOCATION_URL
in below command):
PoemGenerator
, the entrypoint, which handles the input and output and
orchestrates calls to the LLM.PhiLLM
, which runs inference on Phi-3 Mini.hello_chain/
, go up one level with cd ..
first):
poems.py
:
poems.py
:
asyncio.ensure_future
around each RPC to the LLM chainlet.
This makes the current python process start these remote calls concurrently,
i.e. the next call is started before the previous one has finished and we can
minimize our overall runtime. In order to await the results of all calls,
asyncio.gather
is used which gives us back normal python objects.
If the LLM is hit with many concurrent requests, it can auto-scale up (if
autoscaling is configured). More advanced LLM models have batching capabilities,
so for those even a single instance can serve concurrent request.
ACTIVE
and test invoking your Chain (replace
$INVOCATION_URL
in below command):