mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-11 19:56:03 +00:00
handle pre-existing providers
This commit is contained in:
parent
a8b2a0242f
commit
9e491218c6
1 changed files with 25 additions and 14 deletions
|
|
@ -541,26 +541,37 @@ async def resolve_impls_via_provider_registration(
|
||||||
else:
|
else:
|
||||||
# Regular providers - register through ProviderImpl
|
# Regular providers - register through ProviderImpl
|
||||||
api = Api(api_str)
|
api = Api(api_str)
|
||||||
logger.info(f"Registering {provider.provider_id} for {api.value}")
|
|
||||||
|
|
||||||
await providers_impl.register_provider(
|
|
||||||
api=api.value,
|
|
||||||
provider_id=provider.provider_id,
|
|
||||||
provider_type=provider.spec.provider_type,
|
|
||||||
config=provider.config,
|
|
||||||
attributes=getattr(provider, "attributes", None),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get the instantiated impl from dynamic_provider_impls using composite key
|
|
||||||
cache_key = f"{api.value}::{provider.provider_id}"
|
cache_key = f"{api.value}::{provider.provider_id}"
|
||||||
impl = providers_impl.dynamic_provider_impls[cache_key]
|
|
||||||
|
# Check if provider already exists (loaded from kvstore during initialization)
|
||||||
|
if cache_key in providers_impl.dynamic_providers:
|
||||||
|
logger.info(f"Provider {provider.provider_id} for {api.value} already exists, using existing instance")
|
||||||
|
impl = providers_impl.dynamic_provider_impls.get(cache_key)
|
||||||
|
if impl is None:
|
||||||
|
# Provider exists but not instantiated, instantiate it
|
||||||
|
conn_info = providers_impl.dynamic_providers[cache_key]
|
||||||
|
impl = await providers_impl._instantiate_provider(conn_info)
|
||||||
|
providers_impl.dynamic_provider_impls[cache_key] = impl
|
||||||
|
else:
|
||||||
|
logger.info(f"Registering {provider.provider_id} for {api.value}")
|
||||||
|
|
||||||
|
await providers_impl.register_provider(
|
||||||
|
api=api.value,
|
||||||
|
provider_id=provider.provider_id,
|
||||||
|
provider_type=provider.spec.provider_type,
|
||||||
|
config=provider.config,
|
||||||
|
attributes=getattr(provider, "attributes", None),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get the instantiated impl from dynamic_provider_impls using composite key
|
||||||
|
impl = providers_impl.dynamic_provider_impls[cache_key]
|
||||||
|
logger.info(f"Successfully registered startup provider: {provider.provider_id}")
|
||||||
|
|
||||||
impls[api] = impl
|
impls[api] = impl
|
||||||
|
|
||||||
# IMPORTANT: Update providers_impl.deps so subsequent providers can depend on this one
|
# IMPORTANT: Update providers_impl.deps so subsequent providers can depend on this one
|
||||||
providers_impl.deps[api] = impl
|
providers_impl.deps[api] = impl
|
||||||
|
|
||||||
logger.info(f"Successfully registered startup provider: {provider.provider_id}")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to handle provider {provider.provider_id}: {e}")
|
logger.error(f"Failed to handle provider {provider.provider_id}: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue