Skip to content

Commit

Permalink
Merge pull request #410 from uezo/improve-dialog-processing-20241214
Browse files Browse the repository at this point in the history
Improve dialog processing
  • Loading branch information
uezo authored Dec 13, 2024
2 parents d7854ac + 65ddef1 commit a091d8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Scripts/Dialog/DialogPriorityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public void SetRequest(string text, Dictionary<string, object> payloads = null,
{
if (priority == 0)
{
_ = dialogProcessor.StartDialogAsync(text);
_ = dialogProcessor.StartDialogAsync(text + textToAppendNext);
}
else
{
dialogQueue.Enqueue(new DialogQueueItem() {
Priority = priority, Text = text + textToAppendNext, Payloads = payloads
}, priority);

textToAppendNext = string.Empty;
}

textToAppendNext = string.Empty;
}

public void SetRequestToAppendNext(string text)
Expand Down
12 changes: 9 additions & 3 deletions Scripts/Dialog/DialogProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum DialogStatus
// Actions for each status
public Func<string, Dictionary<string, object>, CancellationToken, UniTask> OnStartAsync { get; set; }
public Func<string, Dictionary<string, object>, CancellationToken, UniTask> OnRequestRecievedAsync { get; set; }
public Func<ILLMSession, CancellationToken, UniTask> OnBeforeProcessContentStreamAsync { get; set; }
public Func<string, Dictionary<string, object>, ILLMSession, CancellationToken, UniTask> OnResponseShownAsync { get; set; }
public Func<bool, CancellationToken, UniTask> OnEndAsync { get; set; }
public Func<bool, UniTask> OnStopAsync { get; set; }
Expand Down Expand Up @@ -109,7 +110,7 @@ public void LoadLLMTools()
}

// Start dialog
public async UniTask StartDialogAsync(string text, Dictionary<string, object> payloads = null)
public async UniTask StartDialogAsync(string text, Dictionary<string, object> payloads = null, bool overwrite = true)
{
if (string.IsNullOrEmpty(text) && (payloads == null || payloads.Count == 0))
{
Expand All @@ -120,8 +121,11 @@ public async UniTask StartDialogAsync(string text, Dictionary<string, object> pa
processingId = Guid.NewGuid().ToString();
var currentProcessingId = processingId;

// Stop running dialog and get cancellation token
await StopDialog(true);
if (overwrite)
{
// Stop running dialog and get cancellation token
await StopDialog(true);
}

var token = GetDialogToken();

Expand Down Expand Up @@ -166,6 +170,8 @@ public async UniTask StartDialogAsync(string text, Dictionary<string, object> pa
}
}

await OnBeforeProcessContentStreamAsync(llmSession, token);

// Start parsing voices, faces and animations
var processContentStreamTask = llmContentProcessor.ProcessContentStreamAsync(llmSession, token);

Expand Down

0 comments on commit a091d8a

Please sign in to comment.