Browse Source

Merge pull request #1 from Norne9/Norne9-patch-chat-session

Optional IHistoryTransform added to ChatSession.InitializeSessionFromHistoryAsync
pull/711/head
Norne9 GitHub 2 years ago
parent
commit
5c60e6d4ca
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>
/// <param name="executor">The executor 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(
ILLamaExecutor executor, ChatHistory history)
ILLamaExecutor executor, ChatHistory history, IHistoryTransform? transform = null)
{
if (executor is not StatefulExecutorBase statefulExecutor)
{
throw new ArgumentException("Executor must have a StatefulExecutorBase", nameof(executor));
}
var session = new ChatSession(executor, history);
if (transform != null)
{
session = session.WithHistoryTransform(transform);
}

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

Loading…
Cancel
Save