Skip to content

Commit 4b1cd0f

Browse files
committed
feat: allow for multiple external provider specs
when using the providers.d method of installation users could hand craft their AdapterSpec's to use overlapping code meaning one repo could contain an inline and remote impl. Currently installing a provider via module does not allow for that as each repo is only allowed to have one `get_provider_spec` method with one Spec returned add an optional way for `get_provider_spec` to return a list of `ProviderSpec` where each can be either an inline or remote impl. Note: the `adapter_type` in `get_provider_spec` MUST match the `provider_type` in the build/run yaml for this to work. resolves #3226 Signed-off-by: Charlie Doern <[email protected]>
1 parent 8ef1189 commit 4b1cd0f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

llama_stack/core/distribution.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def get_external_providers_from_module(
256256
spec = module.get_provider_spec()
257257
else:
258258
# pass in a partially filled out provider spec to satisfy the registry -- knowing we will be overwriting it later upon build and run
259+
# in the case we are building we CANNOT import this module of course because it has not been installed.
259260
spec = ProviderSpec(
260261
api=Api(provider_api),
261262
provider_type=provider.provider_type,
@@ -264,9 +265,16 @@ def get_external_providers_from_module(
264265
config_class="",
265266
)
266267
provider_type = provider.provider_type
267-
# in the case we are building we CANNOT import this module of course because it has not been installed.
268-
# return a partially filled out spec that the build script will populate.
269-
registry[Api(provider_api)][provider_type] = spec
268+
if isinstance(spec, list):
269+
# optionally allow people to pass inline and remote provider specs as a returned list.
270+
# with the old method, users could pass in directories of specs using overlapping code
271+
# we want to ensure we preserve that flexibility in this method.
272+
for provider_spec in spec:
273+
if provider_spec.provider_type != provider.provider_type:
274+
continue
275+
registry[Api(provider_api)][provider.provider_type] = provider_spec
276+
else:
277+
registry[Api(provider_api)][provider_type] = spec
270278
except ModuleNotFoundError as exc:
271279
raise ValueError(
272280
"get_provider_spec not found. If specifying an external provider via `module` in the Provider spec, the Provider must have the `provider.get_provider_spec` module available"

0 commit comments

Comments
 (0)