Skip to content

Commit fa6dcd4

Browse files
Support 'internal URLs' for chainlet stubs, update docs (#1442)
* Support 'internal URLs' for chainlet stubs, update docs.
1 parent a1975b0 commit fa6dcd4

File tree

10 files changed

+246
-72
lines changed

10 files changed

+246
-72
lines changed

docs/chains/doc_gen/API-reference.mdx

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Inheriting from this class adds validations to make sure subclasses adhere to th
1616
chainlet pattern and facilitates remote chainlet deployment.
1717

1818
Refer to [the docs](https://docs.baseten.co/chains/getting-started) and this
19-
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py)
19+
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/reference_code/reference_chainlet.py)
2020
for more guidance on how to create subclasses.
2121

2222

@@ -50,7 +50,7 @@ When deploying a chain remotely, a corresponding stub to the remote is injected
5050
its place. In [`run_local`](#truss-chains-run-local) mode an instance of a local chainlet is injected.
5151

5252
Refer to [the docs](https://docs.baseten.co/chains/getting-started) and this
53-
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py)
53+
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/reference_code/reference_chainlet.py)
5454
for more guidance on how make one chainlet depend on another chainlet.
5555

5656
<Warning>
@@ -78,7 +78,7 @@ chainlet instance is provided.
7878
Sets a “symbolic marker” for injecting a context object at runtime.
7979

8080
Refer to [the docs](https://docs.baseten.co/chains/getting-started) and this
81-
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py)
81+
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/reference_code/reference_chainlet.py)
8282
for more guidance on the `__init__`-signature of chainlets.
8383

8484
<Warning>
@@ -606,18 +606,18 @@ class MyChainlet(chains.ChainletBase):
606606
| `api_key` | *str* | A baseten API key to authorize requests. |
607607

608608

609-
#### *classmethod* from_url(predict_url, context, options=None)
609+
#### *classmethod* from_url(predict_url, context_or_api_key, options=None)
610610

611611
Factory method, convenient to be used in chainlet’s `__init__`-method.
612612

613613

614614
**Parameters:**
615615

