diff --git a/LLama.Examples/LLama.Examples.csproj b/LLama.Examples/LLama.Examples.csproj index 5bad3f088..330e77386 100644 --- a/LLama.Examples/LLama.Examples.csproj +++ b/LLama.Examples/LLama.Examples.csproj @@ -14,7 +14,7 @@ - + diff --git a/LLama/Extensions/LLamaExecutorExtensions.cs b/LLama/Extensions/LLamaExecutorExtensions.cs index 61729ce16..7fd799f6a 100644 --- a/LLama/Extensions/LLamaExecutorExtensions.cs +++ b/LLama/Extensions/LLamaExecutorExtensions.cs @@ -63,7 +63,7 @@ public void Dispose() { } public async Task GetResponseAsync( IEnumerable messages, ChatOptions? options = null, CancellationToken cancellationToken = default) { - var result = _executor.InferAsync(CreatePrompt(messages), CreateInferenceParams(options), cancellationToken); + var result = _executor.InferAsync(CreatePrompt(messages, options), CreateInferenceParams(options), cancellationToken); StringBuilder text = new(); await foreach (var token in _outputTransform.TransformAsync(result)) @@ -86,7 +86,7 @@ public async Task GetResponseAsync( public async IAsyncEnumerable GetStreamingResponseAsync( IEnumerable messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) { - var result = _executor.InferAsync(CreatePrompt(messages), CreateInferenceParams(options), cancellationToken); + var result = _executor.InferAsync(CreatePrompt(messages, options), CreateInferenceParams(options), cancellationToken); string messageId = Guid.NewGuid().ToString("N"); await foreach (var token in _outputTransform.TransformAsync(result)) @@ -100,7 +100,7 @@ public async IAsyncEnumerable GetStreamingResponseAsync( } /// Format the chat messages into a string prompt. - private string CreatePrompt(IEnumerable messages) + private string CreatePrompt(IEnumerable messages, ChatOptions? options = null) { if (messages is null) { @@ -120,6 +120,11 @@ private string CreatePrompt(IEnumerable messages) AuthorRole.User, string.Concat(message.Contents.OfType())); } + + if (options?.Instructions is { } instructions) + { + history.AddMessage(AuthorRole.System, instructions); + } } else { diff --git a/LLama/LLamaSharp.csproj b/LLama/LLamaSharp.csproj index cf93c4828..f53de7069 100644 --- a/LLama/LLamaSharp.csproj +++ b/LLama/LLamaSharp.csproj @@ -45,15 +45,15 @@ - + - - - - + + + +