Skip to content

Commit de00c15

Browse files
authored
Merge pull request #1256 from stephentoub/instructions
Respect ChatOptions.Instructions in LlamaExecutorChatClient
2 parents 9fe066d + d88cc7f commit de00c15

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

LLama.Examples/LLama.Examples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.8" />
17+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.9" />
1818
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.98.250508.3" />
1919
<PackageReference Include="Microsoft.SemanticKernel" Version="1.64.0" />
2020
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" Version="1.44.0-alpha" />

LLama/Extensions/LLamaExecutorExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void Dispose() { }
6363
public async Task<ChatResponse> GetResponseAsync(
6464
IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
6565
{
66-
var result = _executor.InferAsync(CreatePrompt(messages), CreateInferenceParams(options), cancellationToken);
66+
var result = _executor.InferAsync(CreatePrompt(messages, options), CreateInferenceParams(options), cancellationToken);
6767

6868
StringBuilder text = new();
6969
await foreach (var token in _outputTransform.TransformAsync(result))
@@ -86,7 +86,7 @@ public async Task<ChatResponse> GetResponseAsync(
8686
public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
8787
IEnumerable<ChatMessage> messages, ChatOptions? options = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
8888
{
89-
var result = _executor.InferAsync(CreatePrompt(messages), CreateInferenceParams(options), cancellationToken);
89+
var result = _executor.InferAsync(CreatePrompt(messages, options), CreateInferenceParams(options), cancellationToken);
9090

9191
string messageId = Guid.NewGuid().ToString("N");
9292
await foreach (var token in _outputTransform.TransformAsync(result))
@@ -100,7 +100,7 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
100100
}
101101

102102
/// <summary>Format the chat messages into a string prompt.</summary>
103-
private string CreatePrompt(IEnumerable<ChatMessage> messages)
103+
private string CreatePrompt(IEnumerable<ChatMessage> messages, ChatOptions? options = null)
104104
{
105105
if (messages is null)
106106
{
@@ -120,6 +120,11 @@ private string CreatePrompt(IEnumerable<ChatMessage> messages)
120120
AuthorRole.User,
121121
string.Concat(message.Contents.OfType<TextContent>()));
122122
}
123+
124+
if (options?.Instructions is { } instructions)
125+
{
126+
history.AddMessage(AuthorRole.System, instructions);
127+
}
123128
}
124129
else
125130
{

LLama/LLamaSharp.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
<PackageReference Include="IsExternalInit" Version="1.0.3" PrivateAssets="all" />
4646
<PackageReference Include="System.Memory" Version="4.6.3" PrivateAssets="all" />
4747
<PackageReference Include="System.Linq.Async" Version="6.0.3" />
48-
<PackageReference Include="System.Text.Json" Version="9.0.8" />
48+
<PackageReference Include="System.Text.Json" Version="9.0.9" />
4949
</ItemGroup>
5050

5151
<ItemGroup>
5252
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.0" />
53-
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.8" />
54-
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.8.0" />
55-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.8" />
56-
<PackageReference Include="System.Numerics.Tensors" Version="9.0.8" />
53+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.9" />
54+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.9.0" />
55+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.9" />
56+
<PackageReference Include="System.Numerics.Tensors" Version="9.0.9" />
5757
</ItemGroup>
5858

5959
<PropertyGroup>

0 commit comments

Comments
 (0)