616-
| Name | Type | Description |
617-
|---------------|--------------------------------------------------------------|-------------------------------------------------------------------|
618-
| `predict_url` | *str* | URL to predict endpoint of another chain / truss model. |
619-
| `context` | *[DeploymentContext](#class-truss-chains-deploymentcontext)* | Deployment context object, obtained in the chainlet’s `__init__`. |
620-
| `options` | *[RPCOptions](#class-truss-chains-rpcoptions)* | RPC options, e.g. retries. |
616+
| Name | Type | Description |
617+
|----------------------|--------------------------------------------------------------|--------------------------------------------------------------------------------------|
618+
| `predict_url` | *str* | URL to predict endpoint of another chain / truss model. |
619+
| `context_or_api_key` | *[DeploymentContext](#class-truss-chains-deploymentcontext)* | Deployment context object, obtained in the chainlet’s `__init__` or Baseten API key. |
620+
| `options` | *[RPCOptions](#class-truss-chains-rpcoptions)* | RPC options, e.g. retries. |
621621

622622
#### Invocation Methods
623623

docs/chains/doc_gen/generated-reference.mdx

+34-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Inheriting from this class adds validations to make sure subclasses adhere to th
1616
chainlet pattern and facilitates remote chainlet deployment.
1717

1818
Refer to [the docs](https://docs.baseten.co/chains/getting-started) and this
19-
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py)
19+
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/reference_code/reference_chainlet.py)
2020
for more guidance on how to create subclasses.
2121

2222

@@ -48,7 +48,7 @@ When deploying a chain remotely, a corresponding stub to the remote is injected
4848
its place. In `run_local` mode an instance of a local chainlet is injected.
4949

5050
Refer to [the docs](https://docs.baseten.co/chains/getting-started) and this
51-
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py)
51+
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/reference_code/reference_chainlet.py)
5252
for more guidance on how make one chainlet depend on another chainlet.
5353

5454
#### WARNING
@@ -77,7 +77,7 @@ chainlet instance is provided.
7777
Sets a “symbolic marker” for injecting a context object at runtime.
7878

7979
Refer to [the docs](https://docs.baseten.co/chains/getting-started) and this
80-
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py)
80+
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/reference_code/reference_chainlet.py)
8181
for more guidance on the `__init__`-signature of chainlets.
8282

8383
#### WARNING
@@ -564,7 +564,7 @@ foo("./somewhere")
564564
* **Parameters:**
565565
**file_path** (*str*)
566566
* **Return type:**
567-
public_types.AbsPath
567+
*AbsPath*
568568

569569
### `truss_chains.run_local`
570570

@@ -632,16 +632,42 @@ specifically with `StubBase`.
632632
| `name` | *str* | |
633633
| `display_name` | *str* | |
634634
| `options` | *[RPCOptions](#truss_chains.RPCOptions* | |
635-
| `predict_url` | *str* | |
635+
| `predict_url` | *str\|None* | |
636+
| `internal_url` | *[InternalURL](#truss_chains.DeployedServiceDescriptor.InternalURL* | |
636637

637638

639+
#### *class* InternalURL(, gateway_run_remote_url, hostname)
640+
641+
Bases: `pydantic.BaseModel`
642+
643+
**Parameters:**
644+
645+
| Name | Type | Description |
646+
|------|------|-------------|
647+
| `gateway_run_remote_url` | *str* | |
648+
| `hostname` | *str* | |
649+
650+
651+
#### gateway_run_remote_url *: str*
652+
653+
#### hostname *: str*
654+
655+
#### check_at_least_one_url()
656+
657+
* **Parameters:**
658+
**self** ([*DeployedServiceDescriptor*](#truss_chains.DeployedServiceDescriptor))
659+
* **Return type:**
660+
[*DeployedServiceDescriptor*](#truss_chains.DeployedServiceDescriptor)
661+
638662
#### display_name *: str*
639663

664+
#### internal_url *: [InternalURL](#truss_chains.DeployedServiceDescriptor.InternalURL) | None*
665+
640666
#### name *: str*
641667

642668
#### options *: [RPCOptions](#truss_chains.RPCOptions)*
643669

644-
#### predict_url *: str*
670+
#### predict_url *: str | None*
645671

646672

647673
### *class* `truss_chains.StubBase`
@@ -706,7 +732,7 @@ class MyChainlet(chains.ChainletBase):
706732
| `api_key` | *str* | A baseten API key to authorize requests. |
707733

708734

709-
#### *classmethod* from_url(predict_url, context, options=None)
735+
#### *classmethod* from_url(predict_url, context_or_api_key, options=None)
710736

711737
Factory method, convenient to be used in chainlet’s `__init__`-method.
712738

@@ -716,7 +742,7 @@ Factory method, convenient to be used in chainlet’s `__init__`-method.
716742
| Name | Type | Description |
717743
|------|------|-------------|
718744
| `predict_url` | *str* | URL to predict endpoint of another chain / truss model. |
719-
| `context` | *[DeploymentContext](#truss_chains.DeploymentContext* | Deployment context object, obtained in the chainlet’s `__init__`. |
745+
| `context_or_api_key` | *[DeploymentContext](#truss_chains.DeploymentContext* | Deployment context object, obtained in the chainlet’s `__init__` or Baseten API key. |
720746
| `options` | *[RPCOptions](#truss_chains.RPCOptions* | RPC options, e.g. retries. |
721747

722748

docs/chains/doc_gen/reference.patch

+49-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- docs/chains/doc_gen/generated-reference.mdx 2025-03-07 14:07:59.058967543 -0800
2-
+++ docs/chains/doc_gen/API-reference.mdx 2025-03-07 14:06:58.765143669 -0800
1+
--- docs/chains/doc_gen/generated-reference.mdx 2025-03-11 11:50:41.420102369 -0700
2+
+++ docs/chains/doc_gen/API-reference.mdx 2025-03-11 11:45:47.101215413 -0700
33
@@ -30,13 +30,15 @@
44

55
### *class* `truss_chains.EngineBuilderLLMChainlet`
@@ -29,7 +29,7 @@
2929
+its place. In [`run_local`](#truss-chains-run-local) mode an instance of a local chainlet is injected.
3030

3131
Refer to [the docs](https://docs.baseten.co/chains/getting-started) and this
32-
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py)
32+
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/reference_code/reference_chainlet.py)
3333
for more guidance on how make one chainlet depend on another chainlet.
3434

3535
-#### WARNING
@@ -65,7 +65,7 @@
6565
### `truss_chains.depends_context`
6666

6767
@@ -80,16 +81,15 @@
68-
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/example_chainlet.py)
68+
[example chainlet](https://github.com/basetenlabs/truss/blob/main/truss-chains/truss_chains/reference_code/reference_chainlet.py)
6969
for more guidance on the `__init__`-signature of chainlets.
7070

7171
-#### WARNING
@@ -173,14 +173,14 @@
173173
-| `use_binary` | *bool* | Whether to send data in binary format. This can give a parsing speedup and message size reduction (~25%) for numpy arrays. Use `NumpyArrayField` as a field type on pydantic models for integration and set this option to `True`. For simple text data, there is no significant benefit. |
174174
-
175175
-#### retries *: int*
176+
-
177+
-#### timeout_sec *: float*
176178
+| Name | Type | Description |
177179
+|---------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
178180
+| `retries` | *int* | The number of times to retry the remote chainlet in case of failures (e.g. due to transient network issues). For streaming, retries are only made if the request fails before streaming any results back. Failures mid-stream not retried. |
179181
+| `timeout_sec` | *float* | Timeout for the HTTP request to this chainlet. |
180182
+| `use_binary` | *bool* | Whether to send data in binary format. This can give a parsing speedup and message size reduction (~25%) for numpy arrays. Use `NumpyArrayField` as a field type on pydantic models for integration and set this option to `True`. For simple text data, there is no significant benefit. |
181183

182-
-#### timeout_sec *: float*
183-
-
184184
-#### use_binary *: bool*
185185

186186
### `truss_chains.mark_entrypoint`
@@ -582,7 +582,6 @@
582582
-* **Parameters:**
583583
- **file_path** (*str*)
584584
-* **Return type:**
585-
- public_types.AbsPath
586585
+</Warning>
587586
+
588587
+**Parameters:**
@@ -593,9 +592,9 @@
593592
+
594593
+
595594
+* **Returns:**
596-
+ *AbsPath*
597-
+
595+
*AbsPath*
598596

597+
+
599598
### `truss_chains.run_local`
600599

601600
Context manager local debug execution of a chain.
@@ -628,7 +627,7 @@
628627
import os
629628
import truss_chains as chains
630629

631-
@@ -627,21 +536,12 @@
630+
@@ -627,47 +536,12 @@
632631

633632
**Parameters:**
634633

@@ -637,16 +636,42 @@
637636
-| `name` | *str* | |
638637
-| `display_name` | *str* | |
639638
-| `options` | *[RPCOptions](#truss_chains.RPCOptions* | |
640-
-| `predict_url` | *str* | |
639+
-| `predict_url` | *str\|None* | |
640+
-| `internal_url` | *[InternalURL](#truss_chains.DeployedServiceDescriptor.InternalURL* | |
641641
-
642642
-
643+
-#### *class* InternalURL(, gateway_run_remote_url, hostname)
644+
-
645+
-Bases: `pydantic.BaseModel`
646+
-
647+
-**Parameters:**
648+
-
649+
-| Name | Type | Description |
650+
-|------|------|-------------|
651+
-| `gateway_run_remote_url` | *str* | |
652+
-| `hostname` | *str* | |
653+
-
654+
-
655+
-#### gateway_run_remote_url *: str*
656+
-
657+
-#### hostname *: str*
658+
-
659+
-#### check_at_least_one_url()
660+
-
661+
-* **Parameters:**
662+
- **self** ([*DeployedServiceDescriptor*](#truss_chains.DeployedServiceDescriptor))
663+
-* **Return type:**
664+
- [*DeployedServiceDescriptor*](#truss_chains.DeployedServiceDescriptor)
665+
-
643666
-#### display_name *: str*
644667
-
668+
-#### internal_url *: [InternalURL](#truss_chains.DeployedServiceDescriptor.InternalURL) | None*
669+
-
645670
-#### name *: str*
646671
-
647672
-#### options *: [RPCOptions](#truss_chains.RPCOptions)*
648673
-
649-
-#### predict_url *: str*
674+
-#### predict_url *: str | None*
650675
+| Name | Type | Description |
651676
+|----------------|------------------------------------------------|-------------|
652677
+| `name` | *str* | |
@@ -656,7 +681,7 @@
656681

657682

658683
### *class* `truss_chains.StubBase`
659-
@@ -657,7 +557,7 @@
684+
@@ -683,7 +557,7 @@
660685
in user-code for wrapping a deployed truss model into the Chains framework. It
661686
flexibly supports JSON and pydantic inputs and output. Example usage:
662687

@@ -665,7 +690,7 @@
665690
import pydantic
666691
import truss_chains as chains
667692

668-
@@ -668,18 +568,18 @@
693+
@@ -694,18 +568,18 @@
669694

670695
class DeployedWhisper(chains.StubBase):
671696
# Input JSON, output JSON.
@@ -687,7 +712,7 @@
687712
return await self.predict_async(data, output_model=WhisperOutput)
688713

689714

690-
@@ -700,10 +600,10 @@
715+
@@ -726,10 +600,10 @@
691716

692717
**Parameters:**
693718

@@ -701,15 +726,15 @@
701726
+| `api_key` | *str* | A baseten API key to authorize requests. |
702727

703728

704-
#### *classmethod* from_url(predict_url, context, options=None)
705-
@@ -713,27 +613,25 @@
729+
#### *classmethod* from_url(predict_url, context_or_api_key, options=None)
730+
@@ -739,27 +613,25 @@
706731

707732
**Parameters:**
708733

709734
-| Name | Type | Description |
710735
-|------|------|-------------|
711736
-| `predict_url` | *str* | URL to predict endpoint of another chain / truss model. |
712-
-| `context` | *[DeploymentContext](#truss_chains.DeploymentContext* | Deployment context object, obtained in the chainlet’s `__init__`. |
737+
-| `context_or_api_key` | *[DeploymentContext](#truss_chains.DeploymentContext* | Deployment context object, obtained in the chainlet’s `__init__` or Baseten API key. |
713738
-| `options` | *[RPCOptions](#truss_chains.RPCOptions* | RPC options, e.g. retries. |
714739
-
715740
-
@@ -727,11 +752,11 @@
727752
-#### predict_sync(inputs: InputT, output_model: Type[OutputModelT]) → OutputModelT
728753
-
729754
-#### predict_sync(inputs: InputT, output_model: None = None) → Any
730-
+| Name | Type | Description |
731-
+|---------------|--------------------------------------------------------------|-------------------------------------------------------------------|
732-
+| `predict_url` | *str* | URL to predict endpoint of another chain / truss model. |
733-
+| `context` | *[DeploymentContext](#class-truss-chains-deploymentcontext)* | Deployment context object, obtained in the chainlet’s `__init__`. |
734-
+| `options` | *[RPCOptions](#class-truss-chains-rpcoptions)* | RPC options, e.g. retries. |
755+
+| Name | Type | Description |
756+
+|----------------------|--------------------------------------------------------------|--------------------------------------------------------------------------------------|
757+
+| `predict_url` | *str* | URL to predict endpoint of another chain / truss model. |
758+
+| `context_or_api_key` | *[DeploymentContext](#class-truss-chains-deploymentcontext)* | Deployment context object, obtained in the chainlet’s `__init__` or Baseten API key. |
759+
+| `options` | *[RPCOptions](#class-truss-chains-rpcoptions)* | RPC options, e.g. retries. |
735760
+
736761
+#### Invocation Methods
737762
+
@@ -749,7 +774,7 @@
749774

750775

751776
### *class* `truss_chains.RemoteErrorDetail`
752-
@@ -746,62 +644,21 @@
777+
@@ -772,62 +644,21 @@
753778

754779
**Parameters:**
755780

0 commit comments

Comments
 (0)