Skip to content

Commit 8a6eb7d

Browse files
authored
Merge pull request #1047 from hchen2020/master
Twilio.GetHints
2 parents 16878b1 + a4d07d5 commit 8a6eb7d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ private async Task ReceiveMessage(
231231
_logger.LogInformation($"{response.Type}: {receivedText}");
232232

233233
var data = JsonSerializer.Deserialize<ConversationItemCreated>(receivedText);
234-
await Task.Delay(500);
235234
onConversationItemCreated(receivedText);
236235
}
237236
else if (response.Type == "conversation.item.input_audio_transcription.completed")
@@ -253,7 +252,6 @@ private async Task ReceiveMessage(
253252
else if (response.Type == "input_audio_buffer.speech_stopped")
254253
{
255254
_logger.LogInformation($"{response.Type}: {receivedText}");
256-
await Task.Delay(500);
257255
}
258256
else if (response.Type == "input_audio_buffer.committed")
259257
{

src/Plugins/BotSharp.Plugin.Twilio/Services/TwilioMessageQueueService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BotSharp.Abstraction.Files;
2+
using BotSharp.Abstraction.Realtime;
23
using BotSharp.Abstraction.Routing;
34
using BotSharp.Core.Infrastructures;
45
using BotSharp.Plugin.Twilio.Interfaces;
@@ -110,7 +111,7 @@ private async Task ProcessUserMessageAsync(CallerMessage message)
110111
reply.SpeechFileName = await GetReplySpeechFileName(message.ConversationId, reply, sp);
111112
}
112113

113-
reply.Hints = GetHints(reply);
114+
reply.Hints = GetHints(agentId, reply, sp);
114115
await sessionManager.SetAssistantReplyAsync(message.ConversationId, message.SeqNumber, reply);
115116
}
116117

@@ -151,8 +152,13 @@ private static async Task<string> GetReplySpeechFileName(string conversationId,
151152
return fileName;
152153
}
153154

154-
private static string GetHints(AssistantMessage reply)
155+
private static string GetHints(string agentId, AssistantMessage reply, IServiceProvider sp)
155156
{
157+
var agentService = sp.GetRequiredService<IAgentService>();
158+
var agent = agentService.GetAgent(agentId).Result;
159+
var extraWords = new List<string>();
160+
HookEmitter.Emit<IRealtimeHook>(sp, hook => extraWords.AddRange(hook.OnModelTranscriptPrompt(agent)));
161+
156162
var phrases = reply.Content.Split(',', StringSplitOptions.RemoveEmptyEntries);
157163
int capcity = 100;
158164
var hints = new List<string>(capcity);
@@ -174,6 +180,7 @@ private static string GetHints(AssistantMessage reply)
174180
}
175181
// add frequency short words
176182
hints.AddRange(["yes", "no", "correct", "right"]);
183+
hints.AddRange(extraWords);
177184
return string.Join(", ", hints.Select(x => x.ToLower()).Distinct().Reverse());
178185
}
179186

0 commit comments

Comments
 (0)