load_from_github
Apply every Smarter manifest in a GitHub repository, in the order of their dependencies.
manage.py initialize_platform and manage.py initialize_account load two repositories with
this command:
smarter-sh/example-manifests, the community-supported collection of example manifests, one folder per kind: the platform’s example Guardrails, MCPClients, LLMHosts, Proxies, Vectorstores, plugins, LLMClients, Budgets and more.
smarter-sh/stackademy, the Secrets, Connections, plugins, LLMClients and Budget of a fictional code academy.
A repository may also hold scripts, in its scripts/ folder, which run before or after its
manifests are applied: see smarter.apps.account.repository_scripts.
- class smarter.apps.account.management.commands.load_from_github.Command(*args, **kwargs)[source]
Bases:
SmarterCommandDjango manage.py load_from_github command.
Clones a public GitHub repository and applies each Smarter manifest in it, as a user, through the same brokers as the
applyapi. The repository’s folders are only for people: the manifests are applied in the order of their kinds’ dependencies,SAMKinds.apply_order(), so that a Connection exists before the plugin that uses it, a plugin before the LLMClient that lists it, and so on. Within a kind, they are applied in the order of their paths.A manifest is a
*.yaml,*.ymlor*.yaml.tplfile whoseapiVersionis a Smarter api version. Other files, and hidden files and folders, e.g..github/and.pre-commit-config.yaml, are ignored.A manifest template,
*.yaml.tpl, is filled in with this platform’s scheme and domain, e.g. the Stackademy ApiConnection, whosebaseUrlis the platform that applies it.An LLMClient that exists keeps its
deployedvalue, and an LLMClient that needs an extension that is not installed is skipped.A Budget whose manifest lists no
spec.resourcesis created detached, once. If it exists, it is left as it is: applying the manifest again would detach it from the resources that a superuser has since attached it to, and undo their changes.--deploydeploys each LLMClient that is not deployed, and deploys again one whose domain was never verified, or failed to verify.The repository’s top-level
scripts/folder holds no manifests.--run_scriptsruns the scripts that itsscripts/scripts.yamllists: thepreones before any manifest is applied, and thepostones after every manifest is applied and the LLMClients deployed. Onlymanage.py initialize_platformpasses it. Seesmarter.apps.account.repository_scripts.--include_kindapplies only the manifests of the kinds that it names, e.g. the plugins and LLMClients of which each account gets its own copy.--exclude_kindskips the manifests of a kind, e.g. a Budget, which only a superuser may apply, and which applies to the platform rather than to one account.--skip_missing_referencesskips, with a warning, a manifest that names a resource that this platform doesn’t have, e.g. an MCPClient whose credentials Secret no operator has created: the broker raisesSAMBrokerErrorNotFound. It is applied by a later load, once the resource exists.manage.py initialize_platformandmanage.py initialize_accountpass it for the example manifests, some of which need a Secret of a third-party service, and not for Stackademy, which brings its own Secrets.One manifest or script that fails doesn’t stop the rest. The command fails at the end, with the list of what failed, and also when the repository holds no manifest at all, or its
scripts/scripts.yamlis not valid.
The owner is
--username, or the admin of the account--account_number. Applying is idempotent: a resource that exists is updated.- UNVERIFIED_DNS_STATUSES = (LLMClient.DnsVerificationStatusChoices.NOT_VERIFIED, LLMClient.DnsVerificationStatusChoices.FAILED)
The domain statuses of a deployed LLMClient that no deploy task is going to change.
- apply(filespec, user_profile, manifest=None)[source]
Apply one manifest, and report, rather than raise, a failure.
The manifest is applied in a transaction, so that one that fails leaves nothing behind.
- Parameters:
filespec (
str) – The manifest’s path.user_profile (
UserProfile) – The owner of the resource.manifest (
str|None) – The manifest to apply instead of the file’s, e.g. a template’s, filled in.
A manifest that names a resource that doesn’t exist is skipped, rather than failed, with
--skip_missing_references: its file is added toskipped.
- apply_manifests(manifests, user_profile, deploy=False)[source]
Apply the manifests, in order, and deploy the LLMClients if
deploy.- Parameters:
manifests (
list[RepositoryManifest]) – The manifests, fromfind_manifests().user_profile (
UserProfile) – The owner of the resources.deploy (
bool) – Deploy each LLMClient that is not deployed.
- Returns:
A description of each manifest that failed to apply or deploy.
- Return type:
- clone_repo(local_path)[source]
Clone the repository’s default branch, without its history.
- Parameters:
local_path (
str) – The folder to clone into.- Raises:
subprocess.CalledProcessError – If git fails.
- Return type:
- deploy_llmclient(name, user_profile)[source]
Deploy the LLMClient of a user, if it is not deployed.
An LLMClient that is deployed is left as it is, unless its domain was never verified, or failed to verify, e.g. because the DNS service wasn’t ready. It is then deployed again, with
deploy_default_api: otherwise nothing ever retries it, and it stays unreachable until someone undeploys and redeploys it by hand.- Parameters:
name (
str) – The LLMClient’s name.user_profile (
UserProfile) – Its owner.
- Returns:
False if the LLMClient does not exist, or failed to deploy.
- Return type:
- find_manifests(local_path)[source]
Return the repository’s manifests, in the order in which to apply them.
- Parameters:
local_path (
str) – The repository’s clone.- Returns:
The manifests, sorted by
SAMKinds.apply_order(), then by path.- Return type:
- get_user_profile(account_number, username)[source]
Return the owner of the resources:
username, or else the admin of the accountaccount_number.It is the user profile that
manage.py apply_manifestapplies the manifests as.- Parameters:
- Returns:
The owner.
- Return type:
- Raises:
SmarterValueError – If neither is given, or the account or user does not exist.
- help = 'Apply every Smarter manifest in a public GitHub repository, in the order of their dependencies, e.g. https://github.com/smarter-sh/example-manifests.'
- is_existing_detached_budget(item)[source]
Whether a manifest is of a Budget that exists, and lists no resources.
Such a Budget is left as it is: applying its manifest would detach it from the resources that a superuser has attached it to since it was created.
- Parameters:
item (
RepositoryManifest) – The manifest.- Returns:
True if it is to be skipped.
- Return type:
- static keep_deployed(manifest, user_profile)[source]
Return a copy of an LLMClient manifest whose
deployedis that of the LLMClient that exists, if any.A manifest is not deployed, so applying it as it is would undeploy an LLMClient that is deployed, whose undeploy task destroys its A record, only for the next deploy to create it again. Resolvers that query the domain in between cache the NXDOMAIN for minutes.
- static missing_extensions(slugs)[source]
Return the slugs, of those that an LLMClient manifest lists, of the extensions that are not installed.
manage.py install_official_extensionsinstalls them, from a registry that may not be reachable.
- run_scripts(local_path, config, stage, user_profile)[source]
Run the repository’s scripts of one stage, in the order of its
scripts/scripts.yaml.- Parameters:
local_path (
str) – The repository’s clone.config (
RepositoryScriptsConfig|None) – The repository’s scripts configuration, or None if it has none.stage (
Literal['pre','post']) –preorpost.user_profile (
UserProfile) – The owner of the resources, whose account and username the scripts receive.
- Returns:
A description of each script that failed.
- Return type:
- select_manifests(manifests, included, excluded)[source]
Return the manifests of the kinds to apply, and say which were skipped.
- Parameters:
manifests (
list[RepositoryManifest]) – The manifests, fromfind_manifests().included (
list[str]) – Apply only these kinds, or every kind if it is empty.
- Returns:
The manifests to apply, in the same order.
- Return type:
- skipped: set[str]
The manifests, by file, that
apply()skipped, because they name a resource that doesn’t exist.
- user_profile: UserProfile | None = None
- smarter.apps.account.management.commands.load_from_github.MANIFEST_EXTENSIONS = ('.yaml', '.yml', '.yaml.tpl')
The extensions of the files that may hold a manifest.
Other files, e.g. a README, are ignored.
('.yaml', '.yml', '.yaml.tpl')