mirror of
https://github.com/mudler/LocalAI.git
synced 2026-06-21 07:08:50 -04:00
* feat(config): add model alias field and self-validation Add ModelConfig.Alias (yaml: alias), IsAlias(), and an alias short-circuit at the top of Validate() that rejects self-reference and forbids setting backend/parameters.model on a pure-redirect alias. Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(config): resolve and validate model alias targets in the loader Assisted-by: Claude:opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(middleware): resolve model aliases and stamp requested/served identity Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(modeladmin): reject alias configs with invalid targets on create/edit Validate alias targets at create/swap entry points (ImportModelEndpoint, EditYAML, PatchConfig) so a dangling, chained, or disabled alias target is rejected at save time rather than surfacing as a runtime error. Assisted-by: Claude:opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(api): add GET /api/aliases to list model aliases Adds an admin-gated read-only endpoint that lists every model alias config as {name, target} pairs, backed by the loader's existing GetAllModelsConfigs(). Assisted-by: Claude:opus-4.8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(mcp): add set_alias and list_aliases tools Expose model-alias management over the LocalAI Assistant MCP surface: list_aliases (read-only, GET /api/aliases) and set_alias (mutating). SetAlias is swap-first: PATCH /api/models/config-json/:name swaps an existing alias's target (validated, non-destructive) and a 404 falls back to POST /models/import to create a fresh {name, alias} config. The inproc client mirrors this via ConfigService.PatchConfig + a create path modeled on ImportModelEndpoint. Deletion reuses delete_model. Assisted-by: Claude:claude-opus-4 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * style(mcp): replace em dashes in alias tool comments Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(config-meta): expose alias as a model-select field Add an 'alias' section to DefaultSections() and an 'alias' field override in DefaultRegistry() so the schema-driven React editor renders the new top-level ModelConfig.Alias field as a model picker in its own section. Assisted-by: Claude:opus-4.8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): add alias template card and Manage alias badge Add an 'Alias / Routing' template to the create-flow gallery that seeds a minimal name + alias config, and a read-only 'alias -> target' badge on the Manage Models tab. The capabilities row payload does not carry the alias field, so the badge resolves targets from GET /api/aliases looked up by name. Assisted-by: Claude:claude-opus-4 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs: document model aliases Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(swagger): regenerate for GET /api/aliases Adds the /api/aliases path and AliasInfo schema generated from the ListAliasesEndpoint annotation. Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test(localai): check os.RemoveAll error in aliases_test Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix: correct alias conversion docs and advertise /api/aliases in instructions Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(mcp): write alias config 0600 to satisfy gosec G306 The inproc createAlias path wrote the alias YAML with 0644, which gosec flags as a new G306 finding on the PR. The LocalAI process is the sole reader/writer of model configs, so 0600 is correct and keeps the scan clean. Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
78 lines
3.8 KiB
JavaScript
78 lines
3.8 KiB
JavaScript
import { test, expect } from './coverage-fixtures.js'
|
|
|
|
// Alias / Routing template + Manage alias badge regression tests.
|
|
//
|
|
// An alias is a model config with `alias: <target>` that redirects traffic to
|
|
// the target model. This covers the two discoverability surfaces:
|
|
// - the create-flow template gallery exposes an "Alias / Routing" card that
|
|
// seeds a minimal name + alias config
|
|
// - the Manage Models tab renders a read-only "alias -> target" badge on
|
|
// rows that resolve to an alias (looked up via GET /api/aliases, since the
|
|
// capabilities row payload doesn't carry the alias field)
|
|
|
|
// Minimal metadata so the editor renders the alias field once the template
|
|
// loads. Mirrors the Task 7 config-meta registry, which surfaces `alias` as a
|
|
// model-select component.
|
|
const ALIAS_METADATA = {
|
|
sections: [
|
|
{ id: 'general', label: 'General', icon: 'settings', order: 0 },
|
|
{ id: 'other', label: 'Other', icon: 'more-horizontal', order: 100 },
|
|
],
|
|
fields: [
|
|
{ path: 'name', yaml_key: 'name', go_type: 'string', ui_type: 'string',
|
|
section: 'general', label: 'Model Name', component: 'input', order: 0 },
|
|
{ path: 'alias', yaml_key: 'alias', go_type: 'string', ui_type: 'string',
|
|
section: 'general', label: 'Alias', component: 'model-select', autocomplete_provider: 'models',
|
|
description: 'Redirect this model name to another configured model.', order: 1 },
|
|
],
|
|
}
|
|
|
|
test.describe('Alias template - create flow', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.route('**/api/auth/status', (route) =>
|
|
route.fulfill({ contentType: 'application/json', body: JSON.stringify({ authEnabled: false, staticApiKeyRequired: false, providers: [] }) }))
|
|
await page.route('**/api/models/config-metadata*', (route) =>
|
|
route.fulfill({ contentType: 'application/json', body: JSON.stringify(ALIAS_METADATA) }))
|
|
await page.route('**/api/models/config-metadata/autocomplete/**', (route) =>
|
|
route.fulfill({ contentType: 'application/json', body: JSON.stringify({ values: [] }) }))
|
|
|
|
page.on('pageerror', (err) => {
|
|
throw new Error(`uncaught page error: ${err.message}`)
|
|
})
|
|
})
|
|
|
|
test('template gallery exposes the Alias / Routing card', async ({ page }) => {
|
|
await page.goto('/app/model-editor')
|
|
await expect(page.getByRole('button', { name: /Alias \/ Routing/i })).toBeVisible({ timeout: 10_000 })
|
|
})
|
|
|
|
test('alias template loads the editor with the alias field', async ({ page }) => {
|
|
await page.goto('/app/model-editor?template=alias')
|
|
await expect(page.getByText(/Unexpected Application Error/i)).toHaveCount(0)
|
|
await expect(page.locator('h1.page-title')).toBeVisible({ timeout: 10_000 })
|
|
await expect(page.getByText('Alias').first()).toBeVisible()
|
|
})
|
|
})
|
|
|
|
test.describe('Manage - alias badge', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.route('**/api/auth/status', (route) =>
|
|
route.fulfill({ contentType: 'application/json', body: JSON.stringify({ authEnabled: false, staticApiKeyRequired: false, providers: [] }) }))
|
|
await page.route('**/api/models/capabilities', (route) =>
|
|
route.fulfill({ contentType: 'application/json', body: JSON.stringify({ data: [
|
|
{ id: 'fast-llm', capabilities: ['chat'], backend: 'llama-cpp' },
|
|
{ id: 'gpt-4', capabilities: ['chat'], backend: 'llama-cpp' },
|
|
] }) }))
|
|
await page.route('**/api/aliases', (route) =>
|
|
route.fulfill({ contentType: 'application/json', body: JSON.stringify([{ name: 'gpt-4', target: 'fast-llm' }]) }))
|
|
})
|
|
|
|
test('renders a read-only alias -> target badge on aliased rows', async ({ page }) => {
|
|
await page.goto('/app/manage')
|
|
await expect(page.locator('.table')).toBeVisible({ timeout: 10_000 })
|
|
|
|
// The aliased row shows the target; the plain model row does not.
|
|
await expect(page.getByText('alias -> fast-llm')).toBeVisible({ timeout: 10_000 })
|
|
})
|
|
})
|