From 8ca93b20ca343c9717ee528c48465ece460537ac Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Wed, 25 Nov 2026 11:11:36 +0800 Subject: [PATCH 1/7] fix(image): drop hardcoded image models and response_format for GPT image models - Remove gpt-image-1-mini / dall-e-2 fallbacks; fail with a clear error when no image model is configured - Stop sending response_format for OpenAI image generation/edit (GPT image models reject it) Co-Authored-By: Claude Opus 5.5 --- .../Instruct/FileInstructService.Image.cs | 25 +++++++++++++++---- .../Infrastructures/CompletionProvider.cs | 2 +- .../Functions/ComposeImageFn.cs | 5 +--- .../Functions/EditImageFn.cs | 5 +--- .../Functions/GenerateImageFn.cs | 5 +--- .../Providers/Image/ImageClientExtensions.cs | 2 +- .../Image/ImageCompletionProvider.Edit.cs | 7 +----- .../ImageCompletionProvider.Generation.cs | 7 +----- 8 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs index 50c609ca8..f1291ddbf 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs @@ -56,7 +56,8 @@ public async Task GenerateImage(string text, InstructOptions? o text = RenderText(text, options?.Data); var textContent = text.IfNullOrEmptyAs(instruction).IfNullOrEmptyAs(string.Empty); - var completion = CompletionProvider.GetImageCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? "gpt-image-1-mini"); + var (provider, model) = GetImageProviderModel(options); + var completion = CompletionProvider.GetImageCompletion(_services, provider: provider, model: model); var message = await completion.GetImageGeneration(new Agent() { Id = innerAgentId, @@ -86,7 +87,8 @@ public async Task VaryImage(InstructFileModel image, InstructOp } var innerAgentId = options?.AgentId ?? Guid.Empty.ToString(); - var completion = CompletionProvider.GetImageCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? "dall-e-2"); + var (provider, model) = GetImageProviderModel(options); + var completion = CompletionProvider.GetImageCompletion(_services, provider: provider, model: model); var binary = await DownloadFile(image); // Convert image @@ -132,7 +134,8 @@ public async Task EditImage(string text, InstructFileModel imag var instruction = await RenderAgentTemplate(innerAgentId, options?.TemplateName, options?.Data); text = RenderText(text, options?.Data); - var completion = CompletionProvider.GetImageCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? "gpt-image-1-mini"); + var (provider, model) = GetImageProviderModel(options); + var completion = CompletionProvider.GetImageCompletion(_services, provider: provider, model: model); var binary = await DownloadFile(image); // Convert image @@ -182,7 +185,8 @@ public async Task EditImage(string text, InstructFileModel imag var instruction = await RenderAgentTemplate(innerAgentId, options?.TemplateName, options?.Data); text = RenderText(text, options?.Data); - var completion = CompletionProvider.GetImageCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? "gpt-image-1-mini"); + var (provider, model) = GetImageProviderModel(options); + var completion = CompletionProvider.GetImageCompletion(_services, provider: provider, model: model); var imageBinary = await DownloadFile(image); var maskBinary = await DownloadFile(mask); @@ -235,7 +239,8 @@ public async Task ComposeImages(string text, InstructFileModel[ var instruction = await RenderAgentTemplate(innerAgentId, options?.TemplateName, options?.Data); text = RenderText(text, options?.Data); - var completion = CompletionProvider.GetImageCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? "gpt-image-1-mini"); + var (provider, model) = GetImageProviderModel(options); + var completion = CompletionProvider.GetImageCompletion(_services, provider: provider, model: model); var streams = new List(); var fileNames = new List(); @@ -283,4 +288,14 @@ await hook.OnResponseGenerated(new InstructResponseModel return message; } + + private static (string, string) GetImageProviderModel(InstructOptions? options) + { + if (string.IsNullOrEmpty(options?.Provider) || string.IsNullOrEmpty(options?.Model)) + { + throw new InvalidOperationException("Image provider and model are required."); + } + + return (options.Provider, options.Model); + } } diff --git a/src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs b/src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs index 12e33c1e8..9d01d3f41 100644 --- a/src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs +++ b/src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs @@ -286,7 +286,7 @@ private static (string, string) GetProviderAndModel( model = agentConfig?.Model ?? agentSetting.LlmConfig?.Model; if (state.ContainsState(LlmStateConst.MODEL)) { - model = state.GetState(LlmStateConst.MODEL, model ?? "gpt-image-1-mini"); + model = state.GetState(LlmStateConst.MODEL, model); } else if (state.ContainsState(LlmStateConst.MODEL_ID) || !string.IsNullOrEmpty(modelId)) { diff --git a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs index 8bd12ec29..d3966566d 100644 --- a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs +++ b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs @@ -134,10 +134,7 @@ private async Task GetImageEditGeneration(Agent agent, RoleDialogModel m return (provider, model); } - provider = "openai"; - model = "gpt-image-1-mini"; - - return (provider, model); + throw new InvalidOperationException("No image model is configured. Set ImageHandler:Composition or the agent's ImageComposition."); } private IEnumerable SaveGeneratedImage(ImageGeneration? image) diff --git a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs index bd7868ffc..f835a2ba7 100644 --- a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs +++ b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs @@ -136,10 +136,7 @@ private async Task GetImageEdit(Agent agent, RoleDialogModel message, st return (provider, model); } - provider = "openai"; - model = "gpt-image-1-mini"; - - return (provider, model); + throw new InvalidOperationException("No image model is configured. Set ImageHandler:Composition or the agent's ImageComposition."); } private IEnumerable SaveGeneratedImage(ImageGeneration? image) diff --git a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs index c24f28dd2..ad92ea0b8 100644 --- a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs +++ b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs @@ -98,10 +98,7 @@ private async Task GetImageGeneration(Agent agent, RoleDialogModel messa return (provider, model); } - provider = "openai"; - model = "gpt-image-1-mini"; - - return (provider, model); + throw new InvalidOperationException("No image model is configured. Set ImageHandler:Composition or the agent's ImageComposition."); } private IEnumerable SaveGeneratedImages(List? images) diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageClientExtensions.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageClientExtensions.cs index 9f2555042..b12c313b1 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageClientExtensions.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageClientExtensions.cs @@ -93,7 +93,7 @@ private static void BuildMultipartRequest( using var form = new MultipartFormDataContent(boundary) { { new StringContent(prompt), "prompt" }, - { new StringContent(model ?? "gpt-image-1-mini"), "model" } + { new StringContent(model), "model" } }; if (imageCount.HasValue) diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Edit.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Edit.cs index 5ec80f4e4..9e6dc55bb 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Edit.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Edit.cs @@ -116,14 +116,13 @@ public async Task GetImageEdits(Agent agent, RoleDialogModel me var state = _services.GetRequiredService(); var size = state.GetState(ImageStateConst.IMAGE_SIZE); var quality = state.GetState(ImageStateConst.IMAGE_QUALITY); - var responseFormat = state.GetState(ImageStateConst.IMAGE_RESPONSE_FORMAT); var background = state.GetState(ImageStateConst.IMAGE_BACKGROUND); size = LlmUtility.GetModelParameter(settings?.Parameters, "Size", size); quality = LlmUtility.GetModelParameter(settings?.Parameters, "Quality", quality); background = LlmUtility.GetModelParameter(settings?.Parameters, "Background", background); - responseFormat = LlmUtility.GetModelParameter(settings?.Parameters, "ResponseFormat", responseFormat); + // response_format is never sent: GPT image models reject it and always return base64. var options = new ImageEditOptions(); if (!string.IsNullOrEmpty(size)) { @@ -133,10 +132,6 @@ public async Task GetImageEdits(Agent agent, RoleDialogModel me { options.Quality = GetImageQuality(quality); } - if (!string.IsNullOrEmpty(responseFormat)) - { - options.ResponseFormat = GetImageResponseFormat(responseFormat); - } if (!string.IsNullOrEmpty(background)) { options.Background = GetImageBackground(background); diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Generation.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Generation.cs index e60e692e2..e65c72ede 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Generation.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Generation.cs @@ -65,15 +65,14 @@ public async Task GetImageGeneration(Agent agent, RoleDialogMod var size = state.GetState(ImageStateConst.IMAGE_SIZE); var quality = state.GetState(ImageStateConst.IMAGE_QUALITY); var style = state.GetState(ImageStateConst.IMAGE_STYLE); - var responseFormat = state.GetState(ImageStateConst.IMAGE_RESPONSE_FORMAT); var background = state.GetState(ImageStateConst.IMAGE_BACKGROUND); size = LlmUtility.GetModelParameter(settings?.Parameters, "Size", size); quality = LlmUtility.GetModelParameter(settings?.Parameters, "Quality", quality); style = LlmUtility.GetModelParameter(settings?.Parameters, "Style", style); background = LlmUtility.GetModelParameter(settings?.Parameters, "Background", background); - responseFormat = LlmUtility.GetModelParameter(settings?.Parameters, "ResponseFormat", responseFormat); + // response_format is never sent: GPT image models reject it and always return base64. var options = new ImageGenerationOptions(); if (!string.IsNullOrEmpty(size)) { @@ -87,10 +86,6 @@ public async Task GetImageGeneration(Agent agent, RoleDialogMod { options.Style = GetImageStyle(style); } - if (!string.IsNullOrEmpty(responseFormat)) - { - options.ResponseFormat = GetImageResponseFormat(responseFormat); - } if (!string.IsNullOrEmpty(background)) { options.Background = GetImageBackground(background); From abbe731c4dcd6bb0a7ef983c67e6cc5a544bbb5e Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Wed, 25 Nov 2026 11:16:50 +0800 Subject: [PATCH 2/7] refactor(image): stop setting image_response_format in image functions GPT image models do not support response_format and always return base64. Co-Authored-By: Claude Opus 5.5 --- .../BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs | 1 - .../BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs | 1 - .../BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs index d3966566d..21b6ef6da 100644 --- a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs +++ b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/ComposeImageFn.cs @@ -54,7 +54,6 @@ private void SetImageOptions() { var state = _services.GetRequiredService(); state.SetState(ImageStateConst.IMAGE_COUNT, "1"); - state.SetState(ImageStateConst.IMAGE_RESPONSE_FORMAT, "bytes"); } private async Task SelectImage(string? description) diff --git a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs index f835a2ba7..18dc02531 100644 --- a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs +++ b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/EditImageFn.cs @@ -54,7 +54,6 @@ private void SetImageOptions() { var state = _services.GetRequiredService(); state.SetState(ImageStateConst.IMAGE_COUNT, "1"); - state.SetState(ImageStateConst.IMAGE_RESPONSE_FORMAT, "bytes"); } private async Task SelectImage(string? description) diff --git a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs index ad92ea0b8..59fc4e742 100644 --- a/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs +++ b/src/Plugins/BotSharp.Plugin.ImageHandler/Functions/GenerateImageFn.cs @@ -51,7 +51,6 @@ private void SetImageOptions() var state = _services.GetRequiredService(); state.SetState(ImageStateConst.IMAGE_COUNT, "1"); state.SetState(ImageStateConst.IMAGE_QUALITY, "medium"); - state.SetState(ImageStateConst.IMAGE_RESPONSE_FORMAT, "bytes"); } private async Task GetImageGeneration(Agent agent, RoleDialogModel message, string? description) From 73cc5ce2659608fcff92c4f0a541149e8f0faaef Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Wed, 25 Nov 2026 11:27:15 +0800 Subject: [PATCH 3/7] refactor(image): remove image_response_format state and response_format handling GPT image models do not support response_format and always return base64, and DALL-E (the only models that used it) is retired on OpenAI and Azure. Both providers now read image bytes by default. Co-Authored-By: Claude Opus 5.5 --- .../Infrastructures/Enums/ImageStateConst.cs | 1 - .../Image/ImageCompletionProvider.Edit.cs | 4 +--- .../ImageCompletionProvider.Generation.cs | 4 +--- .../ImageCompletionProvider.Variation.cs | 4 +--- .../Image/ImageCompletionProvider.cs | 20 +------------------ .../ImageCompletionProvider.Variation.cs | 7 +------ .../Image/ImageCompletionProvider.cs | 18 ----------------- 7 files changed, 5 insertions(+), 53 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Infrastructures/Enums/ImageStateConst.cs b/src/Infrastructure/BotSharp.Abstraction/Infrastructures/Enums/ImageStateConst.cs index cb9e198c4..09145b0b9 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Infrastructures/Enums/ImageStateConst.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Infrastructures/Enums/ImageStateConst.cs @@ -10,5 +10,4 @@ public static class ImageStateConst public const string IMAGE_QUALITY = "image_quality"; public const string IMAGE_STYLE = "image_style"; public const string IMAGE_BACKGROUND = "image_background"; - public const string IMAGE_RESPONSE_FORMAT = "image_response_format"; } diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Edit.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Edit.cs index ee384a05b..76a77ce0b 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Edit.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Edit.cs @@ -54,13 +54,11 @@ public async Task GetImageEdits(Agent agent, RoleDialogModel me var state = _services.GetRequiredService(); var size = GetImageSize(state.GetState(ImageStateConst.IMAGE_SIZE)); - var format = GetImageFormat(state.GetState(ImageStateConst.IMAGE_RESPONSE_FORMAT)); var count = GetImageCount(state.GetState(ImageStateConst.IMAGE_COUNT)); var options = new ImageEditOptions { - Size = size, - ResponseFormat = format + Size = size }; return (prompt, count, options); } diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Generation.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Generation.cs index 4cb1e1b4d..63de1215f 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Generation.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Generation.cs @@ -34,15 +34,13 @@ public async Task GetImageGeneration(Agent agent, RoleDialogMod var size = GetImageSize(state.GetState(ImageStateConst.IMAGE_SIZE)); var quality = GetImageQuality(state.GetState(ImageStateConst.IMAGE_QUALITY)); var style = GetImageStyle(state.GetState(ImageStateConst.IMAGE_STYLE)); - var format = GetImageFormat(state.GetState(ImageStateConst.IMAGE_RESPONSE_FORMAT)); var count = GetImageCount(state.GetState(ImageStateConst.IMAGE_COUNT)); var options = new ImageGenerationOptions { Size = size, Quality = quality, - Style = style, - ResponseFormat = format + Style = style }; return (prompt, count, options); } diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Variation.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Variation.cs index 86e024a27..260abcd2c 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Variation.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.Variation.cs @@ -30,13 +30,11 @@ public async Task GetImageVariation(Agent agent, RoleDialogMode { var state = _services.GetRequiredService(); var size = GetImageSize(state.GetState(ImageStateConst.IMAGE_SIZE)); - var format = GetImageFormat(state.GetState(ImageStateConst.IMAGE_RESPONSE_FORMAT)); var count = GetImageCount(state.GetState(ImageStateConst.IMAGE_COUNT)); var options = new ImageVariationOptions { - Size = size, - ResponseFormat = format + Size = size }; return (count, options); } diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.cs index 033381f7a..54bff4274 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/Image/ImageCompletionProvider.cs @@ -44,7 +44,7 @@ private List GetImageGenerations(GeneratedImageCollection image { generatedImage.ImageUrl = image?.ImageUri?.AbsoluteUri ?? string.Empty; } - else if (format == GeneratedImageFormat.Bytes) + else { var base64Str = string.Empty; var bytes = image?.ImageBytes?.ToArray(); @@ -123,24 +123,6 @@ private GeneratedImageStyle GetImageStyle(string style) return retStyle; } - private GeneratedImageFormat GetImageFormat(string format) - { - var value = !string.IsNullOrEmpty(format) ? format : "uri"; - - GeneratedImageFormat retFormat; - switch (value) - { - case "bytes": - retFormat = GeneratedImageFormat.Bytes; - break; - default: - retFormat = GeneratedImageFormat.Uri; - break; - } - - return retFormat; - } - private int GetImageCount(int? count) { var retCount = count ?? DEFAULT_IMAGE_COUNT; diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Variation.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Variation.cs index 818bbda2a..a4205e3fa 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Variation.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.Variation.cs @@ -62,20 +62,15 @@ public async Task GetImageVariation(Agent agent, RoleDialogMode var state = _services.GetRequiredService(); var size = state.GetState(ImageStateConst.IMAGE_SIZE); - var responseFormat = state.GetState(ImageStateConst.IMAGE_RESPONSE_FORMAT); size = LlmUtility.GetModelParameter(settings?.Parameters, "Size", size); - responseFormat = LlmUtility.GetModelParameter(settings?.Parameters, "ResponseFormat", responseFormat); + // response_format is never sent: GPT image models reject it and always return base64. var options = new ImageVariationOptions(); if (!string.IsNullOrEmpty(size)) { options.Size = GetImageSize(size); } - if (!string.IsNullOrEmpty(responseFormat)) - { - options.ResponseFormat = GetImageResponseFormat(responseFormat); - } var count = GetImageCount(state.GetState(ImageStateConst.IMAGE_COUNT)); return (count, options); diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.cs index 9c037d002..22a82d000 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Image/ImageCompletionProvider.cs @@ -145,24 +145,6 @@ private GeneratedImageStyle GetImageStyle(string? style) return retStyle; } - private GeneratedImageFormat GetImageResponseFormat(string? format) - { - var value = !string.IsNullOrEmpty(format) ? format : "bytes"; - - GeneratedImageFormat retFormat; - switch (value) - { - case "url": - retFormat = GeneratedImageFormat.Uri; - break; - default: - retFormat = GeneratedImageFormat.Bytes; - break; - } - - return retFormat; - } - private GeneratedImageBackground GetImageBackground(string? background) { var value = !string.IsNullOrEmpty(background) ? background : "auto"; From 23e4723884c8b1405aaf20a43a9049f594a2fb3d Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Wed, 25 Nov 2026 14:23:58 +0800 Subject: [PATCH 4/7] fix(llm): drop hardcoded GPT-4o, audio, realtime and web search model fallbacks Text completions (conversation summary, image reading, instruct, JSON repair, email summary, sequential planner, SQL tools) now fall back to Agent:LlmConfig instead of gpt-4o / gpt-4o-mini. The conversation summary no longer prefers gpt-4o when it is listed in the provider's models. Audio transcription, speech synthesis, realtime and web search have no generic default to fall back to, so a missing model now raises an error instead of using a hardcoded, soon-retired model. Co-Authored-By: Claude Opus 5.5 --- .../Realtime/Models/ModelTurnDetection.cs | 2 +- .../Services/RealtimeHub.cs | 2 +- .../Services/ConversationService.Summary.cs | 28 ++++--------------- .../Instruct/FileInstructService.Image.cs | 3 +- .../Infrastructures/CompletionProvider.cs | 14 ++++++++-- .../Services/InstructService.Instruct.cs | 5 ++-- .../BotSharp.Core/Shared/JsonRepairService.cs | 5 ++-- .../Functions/WebIntelligentSearchFn.cs | 10 ++++--- .../Functions/ReadAudioFn.cs | 5 +--- .../Functions/HandleEmailReaderFn.cs | 6 ++-- .../Models/Realtime/RealtimeSessionBody.cs | 2 +- .../Realtime/RealTimeCompletionProvider.cs | 17 +++++++++-- .../Sequential/SequentialPlanner.cs | 6 ++-- .../Functions/SqlValidateFn.cs | 2 -- .../Services/DbKnowledgeService.cs | 6 ++-- 15 files changed, 61 insertions(+), 52 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Realtime/Models/ModelTurnDetection.cs b/src/Infrastructure/BotSharp.Abstraction/Realtime/Models/ModelTurnDetection.cs index 0fa48cdaa..879d52849 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Realtime/Models/ModelTurnDetection.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Realtime/Models/ModelTurnDetection.cs @@ -11,6 +11,6 @@ public class ModelTurnDetection public class AudioTranscription { - public string Model { get; set; } = Gpt4xModelConstants.GPT_4o_Mini_Transcribe; + public string? Model { get; set; } public string? Language { get; set; } } diff --git a/src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs b/src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs index b47ae4205..ee3fc6ce6 100644 --- a/src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs +++ b/src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs @@ -219,7 +219,7 @@ public RealtimeHubConnection SetHubConnection(string conversationId) return (_settings.Provider, _settings.Model, false); } - return ("openai", "gpt-realtime", false); + throw new InvalidOperationException("No realtime model is configured. Set RealtimeModel or the agent's Realtime config."); } /// diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs index cc6556f95..6509698c7 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs @@ -57,29 +57,13 @@ private string GetPrompt(Agent agent, string templateName, List contents private async Task Summarize(Agent agent, string prompt) { - var provider = "openai"; - string? model; - - var providerService = _services.GetRequiredService(); - var settingService = _services.GetRequiredService(); - var modelSettings = providerService.GetProviderModels(provider); - var defaultModel = Gpt4xModelConstants.GPT_4o; - var modelSetting = modelSettings.FirstOrDefault(x => x.Name.IsEqualTo(defaultModel)); - - if (modelSetting != null) - { - model = modelSetting.Name; - } - else + var provider = agent?.LlmConfig?.Provider; + var model = agent?.LlmConfig?.Model; + if (provider == null || model == null) { - provider = agent?.LlmConfig?.Provider; - model = agent?.LlmConfig?.Model; - if (provider == null || model == null) - { - var agentSettings = _services.GetRequiredService(); - provider = agentSettings.LlmConfig.Provider; - model = agentSettings.LlmConfig.Model; - } + var agentSettings = _services.GetRequiredService(); + provider = agentSettings.LlmConfig.Provider; + model = agentSettings.LlmConfig.Model; } var chatCompletion = CompletionProvider.GetChatCompletion(_services, provider, model); diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs index f1291ddbf..7efc617cf 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs @@ -16,7 +16,8 @@ public async Task ReadImages(string text, IEnumerable var instruction = await RenderAgentTemplate(innerAgentId, options?.TemplateName, options?.Data); text = RenderText(text, options?.Data); - var completion = CompletionProvider.GetChatCompletion(_services, provider: options?.Provider ?? "openai", model: options?.Model ?? Gpt4xModelConstants.GPT_4o, multiModal: true); + var agentSettings = _services.GetRequiredService(); + var completion = CompletionProvider.GetChatCompletion(_services, provider: options?.Provider ?? agentSettings.LlmConfig.Provider, model: options?.Model ?? agentSettings.LlmConfig.Model, multiModal: true); var message = await completion.GetChatCompletions(new Agent() { Id = innerAgentId, diff --git a/src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs b/src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs index 9d01d3f41..52c2f5206 100644 --- a/src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs +++ b/src/Infrastructure/BotSharp.Core/Infrastructures/CompletionProvider.cs @@ -167,7 +167,12 @@ public static IAudioTranscription GetAudioTranscriber( return default!; } - completer.SetModelName(model ?? Gpt4xModelConstants.GPT_4o_Mini_Transcribe); + if (string.IsNullOrEmpty(model)) + { + throw new InvalidOperationException("Audio transcription model is required."); + } + + completer.SetModelName(model); return completer; } @@ -186,7 +191,12 @@ public static IAudioSynthesis GetAudioSynthesizer( return default!; } - completer.SetModelName(model ?? Gpt4xModelConstants.GPT_4o_Mini_Tts); + if (string.IsNullOrEmpty(model)) + { + throw new InvalidOperationException("Audio synthesis model is required."); + } + + completer.SetModelName(model); return completer; } diff --git a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs index 07cea0933..6a20ef687 100644 --- a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs +++ b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Instruct.cs @@ -96,8 +96,9 @@ private async Task GetAiResponse(string text, Agent agent, Inst { var settingService = _services.GetRequiredService(); var dialogs = await BuildDialogs(text, options); - var provider = options?.Provider ?? agent?.LlmConfig?.Provider ?? "openai"; - var model = options?.Model ?? agent?.LlmConfig?.Model ?? Gpt4xModelConstants.GPT_4o; + var agentSettings = _services.GetRequiredService(); + var provider = options?.Provider ?? agent?.LlmConfig?.Provider ?? agentSettings.LlmConfig.Provider; + var model = options?.Model ?? agent?.LlmConfig?.Model ?? agentSettings.LlmConfig.Model; var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model); return await completion.GetChatCompletions(agent, dialogs); } diff --git a/src/Infrastructure/BotSharp.Core/Shared/JsonRepairService.cs b/src/Infrastructure/BotSharp.Core/Shared/JsonRepairService.cs index 032a93646..ae61a507b 100644 --- a/src/Infrastructure/BotSharp.Core/Shared/JsonRepairService.cs +++ b/src/Infrastructure/BotSharp.Core/Shared/JsonRepairService.cs @@ -99,9 +99,10 @@ private async Task RepairByLLMAsync(string malformedJson, JsonRepairOpti try { + var agentSettings = _services.GetRequiredService(); var completion = CompletionProvider.GetChatCompletion(_services, - provider: options?.Provider ?? agent?.LlmConfig?.Provider ?? "openai", - model: options?.Model ?? agent?.LlmConfig?.Model ?? Gpt4xModelConstants.GPT_4o_Mini); + provider: options?.Provider ?? agent?.LlmConfig?.Provider ?? agentSettings.LlmConfig.Provider, + model: options?.Model ?? agent?.LlmConfig?.Model ?? agentSettings.LlmConfig.Model); var innerAgent = new Agent { diff --git a/src/Infrastructure/BotSharp.Core/WebSearch/Functions/WebIntelligentSearchFn.cs b/src/Infrastructure/BotSharp.Core/WebSearch/Functions/WebIntelligentSearchFn.cs index b8687ca87..27fa8b199 100644 --- a/src/Infrastructure/BotSharp.Core/WebSearch/Functions/WebIntelligentSearchFn.cs +++ b/src/Infrastructure/BotSharp.Core/WebSearch/Functions/WebIntelligentSearchFn.cs @@ -84,13 +84,15 @@ private async Task GetChatCompletion(Agent agent, List } provider = "openai"; - model = Gpt4xModelConstants.GPT_4o_Mini_Search_Preview; - var models = llmProviderService.GetProviderModels(provider); var foundModel = models.FirstOrDefault(x => x.WebSearch?.IsDefault == true) ?? models.FirstOrDefault(x => x.WebSearch != null); - model = foundModel?.Name ?? model; - return (provider, model); + if (foundModel == null) + { + throw new InvalidOperationException("No web search model is configured. Add WebSearch settings to an openai model in LlmProviders."); + } + + return (provider, foundModel.Name); } } diff --git a/src/Plugins/BotSharp.Plugin.AudioHandler/Functions/ReadAudioFn.cs b/src/Plugins/BotSharp.Plugin.AudioHandler/Functions/ReadAudioFn.cs index 9878ec62b..bfdc84e4d 100644 --- a/src/Plugins/BotSharp.Plugin.AudioHandler/Functions/ReadAudioFn.cs +++ b/src/Plugins/BotSharp.Plugin.AudioHandler/Functions/ReadAudioFn.cs @@ -167,9 +167,6 @@ private bool VerifyAudioFileType(string fileName) return (provider, model); } - provider = "openai"; - model = Gpt4xModelConstants.GPT_4o_Mini_Transcribe; - - return (provider, model); + throw new InvalidOperationException("No audio transcription model is configured. Set AudioHandler:Audio:Reading or the agent's AudioTranscription."); } } diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs b/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs index 840db66f8..57d6f09de 100644 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs +++ b/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Agents.Settings; using BotSharp.Abstraction.Messaging.Models.RichContent.Template; using BotSharp.Abstraction.Models; using BotSharp.Abstraction.Settings; @@ -69,9 +70,8 @@ public async Task Execute(RoleDialogModel message) var llmProviderService = _services.GetRequiredService(); var settingService = _services.GetRequiredService(); - var provider = llmProviderService.GetProviders().FirstOrDefault(x => x == "openai"); - var model = llmProviderService.GetProviderModel(provider: provider ?? "openai", id: Gpt4xModelConstants.GPT_4o); - var completion = CompletionProvider.GetChatCompletion(_services, provider: provider, model: model?.Name); + var agentSettings = _services.GetRequiredService(); + var completion = CompletionProvider.GetChatCompletion(_services, provider: agentSettings.LlmConfig.Provider, model: agentSettings.LlmConfig.Model); var convService = _services.GetRequiredService(); var conversationId = convService.ConversationId; var dialogs = await convService.GetDialogHistory(fromBreakpoint: false); diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs index a437c696b..bb25a952a 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Models/Realtime/RealtimeSessionBody.cs @@ -83,7 +83,7 @@ public class RealtimeSessionTurnDetection public class InputAudioTranscription { [JsonPropertyName("model")] - public string Model { get; set; } = Gpt4xModelConstants.GPT_4o_Transcribe; + public string? Model { get; set; } [JsonPropertyName("language")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] diff --git a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs index 75acc51cb..ae908a20a 100644 --- a/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs @@ -19,7 +19,7 @@ public class RealTimeCompletionProvider : IRealTimeCompletion private readonly ILogger _logger; private readonly BotSharpOptions _botsharpOptions; - private string _model = "gpt-realtime"; + private string _model = string.Empty; private LlmRealtimeSession _session; private RealtimeOptions? _realtimeOptions; private bool _isBlocking = false; @@ -70,7 +70,15 @@ public async Task Connect( var realtimeSettings = _services.GetRequiredService(); var settingService = _services.GetRequiredService(); - _model ??= realtimeSettings.Model; + if (string.IsNullOrEmpty(_model)) + { + _model = realtimeSettings.Model; + } + + if (string.IsNullOrEmpty(_model)) + { + throw new InvalidOperationException("No realtime model is configured. Set RealtimeModel or the agent's Realtime config."); + } _session = new LlmRealtimeSession(_services, new ChatSessionOptions { Provider = Provider, @@ -381,6 +389,11 @@ public async Task UpdateSession(RealtimeHubConnection conn, bool isInit if (realtimeModelSettings.InputAudioTranscribe) { + if (string.IsNullOrEmpty(realtimeModelSettings.InputAudioTranscription.Model)) + { + throw new InvalidOperationException("RealtimeModel:InputAudioTranscription:Model is required when InputAudioTranscribe is enabled."); + } + var words = new List(); HookEmitter.Emit(_services, hook => words.AddRange(hook.OnModelTranscriptPrompt(agent)), agent.Id); diff --git a/src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs b/src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs index 692a4d9c2..78d0cdf8e 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs @@ -170,12 +170,12 @@ public async Task GetDecomposedStepAsync(Agent router, string me var llmProviderService = _services.GetRequiredService(); var settingService = _services.GetRequiredService(); - var model = llmProviderService.GetProviderModel("openai", Gpt4xModelConstants.GPT_4o); + var agentSettings = _services.GetRequiredService(); // chat completion var completion = CompletionProvider.GetChatCompletion(_services, - provider: "openai", - model: model?.Name); + provider: agentSettings.LlmConfig.Provider, + model: agentSettings.LlmConfig.Model); int retryCount = 0; while (retryCount < 2) diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs index 44ef8ec50..4667513f8 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Functions/SqlValidateFn.cs @@ -64,8 +64,6 @@ public async Task Execute(RoleDialogModel message) var correctedSql = await instructService.Instruct(query, new InstructOptions { - Provider = "openai", - Model = Gpt4xModelConstants.GPT_4o, AgentId = BuiltInAgentId.SqlDriver, TemplateName = "sql_statement_correctness", Data = new Dictionary diff --git a/src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs b/src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs index b2824053a..2090c7756 100644 --- a/src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs +++ b/src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs @@ -1,5 +1,6 @@ using static Dapper.SqlMapper; using MySqlConnector; +using BotSharp.Abstraction.Agents.Settings; using BotSharp.Abstraction.Knowledges.Enums; using BotSharp.Abstraction.VectorStorage.Models; using BotSharp.Abstraction.Models; @@ -26,8 +27,9 @@ public async Task Import(ImportDbKnowledgeRequest request) var kg = _services.GetServices() .FirstOrDefault(x => x.KnowledgeType.IsEqualTo(KnowledgeBaseType.QuestionAnswer)); - var provider = request.Provider ?? "openai"; - var model = request.Model ?? Gpt4xModelConstants.GPT_4o; + var agentSettings = _services.GetRequiredService(); + var provider = request.Provider ?? agentSettings.LlmConfig.Provider; + var model = request.Model ?? agentSettings.LlmConfig.Model; var schema = request.Schema; var collectionName = request.KnowledgebaseCollection; From 89750f612c01b0ec3f501af5022c8a3d6cb2c597 Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Wed, 25 Nov 2026 14:45:49 +0800 Subject: [PATCH 5/7] fix(twilio): configure the audio synthesis model through Twilio:AudioSynthesis The audio synthesizer no longer falls back to a hardcoded model, and Twilio called it without a provider or model, so pre-generated speech (SayGeneratedSpeech off, or hang up / transfer on a realtime call) always failed with no way to configure it. Co-Authored-By: Claude Opus 5.5 --- .../BotSharp.Plugin.Twilio/Services/TwilioService.cs | 4 +++- .../BotSharp.Plugin.Twilio/Settings/TwilioSetting.cs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs index e92c34564..b2b714113 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs @@ -480,7 +480,9 @@ public async Task SaveSpeechAsync(string conversationId, string name, st var data = useSay ? BinaryData.FromString(text) - : await CompletionProvider.GetAudioSynthesizer(_services).GenerateAudioAsync(text); + : await CompletionProvider.GetAudioSynthesizer(_services, + provider: _settings.AudioSynthesis?.Provider, + model: _settings.AudioSynthesis?.Model).GenerateAudioAsync(text); fileStorage.SaveSpeechFile(conversationId, fileName, data); return fileName; } diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Settings/TwilioSetting.cs b/src/Plugins/BotSharp.Plugin.Twilio/Settings/TwilioSetting.cs index af884284e..27352bea0 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Settings/TwilioSetting.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Settings/TwilioSetting.cs @@ -44,6 +44,12 @@ public class TwilioSetting /// public string? SayVoice { get; set; } + /// + /// Audio synthesis model for speech pre-generated as audio: always when SayGeneratedSpeech is off, and for + /// realtime calls even when it is on. Required for those paths. + /// + public LlmProviderModel? AudioSynthesis { get; set; } + /// /// Text of the prerecorded prompts under twilio/, keyed by file name without extension (e.g. "say-it-again-1"). /// Spoken with Say when SayGeneratedSpeech is on; prompts not listed keep playing their audio file. From c7c07c66823eb4557c1b8fc011a6d3e971c708b6 Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Wed, 25 Nov 2026 17:14:12 +0800 Subject: [PATCH 6/7] fix(twilio): a realtime call without Twilio:AudioSynthesis still hangs up and transfers Without an audio synthesis model, hang up and transfer on a realtime call play the mp3 already saved for the line, or go on without it, instead of throwing before the call is redirected. Co-Authored-By: Claude Opus 5.5 --- .../Functions/HangupPhoneCallFn.cs | 5 ++++- .../Functions/TransferPhoneCallFn.cs | 5 ++++- .../BotSharp.Plugin.Twilio/Services/TwilioService.cs | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs index 19ab6b94c..d8d432319 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/HangupPhoneCallFn.cs @@ -49,7 +49,10 @@ public async Task Execute(RoleDialogModel message) var initAudioFile = await twilio.SaveSpeechAsync(conversationId, "ending", args.ResponseContent, preferAudio: twilio.IsRealtimeCall()); - processUrl += $"&init-audio-file={initAudioFile}"; + if (!string.IsNullOrEmpty(initAudioFile)) + { + processUrl += $"&init-audio-file={initAudioFile}"; + } } // A call that already ended is what hanging up wants, so it still counts as hung up diff --git a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/TransferPhoneCallFn.cs b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/TransferPhoneCallFn.cs index 2553ddca2..0144f5b5c 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/TransferPhoneCallFn.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/OutboundPhoneCallHandler/Functions/TransferPhoneCallFn.cs @@ -54,7 +54,10 @@ public async Task Execute(RoleDialogModel message) var initAudioFile = await twilio.SaveSpeechAsync(conversationId, "transfer", args.TransitionMessage, preferAudio: twilio.IsRealtimeCall()); - processUrl += $"&init-audio-file={initAudioFile}"; + if (!string.IsNullOrEmpty(initAudioFile)) + { + processUrl += $"&init-audio-file={initAudioFile}"; + } } // Transfer call diff --git a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs index b2b714113..8a1b9521e 100644 --- a/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs +++ b/src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioService.cs @@ -473,11 +473,18 @@ public async Task SaveSpeechAsync(string conversationId, string name, st var fileStorage = _services.GetRequiredService(); var useSay = _settings.SayGeneratedSpeech && !preferAudio; var fileName = name + (useSay ? TextSpeechExtension : AudioSpeechExtension); - if (reuseExisting && !fileStorage.GetSpeechFile(conversationId, fileName).ToMemory().IsEmpty) + // Without a synthesis model a realtime call plays the mp3 already saved, or goes on without the speech + var noSynthesis = preferAudio && string.IsNullOrEmpty(_settings.AudioSynthesis?.Model); + if ((reuseExisting || noSynthesis) && !fileStorage.GetSpeechFile(conversationId, fileName).ToMemory().IsEmpty) { return fileName; } + if (noSynthesis) + { + return string.Empty; + } + var data = useSay ? BinaryData.FromString(text) : await CompletionProvider.GetAudioSynthesizer(_services, From cf18b5161d14a629d2e45e0cfdbba77983ca8709 Mon Sep 17 00:00:00 2001 From: "nick.yi" Date: Wed, 25 Nov 2026 17:16:46 +0800 Subject: [PATCH 7/7] chore: address review of the hardcoded model removal - text-to-speech returns 400 when no model is given instead of throwing - drop the ILlmProviderService locals left unused in EmailHandler and Planner - name the tuple GetImageProviderModel returns - remove the Gpt4xModelConstants no longer referenced - add a Twilio:AudioSynthesis example to appsettings Co-Authored-By: Claude Opus 5.5 --- .../BotSharp.Abstraction/Models/Gpt4xModelConstants.cs | 4 ---- .../Files/Services/Instruct/FileInstructService.Image.cs | 2 +- .../Controllers/Instruct/InstructModeController.Audio.cs | 5 +++++ .../Functions/HandleEmailReaderFn.cs | 1 - .../BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs | 1 - src/WebStarter/appsettings.json | 6 +++++- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs b/src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs index 8919b743c..649224905 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Models/Gpt4xModelConstants.cs @@ -4,9 +4,5 @@ public static class Gpt4xModelConstants { public const string GPT_4o = "gpt-4o"; public const string GPT_4o_Mini = "gpt-4o-mini"; - public const string GPT_4o_Mini_Search_Preview = "gpt-4o-mini-search-preview"; - public const string GPT_4o_Mini_Transcribe = "gpt-4o-mini-transcribe"; - public const string GPT_4o_Transcribe = "gpt-4o-transcribe"; - public const string GPT_4o_Mini_Tts = "gpt-4o-mini-tts"; public const string GPT_4o_Search_Preview = "gpt-4o-search-preview"; } diff --git a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs index 7efc617cf..835bb5862 100644 --- a/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs +++ b/src/Infrastructure/BotSharp.Core/Files/Services/Instruct/FileInstructService.Image.cs @@ -290,7 +290,7 @@ await hook.OnResponseGenerated(new InstructResponseModel return message; } - private static (string, string) GetImageProviderModel(InstructOptions? options) + private static (string Provider, string Model) GetImageProviderModel(InstructOptions? options) { if (string.IsNullOrEmpty(options?.Provider) || string.IsNullOrEmpty(options?.Model)) { diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Instruct/InstructModeController.Audio.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Instruct/InstructModeController.Audio.cs index 027e9e40b..ef4893b26 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Instruct/InstructModeController.Audio.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Instruct/InstructModeController.Audio.cs @@ -90,6 +90,11 @@ public async Task TextToSpeech([FromBody] TextToSpeechRequest req var state = _services.GetRequiredService(); request.States.ForEach(x => state.SetState(x.Key, x.Value, source: StateSource.External)); + if (string.IsNullOrEmpty(request.Model)) + { + return BadRequest("Audio synthesis model is required."); + } + var completion = CompletionProvider.GetAudioSynthesizer(_services, provider: request.Provider, model: request.Model); var binaryData = await completion.GenerateAudioAsync(request.Text); var stream = binaryData.ToStream(); diff --git a/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs b/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs index 57d6f09de..cbb634d83 100644 --- a/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs +++ b/src/Plugins/BotSharp.Plugin.EmailHandler/Functions/HandleEmailReaderFn.cs @@ -68,7 +68,6 @@ public async Task Execute(RoleDialogModel message) Instruction = prompt }; - var llmProviderService = _services.GetRequiredService(); var settingService = _services.GetRequiredService(); var agentSettings = _services.GetRequiredService(); var completion = CompletionProvider.GetChatCompletion(_services, provider: agentSettings.LlmConfig.Provider, model: agentSettings.LlmConfig.Model); diff --git a/src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs b/src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs index 78d0cdf8e..deaaf27c6 100644 --- a/src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs +++ b/src/Plugins/BotSharp.Plugin.Planner/Sequential/SequentialPlanner.cs @@ -168,7 +168,6 @@ public async Task GetDecomposedStepAsync(Agent router, string me var inst = new DecomposedStep(); - var llmProviderService = _services.GetRequiredService(); var settingService = _services.GetRequiredService(); var agentSettings = _services.GetRequiredService(); diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index eb90345c7..e8f2678ab 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -1489,7 +1489,11 @@ "AccountSID": "", "AuthToken": "", "CallbackHost": "https://", - "AgentId": "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a" + "AgentId": "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a", + "AudioSynthesis": { + "Provider": "openai", + "Model": "gpt-4o-mini-tts" + } }, "Database": {