| @@ -21,5 +21,11 @@ namespace LLama.Abstractions | |||||
| /// <param name="text">The chat history as plain text.</param> | /// <param name="text">The chat history as plain text.</param> | ||||
| /// <returns>The updated history.</returns> | /// <returns>The updated history.</returns> | ||||
| ChatHistory TextToHistory(AuthorRole role, string text); | ChatHistory TextToHistory(AuthorRole role, string text); | ||||
| /// <summary> | |||||
| /// Copy the transform. | |||||
| /// </summary> | |||||
| /// <returns></returns> | |||||
| IHistoryTransform Clone(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -13,5 +13,11 @@ namespace LLama.Abstractions | |||||
| /// <param name="tokens"></param> | /// <param name="tokens"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| IAsyncEnumerable<string> TransformAsync(IAsyncEnumerable<string> tokens); | IAsyncEnumerable<string> TransformAsync(IAsyncEnumerable<string> tokens); | ||||
| /// <summary> | |||||
| /// Copy the transform. | |||||
| /// </summary> | |||||
| /// <returns></returns> | |||||
| ITextStreamTransform Clone(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -17,5 +17,11 @@ | |||||
| /// <param name="text"></param> | /// <param name="text"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| string Transform(string text); | string Transform(string text); | ||||
| /// <summary> | |||||
| /// Copy the transform. | |||||
| /// </summary> | |||||
| /// <returns></returns> | |||||
| ITextTransform Clone(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -189,9 +189,9 @@ public class ChatSession | |||||
| } | } | ||||
| Executor.Context.LoadState(state.ContextState); | Executor.Context.LoadState(state.ContextState); | ||||
| History = new ChatHistory(state.History); | History = new ChatHistory(state.History); | ||||
| InputTransformPipeline = state.InputTransformPipeline.ToList(); | |||||
| OutputTransform = state.OutputTransform; | |||||
| HistoryTransform = state.HistoryTransform; | |||||
| InputTransformPipeline = state.InputTransformPipeline.Select(t => t.Clone()).ToList(); | |||||
| OutputTransform = state.OutputTransform.Clone(); | |||||
| HistoryTransform = state.HistoryTransform.Clone(); | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -634,8 +634,8 @@ public record SessionState | |||||
| ContextState = contextState; | ContextState = contextState; | ||||
| ExecutorState = executorState; | ExecutorState = executorState; | ||||
| History = history.Messages.ToArray(); | History = history.Messages.ToArray(); | ||||
| InputTransformPipeline = inputTransformPipeline.ToArray(); | |||||
| OutputTransform = outputTransform; | |||||
| HistoryTransform = historyTransform; | |||||
| InputTransformPipeline = inputTransformPipeline.Select(t => t.Clone()).ToArray(); | |||||
| OutputTransform = outputTransform.Clone(); | |||||
| HistoryTransform = historyTransform.Clone(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -47,6 +47,12 @@ namespace LLama | |||||
| _isInstructMode = isInstructMode; | _isInstructMode = isInstructMode; | ||||
| } | } | ||||
| /// <inheritdoc /> | |||||
| public IHistoryTransform Clone() | |||||
| { | |||||
| return new DefaultHistoryTransform(_userName, _assistantName, _systemName, _unknownName, _isInstructMode); | |||||
| } | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public virtual string HistoryToText(ChatHistory history) | public virtual string HistoryToText(ChatHistory history) | ||||
| { | { | ||||
| @@ -116,6 +122,12 @@ namespace LLama | |||||
| { | { | ||||
| return text.Trim(); | return text.Trim(); | ||||
| } | } | ||||
| /// <inheritdoc /> | |||||
| public ITextTransform Clone() | |||||
| { | |||||
| return new NaiveTextInputTransform(); | |||||
| } | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -129,6 +141,12 @@ namespace LLama | |||||
| { | { | ||||
| return tokens; | return tokens; | ||||
| } | } | ||||
| /// <inheritdoc /> | |||||
| public ITextStreamTransform Clone() | |||||
| { | |||||
| return new EmptyTextOutputStreamTransform(); | |||||
| } | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -157,6 +175,12 @@ namespace LLama | |||||
| _removeAllMatchedTokens = removeAllMatchedTokens; | _removeAllMatchedTokens = removeAllMatchedTokens; | ||||
| } | } | ||||
| /// <inheritdoc /> | |||||
| public ITextStreamTransform Clone() | |||||
| { | |||||
| return new KeywordTextOutputStreamTransform(_keywords, _maxKeywordLength, _removeAllMatchedTokens); | |||||
| } | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public async IAsyncEnumerable<string> TransformAsync(IAsyncEnumerable<string> tokens) | public async IAsyncEnumerable<string> TransformAsync(IAsyncEnumerable<string> tokens) | ||||
| { | { | ||||