Merge branch 'master' of https://github.com/SciSharp/BotSharp into features/add-knowledge-docs

This commit is contained in:
Jicheng Lu 2024-09-10 14:03:45 -05:00
commit f66d5f4101
4 changed files with 24 additions and 4 deletions

View file

@ -184,7 +184,7 @@ public class TwilioVoiceController : TwilioController
response = twilio.ReturnInstructions(new List<string>
{
$"twilio/voice/speeches/{conversationId}/{reply.SpeechFileName}"
}, $"twilio/voice/{conversationId}/receive/{nextSeqNum}?states={states}", true);
}, $"twilio/voice/{conversationId}/receive/{nextSeqNum}?states={states}", true, hints:reply.Hints);
}
}

View file

@ -7,5 +7,6 @@ namespace BotSharp.Plugin.Twilio.Models
public string Content { get; set; }
public string MessageId { get; set; }
public string SpeechFileName { get; set; }
public string Hints { get; set; }
}
}

View file

@ -106,8 +106,27 @@ namespace BotSharp.Plugin.Twilio.Services
var data = await completion.GenerateAudioFromTextAsync(reply.Content);
var fileName = $"reply_{reply.MessageId}.mp3";
fileStorage.SaveSpeechFile(message.ConversationId, fileName, data);
reply.SpeechFileName = fileName;
var phrases = reply.Content.Split(',', StringSplitOptions.RemoveEmptyEntries);
int capcity = 100;
var hints = new List<string>(capcity);
for (int i = phrases.Length - 1; i >= 0; i--)
{
var words = phrases[i].Split(' ', StringSplitOptions.RemoveEmptyEntries);
for (int j = words.Length - 1; j >= 0; j--)
{
hints.Add(words[j]);
if (hints.Count >= capcity)
{
break;
}
}
if (hints.Count >= capcity)
{
break;
}
}
reply.Hints = string.Join(',', hints);
reply.Content = null;
await sessionManager.SetAssistantReplyAsync(message.ConversationId, message.SeqNumber, reply);
}

View file

@ -66,7 +66,7 @@ public class TwilioService
return response;
}
public VoiceResponse ReturnInstructions(List<string> speechPaths, string callbackPath, bool actionOnEmptyResult, int timeout = 3)
public VoiceResponse ReturnInstructions(List<string> speechPaths, string callbackPath, bool actionOnEmptyResult, int timeout = 3, string hints = null)
{
var response = new VoiceResponse();
var gather = new Gather()
@ -81,7 +81,7 @@ public class TwilioService
SpeechTimeout = "auto", // timeout > 0 ? timeout.ToString() : "3",
Timeout = timeout > 0 ? timeout : 3,
ActionOnEmptyResult = actionOnEmptyResult,
Hints = "Yes, No, Correct"
Hints = hints
};
if (!speechPaths.IsNullOrEmpty())