Browse Source

InitializeSessionFromHistoryAsync changed

ChatSession.InitializeSessionFromHistoryAsync now accepts IHistoryTransform as an optional parameter.
pull/711/head^2
Norne9 GitHub 1 year ago
parent
commit
ad9bf1cbba
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      LLama/ChatSession.cs

+ 9
- 3
LLama/ChatSession.cs View File

@@ -74,15 +74,21 @@ public class ChatSession
/// </summary> /// </summary>
/// <param name="executor">The executor for this session</param> /// <param name="executor">The executor for this session</param>
/// <param name="history">History for this session</param> /// <param name="history">History for this session</param>
/// <returns></returns>
/// <param name="transform">History Transform for this session</param>
/// <returns>A new chat session.</returns>
public static async Task<ChatSession> InitializeSessionFromHistoryAsync( public static async Task<ChatSession> InitializeSessionFromHistoryAsync(
ILLamaExecutor executor, ChatHistory history)
ILLamaExecutor executor, ChatHistory history, IHistoryTransform? transform = null)
{ {
if (executor is not StatefulExecutorBase statefulExecutor) if (executor is not StatefulExecutorBase statefulExecutor)
{ {
throw new ArgumentException("Executor must have a StatefulExecutorBase", nameof(executor)); throw new ArgumentException("Executor must have a StatefulExecutorBase", nameof(executor));
} }
var session = new ChatSession(executor, history); var session = new ChatSession(executor, history);
if (transform != null)
{
session = session.WithHistoryTransform(transform);
}

await statefulExecutor.PrefillPromptAsync(session.HistoryTransform.HistoryToText(history)); await statefulExecutor.PrefillPromptAsync(session.HistoryTransform.HistoryToText(history));
return session; return session;
} }
@@ -780,4 +786,4 @@ public record SessionState
outputTransform, outputTransform,
historyTransform); historyTransform);
} }
}
}

Loading…
Cancel
Save