Skip to content

fix(magic-ai): pre-select the newest PIM-capable models on fetch - #724

Merged
navneetkumar-pim-webkul merged 1 commit into
3.xfrom
fix/magic-ai-recommend-latest-models
Sep 24, 2026
Merged

navneetkumar-pim-webkul merged 1 commit into
3.xfrom
fix/magic-ai-recommend-latest-models

Conversation

@navneetkumar-pim-webkul

Copy link
Copy Markdown
Collaborator

Issue Reference

No issue filed. Found while adding Gemini, OpenAI, Mistral and xAI platforms: the form pre-selected legacy or unusable models and the connection test failed on a valid key.

Description

Model discovery kept only model ids and sorted them alphabetically, so after Fetch models the form ticked e.g. gpt-3.5-turbo, -0125, -1106, -16k, -instruct; Gemini image models; and mistral-small-2603 next to mistral-small-latest plus voxtral speech models. The connection test then pinged the first ticked model and failed (Gemini 404 "no longer available to new users", or a 429).

  • Discovery (AiProvider): keeps the release timestamp each API reports (created / created_at / Ollama modified_at) via the new fetchModelCatalog(); discoverModels() gains an additive released key. Gemini is filtered by supportedGenerationMethods (generateContent / predict), which drops embedding and aqa models. fetchModels() still returns sorted ids, so existing callers keep working.
  • Recommendation (ModelRecommender::recommend): newest first by release date, with the version in the name as fallback (gemini-3.7 > 3.1 > 2.5), and the cost-effective tier within a generation. One model per family (the -latest alias wins). Picks the newest text models for chat, generation and the AI agent, plus one image model.
  • List filter: also drops curie:ft-* fine-tunes, *-instruct, *-search-*, aqa and voxtral. Gemini *-image models count as image models for the connection-test picker and the chat widget's JS copy of the list.
  • Connection test: tries up to 3 ticked text models before failing, and reports the first failure.

How To Test This?

  1. Configuration → Magic AI → Add Platform → OpenAI, enter a key, fetch models.
    • Pre-selected: newest models (e.g. gpt-5-mini, gpt-5, gpt-4.1-mini, gpt-4o-mini) plus one image model.
    • Not pre-selected: gpt-3.5-*. Not listed: curie:ft-*.
  2. Repeat with Google Gemini. The newest generation (3.x) is pre-selected with one *-image model, and aqa / embedding models are not listed.
  3. Repeat with Mistral. mistral-small-latest is selected once (no -2603 duplicate), and no voxtral model is selected.
  4. On Gemini, tick a model the account can no longer call first (e.g. gemini-2.5-flash), then a current one, and click Test Connection. It succeeds via the fallback.
  5. vendor/bin/pest packages/Webkul/AiAgent/tests/Unit packages/Webkul/MagicAI/tests packages/Webkul/Admin/tests/Feature/MagicAi packages/Webkul/Admin/tests/Feature/MagicAI

Screenshots

N/A — only the server response changes: the fetched list and which models are pre-selected.

Checklist

  • vendor/bin/pest passes locally (AiAgent Unit, MagicAI, Admin Magic AI suites: 684 passed)
  • vendor/bin/pint --test reports no style issues
  • Tailwind classes are reordered (no markup change)
  • New user-facing strings use translation keys (none added; unopim:translations:check passes)
  • Target branch is 3.x

Also run: PHPStan on the changed files (no errors) and Rector dry-run (suggestions applied to new lines). Playwright was not run.

Existing tests updated for the intended behaviour: one pre-selected image model instead of all of them, -instruct excluded, newest generation ranked before the cheaper older tier, and the additive released key.

Documentation

  • My pull request requires an update on the documentation repository.

Model discovery kept only the ids and sorted them alphabetically, so the
auto-selection on the Add AI Platform form ticked legacy models such as
five gpt-3.5-turbo variants, and the connection test pinged Gemini image
models or models the provider no longer serves to the account.

- keep the release timestamp each provider reports and rank by it, with
  the version in the model name as the fallback for providers without one
- pre-select the newest text models for chat, generation and the agent
  plus the newest image model, one per family
- list only Gemini models that support generateContent or predict, and
  drop legacy fine-tunes, completion-only, search and speech models
- try up to three ticked text models before a connection test fails
Copilot AI lite review requested due to automatic review settings September 24, 2026 14:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Address Azure release timestamps, context-window family normalization, and filtering of non-chat models from retry candidates.

Review effort: Lite
Findings: None

What changed in this PR

Updates Magic AI model discovery and selection to prefer current, usable models and retry connection tests across multiple text models.

Changes:

  • Adds provider release metadata and filters unsupported models.
  • Improves ranking, family deduplication, and image-model selection.
  • Adds connection-test fallback attempts and related coverage.
File Description
packages/​Webkul/​MagicAI/​tests/​Unit/​AiProviderTest.php Tests discovery metadata and Gemini filtering.
packages/​Webkul/​MagicAI/​tests/​Feature/​PlatformConnectionTest.php Tests connection fallback behavior.
packages/​Webkul/​MagicAI/​src/​Support/​ModelRecommender.php Implements filtering, ranking, deduplication, and text selection.
packages/​Webkul/​MagicAI/​src/​Enums/​AiProvider.php Adds catalog metadata and provider filtering.
packages/​Webkul/​AiAgent/​tests/​Unit/​ModelSelectionConfigTest.php Updates recommendation expectations.
packages/​Webkul/​AiAgent/​tests/​Unit/​ModelRecommenderTest.php Covers ranking and filtering scenarios.
packages/​Webkul/​AiAgent/​Resources/​views/​components/​chat-widget.blade.php Recognizes Gemini image models.
packages/​Webkul/​Admin/​src/​Http/​Controllers/​MagicAI/​MagicAIPlatformController.php Adds connection-test fallback logic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@navneetkumar-pim-webkul
navneetkumar-pim-webkul merged commit 9ab55d2 into 3.x Sep 24, 2026
24 checks passed
@navneetkumar-pim-webkul
navneetkumar-pim-webkul deleted the fix/magic-ai-recommend-latest-models branch September 24, 2026 15:02
@navneetkumar-pim-webkul navneetkumar-pim-webkul mentioned this pull request Sep 24, 2026
2 of 6 tasks
navneetkumar-pim-webkul added a commit that referenced this pull request Sep 24, 2026
Six merged pull requests since v3.1.1 carried no changelog entry: the
gallery unsaved badge and worker timeout handler (#713), the import filter
re-render (#720), the worker timeout alarm (#722), the channel name on
PostgreSQL (#725), the price input height (#726), and the export view
events (#717, #718). The two fixes pending in #727 and #728 are included
so the cut merges after them.

The model recommendation entry described the cheap-tier ranking that #724
replaced with newest-per-family; it now describes the shipped behaviour.

3.1.2 is a patch release, so everything is filed under bug fixes and
improvements; no feature section. Core::VERSION, package.json and the
UPGRADE.md walkthrough move to 3.1.2 together, as they did for 3.1.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants