revert
This commit is contained in:
parent
01175d1ebf
commit
44357bf1bb
|
|
@ -39,8 +39,8 @@ public class RealtimeHub : IRealtimeHub
|
|||
var dialogs = convService.GetDialogHistory();
|
||||
if (dialogs.Count == 0)
|
||||
{
|
||||
//dialogs.Add(new RoleDialogModel(AgentRole.User, "Hi"));
|
||||
//storage.Append(_conn.ConversationId, dialogs.First());
|
||||
dialogs.Add(new RoleDialogModel(AgentRole.User, "Hi"));
|
||||
storage.Append(_conn.ConversationId, dialogs.First());
|
||||
}
|
||||
|
||||
routing.Context.SetDialogs(dialogs);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
using BotSharp.Abstraction.Options;
|
||||
using BotSharp.Plugin.OpenAI.Models.Realtime;
|
||||
using BotSharp.Plugin.OpenAI.Providers.Realtime.Session;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenAI.Chat;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Channels;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System;
|
||||
|
||||
namespace BotSharp.Plugin.OpenAI.Providers.Realtime;
|
||||
|
||||
|
|
@ -25,9 +21,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
protected string _model = "gpt-4o-mini-realtime-preview";
|
||||
private RealtimeChatSession _session;
|
||||
|
||||
//private Channel<AudioMessage> _messageChannel;
|
||||
//private ConcurrentDictionary<string, AudioMessage> _messageDic;
|
||||
|
||||
public RealTimeCompletionProvider(
|
||||
RealtimeModelSettings settings,
|
||||
ILogger<RealTimeCompletionProvider> logger,
|
||||
|
|
@ -54,13 +47,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
var realtimeModelSettings = _services.GetRequiredService<RealtimeModelSettings>();
|
||||
_model = realtimeModelSettings.Model;
|
||||
|
||||
//_messageDic = new();
|
||||
//_messageChannel = Channel.CreateUnbounded<AudioMessage>(new UnboundedChannelOptions
|
||||
//{
|
||||
// SingleReader = true,
|
||||
// SingleWriter = true
|
||||
//});
|
||||
|
||||
if (_session != null)
|
||||
{
|
||||
_session.Dispose();
|
||||
|
|
@ -78,38 +64,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
onConversationItemCreated,
|
||||
onInputAudioTranscriptionCompleted,
|
||||
onInterruptionDetected);
|
||||
|
||||
//_ = Task.Run(async () =>
|
||||
//{
|
||||
// await foreach (var item in _messageChannel.Reader.ReadAllAsync())
|
||||
// {
|
||||
// var start = DateTime.UtcNow;
|
||||
// while (_messageDic.TryGetValue(item.ItemId, out var found) && !string.IsNullOrEmpty(found.Transcript))
|
||||
// {
|
||||
// if (found.Event == "conversation.item.input_audio_transcription.completed")
|
||||
// {
|
||||
// var message = await OnUserAudioTranscriptionCompleted(conn, found.ReceivedText);
|
||||
// if (!string.IsNullOrEmpty(message.Content))
|
||||
// {
|
||||
// onInputAudioTranscriptionCompleted(message);
|
||||
// }
|
||||
// _messageDic.TryRemove(found.ItemId, out _);
|
||||
// }
|
||||
// else if (found.Event == "response.done")
|
||||
// {
|
||||
// var messages = await OnResponsedDone(conn, found.ReceivedText);
|
||||
// onModelResponseDone(messages);
|
||||
// _messageDic.TryRemove(found.ItemId, out _);
|
||||
// }
|
||||
|
||||
// if ((DateTime.UtcNow - start).TotalSeconds > 2)
|
||||
// {
|
||||
// _messageDic.TryRemove(found.ItemId, out _);
|
||||
// start = DateTime.UtcNow;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//});
|
||||
}
|
||||
|
||||
public async Task Disconnect()
|
||||
|
|
@ -241,16 +195,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
{
|
||||
_logger.LogInformation($"{response.Type}: {receivedText}");
|
||||
|
||||
//var data = JsonSerializer.Deserialize<ResponseDone>(receivedText);
|
||||
//var output = data.Body.Outputs.FirstOrDefault();
|
||||
|
||||
//if (output != null && _messageDic.TryGetValue(output.Id, out var item))
|
||||
//{
|
||||
// item.Event = response.Type;
|
||||
// item.ReceivedText = receivedText;
|
||||
// item.Transcript = output.Content.FirstOrDefault()?.Transcript;
|
||||
//}
|
||||
|
||||
var messages = await OnResponsedDone(conn, receivedText);
|
||||
onModelResponseDone(messages);
|
||||
}
|
||||
|
|
@ -259,17 +203,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
_logger.LogInformation($"{response.Type}: {receivedText}");
|
||||
|
||||
var data = JsonSerializer.Deserialize<ConversationItemCreated>(receivedText);
|
||||
//_messageDic.TryAdd(data.Item.Id, new AudioMessage
|
||||
//{
|
||||
// ItemId = data.Item.Id,
|
||||
// ReceivedText = receivedText
|
||||
//});
|
||||
//await _messageChannel.Writer.WriteAsync(new AudioMessage
|
||||
//{
|
||||
// ItemId = data.Item.Id,
|
||||
// ReceivedText = receivedText
|
||||
//});
|
||||
|
||||
await Task.Delay(500);
|
||||
onConversationItemCreated(receivedText);
|
||||
}
|
||||
|
|
@ -277,14 +210,6 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
{
|
||||
_logger.LogInformation($"{response.Type}: {receivedText}");
|
||||
|
||||
//var data = JsonSerializer.Deserialize<ResponseAudioTranscript>(receivedText);
|
||||
//if (_messageDic.TryGetValue(data.ItemId, out var item))
|
||||
//{
|
||||
// item.Event = response.Type;
|
||||
// item.ReceivedText = receivedText;
|
||||
// item.Transcript = data.Transcript;
|
||||
//}
|
||||
|
||||
var message = await OnUserAudioTranscriptionCompleted(conn, receivedText);
|
||||
if (!string.IsNullOrEmpty(message.Content))
|
||||
{
|
||||
|
|
@ -305,12 +230,9 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
else if (response.Type == "input_audio_buffer.committed")
|
||||
{
|
||||
_logger.LogInformation($"{response.Type}: {receivedText}");
|
||||
await Task.Delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
//_messageChannel?.Writer.TryComplete();
|
||||
//_messageChannel = null;
|
||||
_session.Dispose();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue