diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs index 6088ca46a..3ae30059f 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs @@ -64,16 +64,11 @@ public static string CleanStr(this string? str) return str.Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", ""); } - [GeneratedRegex(@"[^\u0000-\u007F]")] - private static partial Regex NonAsciiCharactersRegex(); - public static string CleanJsonStr(this string? str) { if (string.IsNullOrWhiteSpace(str)) return string.Empty; - str = str.Replace("```json", string.Empty).Replace("```", string.Empty).Trim(); - - return NonAsciiCharactersRegex().Replace(str, ""); + return str.Replace("```json", string.Empty).Replace("```", string.Empty).Trim(); } public static T? Json(this string text) diff --git a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs index 13112c2ad..8a1e32c8d 100644 --- a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs +++ b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs @@ -295,7 +295,7 @@ private async Task RunLlm( result = await GetChatCompletion(chatCompleter, agent, instruction, prompt, message.MessageId, files); } // Repair JSON format if needed - responseFormat = responseFormat ?? agentService.GetTemplateResponseFormat(agent, templateName); + responseFormat ??= agentService.GetTemplateResponseFormat(agent, templateName); if (responseFormat == ResponseFormatType.Json) { var jsonRepairService = _services.GetRequiredService(); diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Instruct/InstructModeController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Instruct/InstructModeController.cs index 344f0758b..9f5cb69b7 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Instruct/InstructModeController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Instruct/InstructModeController.cs @@ -65,7 +65,8 @@ public async Task InstructCompletionSse([FromRoute] string agentId, [FromBody] I templateName: input.Template, files: input.Files, codeOptions: input.CodeOptions, - fileOptions: input.FileOptions); + fileOptions: input.FileOptions, + responseFormat: input.ResponseFormat); result.States = state.GetStates();