Skip to content

Revert model upgrade adapting#1365

Merged
yileicn merged 1 commit into
SciSharp:masterfrom
adenchen123:model-upgrade-adapting-revert
Jun 17, 2026
Merged

Revert model upgrade adapting#1365
yileicn merged 1 commit into
SciSharp:masterfrom
adenchen123:model-upgrade-adapting-revert

Conversation

@adenchen123

Copy link
Copy Markdown
Contributor

No description provided.

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Revert model upgrade mapping and use explicit model names
🐞 Bug fix ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

Description

• Remove configurable model-upgrade mapping and related DI/config wiring.
• Stop rewriting model IDs at runtime; use configured or constant model names.
• Simplify settings service API by dropping GetUpgradeModel().
Diagram

graph TD
  Plugins["Plugin functions"] --> Completion["CompletionProvider"] --> Providers["LLM providers"]
  RealtimeHub["RealtimeHub"] --> RealtimeProviders["Realtime providers"] --> Providers
  Completion --> ModelConsts["Model constants"]
  RealtimeProviders --> RealtimeSettings["RealtimeModelSettings"]
  CoreServices["Core services"] --> Completion
  subgraph Legend
    direction LR
    _svc([Service/Module]) ~~~ _cfg["Settings/Constants"] ~~~ _ext{{External}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Provider-layer alias resolution
  • ➕ Keeps model-ID rewriting centralized where provider models are resolved
  • ➕ Avoids leaking upgrade logic into unrelated services/plugins
  • ➖ Requires changes in provider model registry/lookup behavior
  • ➖ May be harder to override per-workflow if not designed carefully
2. Config-driven aliases with explicit opt-in per call site
  • ➕ Preserves flexibility while limiting blast radius
  • ➕ Allows gradual rollout and easier debugging
  • ➖ More boilerplate at call sites to opt-in
  • ➖ Still requires maintaining alias configuration
3. Feature-flagged upgrade mapper (default off)
  • ➕ Allows re-enabling mapping for specific deployments
  • ➕ Reduces risk of unexpected model changes globally
  • ➖ Adds configuration complexity back
  • ➖ Flag interactions can be confusing without strong observability

Recommendation: This revert is a reasonable stabilization step if runtime model rewriting caused unexpected provider/model mismatches. If model deprecations must be handled automatically in the future, prefer provider-layer alias resolution (single responsibility) plus logging/metrics so upgrades are observable and testable.

Files changed (18) +17 / -43

Bug fix (15) +17 / -18
RealtimeHub.csStop upgrading realtime hub model via settings service +1/-1

Stop upgrading realtime hub model via settings service

• Uses the configured model value directly instead of passing it through GetUpgradeModel. This keeps realtime hub model selection explicit and predictable.

src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs

ConversationService.Summary.csUse GPT-4o constant as summarization default model +1/-1

Use GPT-4o constant as summarization default model

• Removes GetUpgradeModel usage and defaults directly to GPT_4o. Prevents silent model substitution during conversation summarization.

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs

FileInstructService.Image.csUse GPT-4o constant for multimodal image reading default +1/-1

Use GPT-4o constant for multimodal image reading default

• Stops upgrading the default multimodal model via settings service. Uses GPT_4o directly when options do not specify a model.

src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs

CompletionProvider.csRemove model upgrade mapping for audio transcription and TTS defaults +2/-2

Remove model upgrade mapping for audio transcription and TTS defaults

• Sets default model names directly to GPT_4o_Mini_Transcribe and GPT_4o_Mini_Tts. Avoids runtime remapping when creating audio transcriber/synthesizer instances.

src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs

InstructService.Instruct.csUse GPT-4o constant as instruct default model +1/-1

Use GPT-4o constant as instruct default model

• Replaces GetUpgradeModel-based defaulting with a direct GPT_4o constant. Keeps instruct execution model choice stable unless explicitly overridden.

src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs

JsonRepairService.csUse GPT-4o Mini constant for JSON repair default model +1/-1

Use GPT-4o Mini constant for JSON repair default model

• Stops upgrading the JSON repair default model via settings service. Uses GPT_4o_Mini directly when no model is provided.

src/Infrastructure/BotSharp.Core/Shared/JsonRepairService.cs

WebIntelligentSearchFn.csUse GPT-4o Mini Search Preview constant for web search default +1/-1

Use GPT-4o Mini Search Preview constant for web search default

• Removes GetUpgradeModel from web search completion selection. The web-search default model is now the explicit preview constant.

src/Infrastructure/BotSharp.Core/WebSearch/Functions/WebIntelligentSearchFn.cs

ReadAudioFn.csUse fixed transcribe model constant in audio handler +1/-1

Use fixed transcribe model constant in audio handler

• Stops upgrading the transcription model via settings service. The audio handler now uses GPT_4o_Mini_Transcribe directly.

src/Plugins/BotSharp.Plugin.AudioHandler/Functions/ReadAudioFn.cs

HandleEmailReaderFn.csUse GPT-4o constant for email reader completion model lookup +1/-1

Use GPT-4o constant for email reader completion model lookup

• Removes GetUpgradeModel from provider model resolution. Email reader now requests the GPT_4o model ID directly from the provider model list.

src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs

RealTimeCompletionProvider.csStop upgrading GoogleAI realtime model via settings service +1/-1

Stop upgrading GoogleAI realtime model via settings service

• Uses RealtimeModelSettings.Model directly instead of applying upgrade mapping. Keeps Google realtime session model consistent with configured settings.

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Realtime/RealTimeCompletionProvider.cs

AiResponseHelper.csUse GPT-4o Mini constant for image handler chat completion default +1/-1

Use GPT-4o Mini constant for image handler chat completion default

• Removes settings-based model upgrade logic. Defaults to GPT_4o_Mini when the agent does not specify a model.

src/Plugins/BotSharp.Plugin.ImageHandler/Helpers/AiResponseHelper.cs

RealTimeCompletionProvider.csRemove model upgrade mapping from OpenAI realtime initialization and updates +2/-3

Remove model upgrade mapping from OpenAI realtime initialization and updates

• Stops rewriting the realtime model during provider construction and connection. Also uses configured transcription model directly during session updates.

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs

SequentialPlanner.csUse GPT-4o constant in sequential planner provider model selection +1/-1

Use GPT-4o constant in sequential planner provider model selection

• Removes GetUpgradeModel from planner model lookup. The planner now resolves GPT_4o directly from the provider model registry.

src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs

SqlValidateFn.csUse GPT-4o constant for SQL validation instruct options +1/-1

Use GPT-4o constant for SQL validation instruct options

• Eliminates upgrade mapping when setting the SQL validation model. Uses GPT_4o directly in instruct options.

src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs

DbKnowledgeService.csUse GPT-4o constant as default model for DB knowledge import +1/-1

Use GPT-4o constant as default model for DB knowledge import

• Removes GetUpgradeModel usage when defaulting the import model. Imports now default to GPT_4o unless a request model is supplied.

src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs

Refactor (2) +0 / -15
ISettingService.csRemove GetUpgradeModel from settings service contract +0/-2

Remove GetUpgradeModel from settings service contract

• Drops the model-upgrade method from the interface, reflecting removal of the mapping feature. Callers must now use explicit model IDs or their own settings directly.

src/Infrastructure/BotSharp.Abstraction/Settings/ISettingService.cs

SettingService.csDelete GetUpgradeModel implementation +0/-13

Delete GetUpgradeModel implementation

• Removes the upgrade-map lookup logic that depended on ModelUpgradeMapSettings. SettingService now no longer performs model name translation.

src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs

Other (1) +0 / -10
AgentPlugin.csRemove DI registration for model upgrade map settings +0/-10

Remove DI registration for model upgrade map settings

• Deletes the scoped registration that bound ModelUpgradeMap from configuration. This aligns DI with the reverted model-upgrade mapping functionality.

src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. gpt-4o setting missing 🐞 Bug ☼ Reliability
Description
Code paths now pass Gpt4xModelConstants.GPT_4o ("gpt-4o") directly, but the repo's OpenAI
LlmProviders models do not define a model with Name == "gpt-4o". When OpenAI
ProviderHelper.GetClient is invoked, GetSetting returns null and settings!.ApiKey can throw a
NullReferenceException at runtime.
Code

src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs[67]

+                    Model = Gpt4xModelConstants.GPT_4o,
Evidence
Gpt4xModelConstants.GPT_4o is "gpt-4o" and is now used directly (e.g., SqlValidateFn and
InstructService). The default src/WebStarter/appsettings.json OpenAI model list contains
gpt-4o-2024-11-20 and gpt-4o-mini but not gpt-4o, so ILlmProviderService.GetSetting will
return null; OpenAI ProviderHelper.GetClient then dereferences settings!.ApiKey, which can
crash.

src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs[3-13]
src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs[63-76]
src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs[95-103]
src/WebStarter/appsettings.json[154-205]
src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderService.cs[77-95]
src/Plugins/BotSharp.Plugin.OpenAI/Providers/ProviderHelper.cs[8-15]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
Several call sites now hardcode the model name `gpt-4o` (via `Gpt4xModelConstants.GPT_4o`). In the repo’s default configuration, OpenAI models are configured with names like `gpt-4o-2024-11-20` and `gpt-4o-mini`, so `ILlmProviderService.GetSetting("openai", "gpt-4o")` returns `null` and OpenAI client creation can crash.

### Issue Context
- `LlmProviderService.GetSetting` resolves by **model Name** (not Id).
- `BotSharp.Plugin.OpenAI` uses `ProviderHelper.GetClient(...)` which dereferences `settings!.ApiKey`.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs[63-76]
- src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs[22-33]
- src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs[95-103]

**Suggested remediation options (pick one):**
1. **Config fix:** Add an OpenAI model entry with `Name: "gpt-4o"` under `LlmProviders` (and any other environments, e.g. tests), so `GetSetting` succeeds.
2. **Code fix:** Stop passing `gpt-4o` directly; instead, select a configured model name (e.g., `gpt-4o-2024-11-20`) or resolve via `ILlmProviderService` (e.g., choose a model by Id/group/capability and use `.Name`).
3. **Hardening (recommended regardless):** Add explicit null checks in OpenAI client creation paths so a missing model setting fails with a clear exception instead of a NullReferenceException.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Realtime model not configured 🐞 Bug ☼ Reliability
Description
The OpenAI realtime provider no longer upgrades the model name, so the repo default
RealtimeModel.Model ("gpt-realtime") is used as-is. RealTimeCompletionProvider.BuildHeaders
calls GetSetting(Provider, _model) and dereferences settings.ApiKey without a null check, which
will throw if "gpt-realtime" is not present in LlmProviders.
Code

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs[46]

-        _model = settingService.GetUpgradeModel(_model);
Evidence
The repo config sets RealtimeModel.Model to gpt-realtime while the OpenAI LlmProviders list
does not include gpt-realtime (it includes gpt-4o-mini-realtime-preview-2024-12-17).
BuildHeaders() dereferences settings.ApiKey without a null check, so a missing model setting
will crash during realtime Connect.

src/WebStarter/appsettings.json[1002-1014]
src/WebStarter/appsettings.json[154-215]
src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs[728-738]
src/Infrastructure/BotSharp.Core/Infrastructures/LlmProviderService.cs[77-95]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
After removing `GetUpgradeModel`, realtime connections may now use `RealtimeModel.Model = "gpt-realtime"` directly. The OpenAI realtime provider requires a corresponding `LlmProviders` model setting (for ApiKey resolution), but the repo’s OpenAI models list does not include `Name: "gpt-realtime"`, causing `BuildHeaders()` to throw.

### Issue Context
- `src/WebStarter/appsettings.json` sets `RealtimeModel.Model` to `gpt-realtime`.
- `LlmProviders` for OpenAI does not define a model named `gpt-realtime` (but does define a realtime model like `gpt-4o-mini-realtime-preview-2024-12-17`).
- `BuildHeaders()` assumes `GetSetting(...)` is non-null.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs[728-738]
- src/WebStarter/appsettings.json[1002-1014]
- src/WebStarter/appsettings.json[154-215]

**Suggested remediation (do both):**
1. **Config:** Change `RealtimeModel.Model` to a model name that exists under `LlmProviders` (e.g., `gpt-4o-mini-realtime-preview-2024-12-17` as currently configured).
2. **Code hardening:** Update `BuildHeaders()` to handle `settings == null` (throw a clear `InvalidOperationException` like `Can't find model settings for openai.<model>`), instead of a NullReferenceException.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

{
Provider = "openai",
Model = settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o),
Model = Gpt4xModelConstants.GPT_4o,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Action required

1. Gpt-4o setting missing 🐞 Bug ☼ Reliability

Code paths now pass Gpt4xModelConstants.GPT_4o ("gpt-4o") directly, but the repo's OpenAI
LlmProviders models do not define a model with Name == "gpt-4o". When OpenAI
ProviderHelper.GetClient is invoked, GetSetting returns null and settings!.ApiKey can throw a
NullReferenceException at runtime.
Agent Prompt
### Issue description
Several call sites now hardcode the model name `gpt-4o` (via `Gpt4xModelConstants.GPT_4o`). In the repo’s default configuration, OpenAI models are configured with names like `gpt-4o-2024-11-20` and `gpt-4o-mini`, so `ILlmProviderService.GetSetting("openai", "gpt-4o")` returns `null` and OpenAI client creation can crash.

### Issue Context
- `LlmProviderService.GetSetting` resolves by **model Name** (not Id).
- `BotSharp.Plugin.OpenAI` uses `ProviderHelper.GetClient(...)` which dereferences `settings!.ApiKey`.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs[63-76]
- src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs[22-33]
- src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs[95-103]

**Suggested remediation options (pick one):**
1. **Config fix:** Add an OpenAI model entry with `Name: "gpt-4o"` under `LlmProviders` (and any other environments, e.g. tests), so `GetSetting` succeeds.
2. **Code fix:** Stop passing `gpt-4o` directly; instead, select a configured model name (e.g., `gpt-4o-2024-11-20`) or resolve via `ILlmProviderService` (e.g., choose a model by Id/group/capability and use `.Name`).
3. **Hardening (recommended regardless):** Add explicit null checks in OpenAI client creation paths so a missing model setting fails with a clear exception instead of a NullReferenceException.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

_botsharpOptions = botsharpOptions;

var settingService = _services.GetRequiredService<ISettingService>();
_model = settingService.GetUpgradeModel(_model);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Action required

2. Realtime model not configured 🐞 Bug ☼ Reliability

The OpenAI realtime provider no longer upgrades the model name, so the repo default
RealtimeModel.Model ("gpt-realtime") is used as-is. RealTimeCompletionProvider.BuildHeaders
calls GetSetting(Provider, _model) and dereferences settings.ApiKey without a null check, which
will throw if "gpt-realtime" is not present in LlmProviders.
Agent Prompt
### Issue description
After removing `GetUpgradeModel`, realtime connections may now use `RealtimeModel.Model = "gpt-realtime"` directly. The OpenAI realtime provider requires a corresponding `LlmProviders` model setting (for ApiKey resolution), but the repo’s OpenAI models list does not include `Name: "gpt-realtime"`, causing `BuildHeaders()` to throw.

### Issue Context
- `src/WebStarter/appsettings.json` sets `RealtimeModel.Model` to `gpt-realtime`.
- `LlmProviders` for OpenAI does not define a model named `gpt-realtime` (but does define a realtime model like `gpt-4o-mini-realtime-preview-2024-12-17`).
- `BuildHeaders()` assumes `GetSetting(...)` is non-null.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs[728-738]
- src/WebStarter/appsettings.json[1002-1014]
- src/WebStarter/appsettings.json[154-215]

**Suggested remediation (do both):**
1. **Config:** Change `RealtimeModel.Model` to a model name that exists under `LlmProviders` (e.g., `gpt-4o-mini-realtime-preview-2024-12-17` as currently configured).
2. **Code hardening:** Update `BuildHeaders()` to handle `settings == null` (throw a clear `InvalidOperationException` like `Can't find model settings for openai.<model>`), instead of a NullReferenceException.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@yileicn

yileicn commented Jun 17, 2026

Copy link
Copy Markdown
Member

reviewed

@yileicn yileicn merged commit bfe1884 into SciSharp:master Jun 17, 2026
4 checks passed
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