Skip to content

Commit da9c3c6

Browse files
author
Jicheng Lu
committed
temp save
1 parent c837dd6 commit da9c3c6

8 files changed

Lines changed: 315 additions & 200 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/MLTasks/IRealTimeCompletion.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using BotSharp.Abstraction.Realtime.Models;
2+
using System;
3+
using static System.Runtime.InteropServices.JavaScript.JSType;
24

35
namespace BotSharp.Abstraction.MLTasks;
46

@@ -10,14 +12,14 @@ public interface IRealTimeCompletion
1012

1113
Task Connect(
1214
RealtimeHubConnection conn,
13-
Action onModelReady,
14-
Action<string, string> onModelAudioDeltaReceived,
15-
Action onModelAudioResponseDone,
16-
Action<string> onAudioTranscriptDone,
17-
Action<List<RoleDialogModel>> onModelResponseDone,
18-
Action<string> onConversationItemCreated,
19-
Action<RoleDialogModel> onInputAudioTranscriptionCompleted,
20-
Action onInterruptionDetected);
15+
Func<Task> onModelReady,
16+
Func<string, string, Task> onModelAudioDeltaReceived,
17+
Func<Task> onModelAudioResponseDone,
18+
Func<string, Task> onModelAudioTranscriptDone,
19+
Func<List<RoleDialogModel>, Task> onModelResponseDone,
20+
Func<string, Task> onConversationItemCreated,
21+
Func<RoleDialogModel, Task> onInputAudioTranscriptionDone,
22+
Func<Task> onInterruptionDetected);
2123
Task AppenAudioBuffer(string message);
2224
Task AppenAudioBuffer(ArraySegment<byte> data, int length);
2325

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ await _completer.Connect(
7676
{
7777
var data = _conn.OnModelAudioResponseDone();
7878
await (responseToUser?.Invoke(data) ?? Task.CompletedTask);
79-
},
80-
onAudioTranscriptDone: async transcript =>
79+
},
80+
onModelAudioTranscriptDone: async transcript =>
8181
{
8282

8383
},
@@ -117,7 +117,7 @@ await _completer.Connect(
117117
{
118118

119119
},
120-
onInputAudioTranscriptionCompleted: async message =>
120+
onInputAudioTranscriptionDone: async message =>
121121
{
122122
// append input audio transcript to conversation
123123
dialogs.Add(message);

src/Infrastructure/BotSharp.Core/Infrastructures/Websocket/AsyncWebsocketDataResultEnumerator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public async ValueTask<bool> MoveNextAsync()
4444

4545
if (receivedResult.CloseStatus.HasValue)
4646
{
47-
Console.WriteLine($"Web socket close status: {receivedResult.CloseStatus}");
47+
#if DEBUG
48+
Console.WriteLine($"Websocket close: {receivedResult.CloseStatus} {receivedResult.CloseStatusDescription}");
49+
#endif
4850
Current = null;
4951
return false;
5052
}

src/Plugins/BotSharp.Plugin.GoogleAI/BotSharp.Plugin.GoogleAI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>$(TargetFramework)</TargetFramework>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using GenerativeAI.Types;
2+
3+
namespace BotSharp.Plugin.GoogleAI.Models.Realtime;
4+
5+
internal class RealtimeServerResponse
6+
{
7+
[JsonPropertyName("setupComplete")]
8+
public RealtimeGenerateContentSetupComplete? SetupComplete { get; set; }
9+
10+
[JsonPropertyName("serverContent")]
11+
public RealtimeGenerateContentServerContent? ServerContent { get; set; }
12+
13+
[JsonPropertyName("usageMetadata")]
14+
public RealtimeUsageMetaData? UsageMetaData { get; set; }
15+
}
16+
17+
18+
internal class RealtimeGenerateContentSetupComplete { }
19+
20+
internal class RealtimeGenerateContentServerContent
21+
{
22+
[JsonPropertyName("turnComplete")]
23+
public bool? TurnComplete { get; set; }
24+
25+
[JsonPropertyName("generationComplete")]
26+
public bool? GenerationComplete { get; set; }
27+
28+
[JsonPropertyName("interrupted")]
29+
public bool? Interrupted { get; set; }
30+
31+
[JsonPropertyName("modelTurn")]
32+
public Content? ModelTurn { get; set; }
33+
}
34+
35+
internal class RealtimeUsageMetaData
36+
{
37+
[JsonPropertyName("promptTokenCount")]
38+
public int? PromptTokenCount { get; set; }
39+
40+
[JsonPropertyName("responseTokenCount")]
41+
public int? ResponseTokenCount { get; set; }
42+
43+
[JsonPropertyName("totalTokenCount")]
44+
public int? TotalTokenCount { get; set; }
45+
46+
[JsonPropertyName("promptTokensDetails")]
47+
public List<RealtimeTokenDetail>? PromptTokensDetails { get; set; }
48+
49+
[JsonPropertyName("responseTokensDetails")]
50+
public List<RealtimeTokenDetail>? ResponseTokensDetails { get; set; }
51+
}
52+
53+
54+
internal class RealtimeTokenDetail
55+
{
56+
[JsonPropertyName("modality")]
57+
public string? Modality { get; set; }
58+
59+
[JsonPropertyName("tokenCount")]
60+
public int? TokenCount { get; set; }
61+
}

0 commit comments

Comments
 (0)