Merge branch 'master' of https://github.com/SciSharp/BotSharp into features/init-reactive-x

This commit is contained in:
Jicheng Lu 2025-07-25 16:12:31 -05:00
commit 734d8f7f2e
5 changed files with 35 additions and 16 deletions

View file

@ -45,8 +45,8 @@
<PackageVersion Include="Whisper.net" Version="1.8.1" />
<PackageVersion Include="Whisper.net.Runtime" Version="1.8.1" />
<PackageVersion Include="NCrontab" Version="3.3.3" />
<PackageVersion Include="Azure.AI.OpenAI" Version="2.2.0-beta.4" />
<PackageVersion Include="OpenAI" Version="2.2.0-beta.4" />
<PackageVersion Include="Azure.AI.OpenAI" Version="2.2.0-beta.5" />
<PackageVersion Include="OpenAI" Version="2.2.0" />
<PackageVersion Include="MailKit" Version="4.11.0" />
<PackageVersion Include="Microsoft.Data.Sqlite" Version="8.0.8" />
<PackageVersion Include="MySql.Data" Version="9.0.0" />
@ -148,4 +148,4 @@
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.25" />
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.26" />
</ItemGroup>
</Project>
</Project>

View file

@ -213,7 +213,7 @@ public class CompletionProvider
model = agentConfig?.Model ?? agentSetting.LlmConfig?.Model;
if (state.ContainsState("model"))
{
model = state.GetState("model", model ?? "dall-e-3");
model = state.GetState("model", model ?? "gpt-image-1");
}
else if (state.ContainsState("model_id") || !string.IsNullOrEmpty(modelId))
{

View file

@ -38,10 +38,8 @@ public partial class ImageCompletionProvider
var options = new ImageGenerationOptions
{
Size = size,
Quality = quality,
Style = style,
ResponseFormat = format
Quality = new GeneratedImageQuality("medium"),
Size = GeneratedImageSize.W1024xH1024
};
return (prompt, count, options);
}

View file

@ -44,7 +44,7 @@ public partial class ImageCompletionProvider : IImageCompletion
{
generatedImage.ImageUrl = image?.ImageUri?.AbsoluteUri ?? string.Empty;
}
else if (format == GeneratedImageFormat.Bytes)
else
{
var base64Str = string.Empty;
var bytes = image?.ImageBytes?.ToArray();
@ -125,16 +125,16 @@ public partial class ImageCompletionProvider : IImageCompletion
private GeneratedImageFormat GetImageFormat(string format)
{
var value = !string.IsNullOrEmpty(format) ? format : "uri";
var value = !string.IsNullOrEmpty(format) ? format : "bytes";
GeneratedImageFormat retFormat;
switch (value)
{
case "bytes":
retFormat = GeneratedImageFormat.Bytes;
case "url":
retFormat = GeneratedImageFormat.Uri;
break;
default:
retFormat = GeneratedImageFormat.Uri;
retFormat = GeneratedImageFormat.Bytes;
break;
}

View file

@ -3,6 +3,7 @@ using BotSharp.Abstraction.MLTasks;
using BotSharp.Abstraction.Realtime;
using BotSharp.Abstraction.Realtime.Models;
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Utilities;
using BotSharp.Plugin.Twilio.Interfaces;
using BotSharp.Plugin.Twilio.Models.Stream;
using Microsoft.AspNetCore.Http;
@ -88,10 +89,15 @@ public class TwilioStreamMiddleware
continue;
}
var (eventType, data) = MapEvents(conn, receivedText);
var (eventType, data) = MapEvents(conn, receivedText, conversationId);
if (eventType == "user_connected")
{
#if DEBUG
_logger.LogCritical($"Start twilio stream connection for conversation ({conversationId})");
#else
_logger.LogInformation($"Start twilio stream connection for conversation ({conversationId})");
#endif
// Connect to model
await ConnectToModel(hub, webSocket);
}
@ -115,6 +121,11 @@ public class TwilioStreamMiddleware
}
else if (eventType == "user_disconnected")
{
#if DEBUG
_logger.LogCritical($"Disconnecting twilio stream connection for conversation ({conversationId})");
#else
_logger.LogInformation($"Disconnecting twilio stream connection for conversation ({conversationId})");
#endif
await hub.Completer.Disconnect();
await HandleUserDisconnected();
}
@ -131,9 +142,19 @@ public class TwilioStreamMiddleware
});
}
private (string, string) MapEvents(RealtimeHubConnection conn, string receivedText)
private (string, string) MapEvents(RealtimeHubConnection conn, string receivedText, string conversationId)
{
var response = JsonSerializer.Deserialize<StreamEventResponse>(receivedText);
StreamEventResponse? response = new();
try
{
response = JsonSerializer.Deserialize<StreamEventResponse>(receivedText);
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error when deserializing twilio stream event response for conversation ({conversationId}) (response: {receivedText?.SubstringMax(30)})");
}
conn.StreamId = response.StreamSid;
string eventType = response.Event;
string data = string.Empty;